Skip to content

fix(table): fill identity partition columns missing from data files - #2487

Merged
laskoviymishka merged 11 commits into
apache:mainfrom
slachiewicz:fix/identity-partition-projection
Dec 2, 2026
Merged

laskoviymishka merged 11 commits into
apache:mainfrom
slachiewicz:fix/identity-partition-projection

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Closes #2485.

A field that a data file doesn't store now takes the file's identity partition value before any default or null, per the spec's column projection rule 1. The value comes from the spec the file was written with, and it is widened to the field's current type, so a float partition value fills a column since promoted to double. No exported API changes.

The same value is used wherever the file is evaluated, not only in the output:

  • Per-file filters. A predicate on such a field is folded to its result for the file's partition value before the filter is translated to the file schema, which would otherwise read the field as null in every row. This covers the row filter, Parquet row-group pruning, and the filter that picks rows for generated position deletes (producePosDeletesFromTask). A folded filter holds for one file only, so those files skip the filter plans cached by file schema. Files that store the column are unaffected.
  • Equality deletes. The projection that adds equality-delete key columns takes the partition values too, so a delete keyed on the partition column matches.
  • Initial-default. A partition value wins over the column's initial-default, and a null partition value stays null. A file with no partition value for the column still takes the default.

Two projections keep reading without partition values: changelog normalization, which reprojects rows the scan has already filled, and the row struct of position delete files in inspect.

Tests, all in identity_partition_projection_internal_test.go:

  • The outside east or id 1 case of TestDeleteOnIdentityPartitionColumnMissingFromDataFile keeps region = 'east' AND id != 1. Its v3 copy-on-write run is the only one that sets rowGroupFilter, and it fails with the row-group fold in processRecordsWithPlans disabled: without it the missing column reads as null, the east row group is pruned, and id 2 is lost.
  • TestScanFillsIdentityPartitionColumnMissingFromDataFile runs with the partition column required and optional. With the production change reverted, the required case fails the scan and the optional one returns region null in every row, without an error.
  • TestDeleteOnIdentityPartitionColumnMissingFromDataFile (copy-on-write and merge-on-read), TestEqualityDeleteOnIdentityPartitionColumnMissingFromDataFile, TestScanWidensPromotedIdentityPartitionColumnMissingFromDataFile and TestIdentityPartitionValueUsesFileSpecAndWinsOverInitialDefault fail with the production change reverted: the merge-on-read delete removes id 1 from east, the equality delete matches nothing, the promoted column panics in ToArrowTable, and region != 'east' loses the row that takes the default.
  • TestIncrementalScansOnIdentityPartitionColumnMissingFromDataFile (append and changelog) also fails with the production change reverted, and still fails with only the projection fix: incremental scans attach the whole row filter to each task, without partition-specific simplification, so region = 'west' AND id = 1 returned no rows.
  • TestOverwriteOnIdentityPartitionColumnMissingFromDataFile fails on main, where rewriting the kept rows of west errors on the missing required column, and passes with only the projection fix: overwrite takes each file's residual from planning.
  • TestFilterOnIdentityPartitionColumnMissingFromDataFile and the copy-on-write delete case pass on the base too: a scan takes each file's residual from planning, which already substitutes the partition value. They pin that.

Verified: go test -race ./table/ and golangci-lint run ./table/... (v2.14.0) on macOS and Linux → pass.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is the right fix for #2485, and other types work: I tried int, long, date, time, timestamp/tz, bool, string, uuid, binary, fixed, float and double.

Blocker: decimal identity partitions now make the scan fail. file.Partition() gives decimals back as iceberg.DecimalLiteral, and defaultToScalar only accepts iceberg.Decimal or string, so scanning a file that leaves out a decimal(9,2) identity partition column fails with write-default decimal: unsupported value type iceberg.DecimalLiteral (12.34). On main that scan returns null. Could you convert the value (or handle DecimalLiteral in defaultToScalar) and add a decimal case to the test?

Nit: identityPartitionConstants was inserted between canReuseFlatProjection and its doc comment, so that comment now sits on top of the new function. Please move the new function above it.

@slachiewicz

