Repository navigation
fix(table): fill identity partition columns missing from data files - #2487
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
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.
|
Both addressed in ace9d24: decimal partition values are converted to |
badalprasadsingh
left a comment
There was a problem hiding this comment.
first pass @slachiewicz, few comments that block the approval
|
@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
left a comment
There was a problem hiding this comment.
thanks @slachiewicz, my earlier comments are addressed, but, these are few test additions that block approval
laskoviymishka
left a comment
There was a problem hiding this comment.
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?
d70b912 to
c6016e1
Compare
zeroshade
left a comment
There was a problem hiding this comment.
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: theidentityPartitionValueerror is discarded (if converted, err := ...; err == nil), so a failed conversion surfaces later as a misleadingwrite-defaulterror.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.
c6016e1 to
8a6e198
Compare
zeroshade
left a comment
There was a problem hiding this comment.
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.
regionTestTablestill commits each file separately, and the delete test only runs format version 2 withwest, so the row-group fold inprocessRecordsWithPlans(only reached by a v3 copy-on-write delete) still runs in no test. When I tried locally, a v3 copy-on-write delete ofregion = 'west' AND id = 1and ofregion = 'east' AND id = 1both 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.
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]>
Signed-off-by: Sylwester Lachiewicz <[email protected]>
…ion columns missing from data files Signed-off-by: Sylwester Lachiewicz <[email protected]>
…ired-null check Signed-off-by: Sylwester Lachiewicz <[email protected]>
…n column types 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]>
8a6e198 to
a9c1fa4
Compare
… data files Signed-off-by: Sylwester Lachiewicz <[email protected]>
Signed-off-by: Sylwester Lachiewicz <[email protected]>
…at keeps rows by partition Signed-off-by: Sylwester Lachiewicz <[email protected]>
|
The follow-up for folding once per file and keeping the cache-skip guard in one place is #2755. |
badalprasadsingh
left a comment
There was a problem hiding this comment.
approving @slachiewicz
the comments are optional, here or in a follow-up
| // 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) { |
There was a problem hiding this comment.
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
| 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()) |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
identityPartitionConstantscollects every identity partition value, andconvertPartitionConstantsconverts all of them on every batch, even for columns the file stores (the common case). A valueidentityPartitionValuecan'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
left a comment
There was a problem hiding this comment.
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.
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:
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.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
rowstruct of position delete files ininspect.Tests, all in
identity_partition_projection_internal_test.go:outside east or id 1case ofTestDeleteOnIdentityPartitionColumnMissingFromDataFilekeepsregion = 'east' AND id != 1. Its v3 copy-on-write run is the only one that setsrowGroupFilter, and it fails with the row-group fold inprocessRecordsWithPlansdisabled: without it the missing column reads as null, the east row group is pruned, and id 2 is lost.TestScanFillsIdentityPartitionColumnMissingFromDataFileruns with the partition column required and optional. With the production change reverted, the required case fails the scan and the optional one returnsregionnull in every row, without an error.TestDeleteOnIdentityPartitionColumnMissingFromDataFile(copy-on-write and merge-on-read),TestEqualityDeleteOnIdentityPartitionColumnMissingFromDataFile,TestScanWidensPromotedIdentityPartitionColumnMissingFromDataFileandTestIdentityPartitionValueUsesFileSpecAndWinsOverInitialDefaultfail with the production change reverted: the merge-on-read delete removes id 1 fromeast, the equality delete matches nothing, the promoted column panics inToArrowTable, andregion != '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, soregion = 'west' AND id = 1returned no rows.TestOverwriteOnIdentityPartitionColumnMissingFromDataFilefails onmain, where rewriting the kept rows ofwesterrors on the missing required column, and passes with only the projection fix: overwrite takes each file's residual from planning.TestFilterOnIdentityPartitionColumnMissingFromDataFileand 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/andgolangci-lint run ./table/...(v2.14.0) on macOS and Linux → pass.