Skip to content

[1015] Read Paimon column stats by the schema each data file was written with - #1016

Open
Indian-boult wants to merge 3 commits into
apache:mainfrom
Indian-boult:fix/paimon-schema-evolution-stats
Open

Indian-boult wants to merge 3 commits into
apache:mainfrom
Indian-boult:fix/paimon-schema-evolution-stats

Conversation

@Indian-boult

Copy link
Copy Markdown
Contributor

Fixes #1015

What is the purpose of the pull request

The Paimon source read each data file's stats by position in the snapshot schema, but Paimon stores them by position in the schema the file was written with. After a schema change this failed the sync (ADD COLUMN) or gave a column the stats of another column (DROP then ADD, or a type change). This PR reads the stats by the file's schema and matches columns by field id.

Brief change log

  • PaimonDataFileExtractor: look up the schema of each data file by DataFileMeta#schemaId(), reading each schema once per sync call, and pass it to the stats extractor.
  • PaimonStatsExtractor.extractColumnStats: when valueStatsCols() is null, take the column names from the file's schema. Match the file's columns to the snapshot schema by field id. Skip a column that was dropped, or whose type or type parameters changed.
  • Tests in TestPaimonStatsExtractor: add a column (append and primary-key tables), rename then add, drop then add, and a type change. Each writes a file before the change and checks its stats after.

Verify this pull request

This change added tests and can be verified as follows:

  • Before the fix, the three add-column tests fail with Mismatch between column stats names and values arity, the drop and add test reports stats for c from b, and the type change test reports stats for a and f from the old types.
  • After the fix, they pass.
  • ./mvnw -pl xtable-core test: 586 tests, 0 failures, 0 errors, 3 skipped.
  • ./mvnw -pl xtable-core -DskipUTs -Dit.test='ITConversionController#testVariousOperations' verify: 28 tests, 0 failures, 0 errors.
  • Manually synced the tables from the issue to Iceberg, Delta and Hudi. Before the fix the add-column table failed to sync and c IS NULL returned 0 rows on the drop and add table. After the fix all syncs succeed and c IS NULL returns 2 rows.

…ten with

Paimon stores a data file's value stats by position in the schema the file
was written with (DataFileMeta#schemaId). When valueStatsCols is null, the
Paimon source used the positions of the snapshot schema instead. After a
schema change, files written before it were read with the wrong layout:

- After ADD COLUMN, the sync failed with "Mismatch between column stats
  names and values arity".
- After DROP COLUMN b and ADD COLUMN c, c got the stats of b. Iceberg then
  skipped those files for c IS NULL, although c is null in all their rows.
- After a column type change, the old values were read with the new type.

Resolve the file's schema by schemaId, match its columns to the snapshot
schema by field id, and skip a column whose type changed.

Fixes apache#1015
…schemas

The file schemas are passed as a map filled as files are read. When a file was written with the schema the stats are reported in, its columns map by name without the match by field id. Adds a test for a column dropped and added again under the same name.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paimon source fails or reports wrong column stats for files written before a schema change

2 participants