Copy link
Copy Markdown
Member Author

Both addressed in ace9d24: decimal partition values are converted to iceberg.Decimal before projection, with TestScanFillsDecimalIdentityPartitionColumnMissingFromDataFile, and identityPartitionConstants now sits above canReuseFlatProjection's doc comment.

@badalprasadsingh badalprasadsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass @slachiewicz, few comments that block the approval

Comment thread table/arrow_scanner.go Resolved
Comment thread table/arrow_scanner.go Resolved
Comment thread table/arrow_utils.go Resolved
Comment thread table/arrow_scanner.go Resolved
@slachiewicz

Copy link
Copy Markdown
Member Author

@badalprasadsingh @zeroshade, updated for the review: the four threads are fixed in 8a6e0d6, with a reply on each; the decimal case is in ace9d24; and d70b912 adds tests for the overwrite and incremental scan paths named in the first thread. Ready for another look.

@badalprasadsingh badalprasadsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @slachiewicz, my earlier comments are addressed, but, these are few test additions that block approval

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files that don't store their identity partition column now read the partition value instead of null, in the scan output and in the per-file filters and equality deletes. I'm requesting changes for two things: tests that exercise foldIdentityPartitionConstants directly, including the v3 copy-on-write delete, and the conversion error in the projection, which shouldn't be swallowed. Could you also open an issue for folding once per file and keeping the cache-skip guard in one place?

Comment thread table/arrow_utils.go Resolved
Comment thread table/arrow_utils.go Resolved
@slachiewicz
slachiewicz force-pushed the fix/identity-partition-projection branch from d70b912 to c6016e1 Compare November 21, 2026 11:06
@laskoviymishka
laskoviymishka self-requested a review November 23, 2026 13:31

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @slachiewicz — both items from my earlier review are addressed: decimal identity partitions are converted before projection (b182d9a, with TestScanFillsDecimalIdentityPartitionColumnMissingFromDataFile), and identityPartitionConstants now sits above canReuseFlatProjection's doc comment. CI is green on c6016e1.

The 11-21 push was a rebase onto the table/internal/substrait move with no other changes, so the six threads @badalprasadsingh and @laskoviymishka opened on 11-17 are still open. Two of them are still visible at head:

  • arrow_utils.go: the identityPartitionValue error is discarded (if converted, err := ...; err == nil), so a failed conversion surfaces later as a misleading write-default error.
  • arrow_utils.go: case hasConstant: still runs before the required-field check, so a null partition value on a required field yields an all-null non-nullable column instead of the missing-required error.

The other four ask for tests: a direct table-driven test of foldIdentityPartitionConstants, a v3 copy-on-write delete that goes through the row-group fold, copy-on-write fixtures that put both files in one commit, and a per-record schema check in the widening test. Could you reply on each, and open the follow-up issue @laskoviymishka asked for (folding once per file, keeping the cache-skip guard in one place)? I'll approve once those reviewers are satisfied.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Iceberg Go maintainer. The findings
below are observations, not blockers; an Apache Iceberg Go
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

@slachiewicz
slachiewicz force-pushed the fix/identity-partition-projection branch from c6016e1 to 8a6e198 Compare November 27, 2026 15:17

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @slachiewicz. Today's two commits address four of the six open threads: the conversion error is now returned with the column name, a null partition value on a required field falls through to the missing-required check again, TestFoldIdentityPartitionConstants tests the folder directly, and the scan helpers check each record against the returned schema. Locally, go test -race ./table/ -run 'IdentityPartition|FoldIdentity' passes on 8a6e1982.

Still open:

  • @badalprasadsingh's and @laskoviymishka's threads on the copy-on-write tests. regionTestTable still commits each file separately, and the delete test only runs format version 2 with west, so the row-group fold in processRecordsWithPlans (only reached by a v3 copy-on-write delete) still runs in no test. When I tried locally, a v3 copy-on-write delete of region = 'west' AND id = 1 and of region = 'east' AND id = 1 both give the right rows, so this is only about pinning it with a test.
  • The follow-up issue @laskoviymishka asked for (fold once per file, keep the cache-skip guard in one place).

One small inline nit as well. I'll approve once those reviewers are satisfied.


This review was drafted with an AI-assisted tool and may contain mistakes. An Apache Iceberg maintainer has read and confirmed it before posting.

Comment thread table/arrow_utils.go Resolved
A required field that a data file does not store failed the scan with
"required field is missing and has no default value", even when an
identity partition holds its value. Writers that keep partition columns out
of their files, as Delta and Hive-style layouts do, hit this. The spec's
column projection resolves such a field from the partition value first.
…rtition values missing from data files

A filter that reads a field the file leaves to its identity partition is folded with that file's value and compiled per file, since the cached plans are keyed by file schema only. Partition values are widened to the field's current type.

Signed-off-by: Sylwester Lachiewicz <[email protected]>
…ion columns missing from data files

Signed-off-by: Sylwester Lachiewicz <[email protected]>
…rom data files

Add both data files in one commit and run the delete test on format versions 2 and 3 with west and east filters. Document that convertPartitionConstants allocates a map per record batch.

Signed-off-by: Sylwester Lachiewicz <[email protected]>
@slachiewicz
slachiewicz force-pushed the fix/identity-partition-projection branch from 8a6e198 to a9c1fa4 Compare November 28, 2026 18:53
…at keeps rows by partition

Signed-off-by: Sylwester Lachiewicz <[email protected]>
@slachiewicz

Copy link
Copy Markdown
Member Author

The follow-up for folding once per file and keeping the cache-skip guard in one place is #2755.

@badalprasadsingh badalprasadsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving @slachiewicz
the comments are optional, here or in a follow-up

Comment thread table/arrow_utils.go
// written with, so a field promoted since still carries the narrower value.
// It returns constants itself when there are none, and otherwise allocates a
// new map per call, which is once per record batch.
func convertPartitionConstants(requested *iceberg.Schema, constants map[int]any) (map[int]any, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are converting every identity value, even for cols the file stores, so something it cannot convert, for e.g., one that another engine wrote, fails a scan that works on main right now

better: it we could skip stored cols

Comment thread table/arrow_utils.go
Comment on lines +1343 to +1346
case hasConstant && constant != nil:
arr = defaultToArray(constant, field.Type, dt, structArr.Len(), alloc)
case hasConstant && (!field.Required || a.allowMissingRequired):
arr = array.MakeArrayOfNull(alloc, dt, structArr.Len())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add tests coverting this: an un-convertible partition value is an error naming the column, and a null partition value on a required column is rejected

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @slachiewicz, everything from my earlier reviews is addressed. The single AddDataFiles commit plus the outside east or id 1 case now exercise the folding in processRecordsWithPlans on v3 copy-on-write, idAndColumnRows checks record types, and laskoviymishka's threads (returning the conversion error, null-on-required, the direct folder test) are resolved, with #2755 for the follow-up. Merged onto current main, go test -race ./table -run 'IdentityPartition|FoldIdentity' and the full go test ./table pass locally.

+1 to both of @badalprasadsingh's latest comments, and I'd like the first one in this PR before merge:

  • Only convert values for columns the file doesn't store. identityPartitionConstants collects every identity partition value, and convertPartitionConstants converts all of them on every batch, even for columns the file stores (the common case). A value identityPartitionValue can't convert, e.g. one another engine wrote, now fails a scan that works on main even though the column is read from the file. Every projected batch of an identity-partitioned table also pays a map allocation and conversion. Dropping values whose source field is in the file schema, once per file, fixes both, keeps "files that store the column are unaffected" literally true, and is a step toward #2755.
  • Tests for the two error paths: an unconvertible value errors naming the column, and a null partition value on a required missing column is rejected.

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this covers all four of my threads, and the v3 copy-on-write outside east or id 1 delete now fails once the row-group fold is removed. +1 to badalprasadsingh's two comments, here or in a follow-up.

@laskoviymishka
laskoviymishka merged commit a111cac into apache:main Dec 2, 2026
16 of 17 checks passed
@slachiewicz
slachiewicz deleted the fix/identity-partition-projection branch December 2, 2026 07:16
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.

Scan fails when an identity partition column is not stored in the data files

4 participants