Skip to content

feat(read): read identity partition columns from file scan tasks - #1068

Merged
wgtmac merged 11 commits into
apache:mainfrom
YinZheng-Sun:codex/partition-column-reading
Dec 1, 2026
Merged

wgtmac merged 11 commits into
apache:mainfrom
YinZheng-Sun:codex/partition-column-reading

Conversation

@YinZheng-Sun

@YinZheng-Sun YinZheng-Sun commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Data files imported from Hive may omit identity-partitioned source columns whose values are stored in the partition tuple. This PR carries each file’s writing spec through scan planning, JSON/REST tasks and splits, and supplies identity source constants to Parquet and Avro readers.

Reading behavior

  • Build a per-file id_to_constant map keyed by source field ID, using the task’s own historical PartitionSpec. Tasks constructed without a spec can still read physical columns. A supplied spec must match the file’s spec ID when present.
  • Pass constants through the existing Avro and Parquet Project entry points and select them during recursive field projection, including primitive leaves of existing structs. Both formats use the projected Arrow type for nulls and for promotions such as decimal precision widening.
  • Read the physical column, including stored nulls, when its field ID is present in the file. For a missing ID, use the identity partition value (including null) before name mapping or the initial default, following the column projection rules. Materialize constants before equality-delete evaluation, including columns needed by deletes but omitted from the output.
  • Preserve upstream row-group filtering, filter binding and case sensitivity. Keep the original two-argument metrics filter interface unchanged; partition constants participate only in projection.

Scope

Identity source columns only: bucket and other transforms do not reconstruct source values. _partition, _spec_id and _file are not added to this constant map. Nested/struct constant values and reconstruction of an entirely absent parent struct are outside this change. JSON tasks must retain the historical source-type information needed to decode partition values.

The reader flow follows Java’s PartitionUtil.constantsMap, GenericReader and recursive Parquet reader construction. Feedback on spec ownership and the constant-map interface is welcome.

Validation

Rebased onto 60447e78c. All 26 local CTest suites and pre-commit passed for 2d73d2f4b.

Earlier validation

Merged upstream main at 748162b3 and resolved the task-reader and Parquet-reader conflicts. After restoring the original metrics filter interface, rebuilt and passed data_test (200) and parquet_test (193), plus pre-commit and clang-tidy 22.1.8 on the changed reader and metrics filter. Earlier validation also passed schema_test (566) and avro_test (255).

For local Apple-toolchain testing only, an existing upstream std::ranges::iota call was temporarily replaced with equivalent std::iota; the source was restored and that workaround is not committed. Clang-tidy 22.1.8 found two diagnostics in the external Avro GenericDatum.hh; both were reproduced against unmodified upstream avro_data_util.cc.

@YinZheng-Sun YinZheng-Sun changed the title feat(read): materialize partition columns from file scan tasks feat(read): read identity partition columns from file scan tasks Oct 29, 2026
@YinZheng-Sun YinZheng-Sun reopened this Oct 29, 2026
@advancedxy

Copy link
Copy Markdown
Contributor

Identity-partitioned source columns may be omitted from data files because their values are stored in the partition tuple.

for the record: apache/iceberg#10835 this might be the most relevant discussion and per iceberg spec: partition source data columns might be always produced unless the data files are migrated from hive tables.

However java's reference implementation prefers id constant from partition data.

Comment thread src/iceberg/manifest/manifest_group.cc Resolved

@wgtmac wgtmac 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.

Sorry for the long delay! Do you want to revive this?

EXPECT_EQ(parsed->spec()->spec_id(), 7);
ICEBERG_UNWRAP_OR_FAIL(
auto split, FileScanTask::MakeSplit(parsed->data_file(), 0, parsed->length(), {},
nullptr, parsed->spec()));

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.

Use a proper subrange and assert is_split(); this range is canonicalized to a whole-file task, so it does not cover spec propagation through the partial-split constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right,thx! Use [0, length - 1) and added ASSERT_TRUE(split->is_split())` before checking that the spec is preserved.

@YinZheng-Sun

Copy link
Copy Markdown
Contributor Author

Sorry for the long delay! Do you want to revive this?

Yes, I'd like to continue with this PR. I've addressed all review comments and resolved conflicts,PTAL when you have time, thanks!

Comment thread src/iceberg/table_scan.h Resolved
Comment thread src/iceberg/parquet/parquet_reader.cc Resolved
Comment thread src/iceberg/avro/avro_data_util.cc Resolved
yinzhengsun and others added 11 commits December 1, 2026 18:01
Check partition tuple arity against the spec and use bounds-checked access when reading identity partition constants. Replace the throwing specs_by_id_.at() lookup in ManifestGroup with a checked find. Make the split test use a proper sub-range so the split constructor path is exercised.
Read the physical Avro or Parquet column when its native field ID is
present, including when the stored value is null. For a missing ID, use
the identity partition value before name mapping or the initial default.
This keeps Parquet row-group pruning consistent with the values returned
by the reader.

Pass the file's writing spec to planner-generated splits. Reject a task
whose spec ID conflicts with the data file, and preserve physical-column
reads for tasks created without a spec.

Share Arrow scalar conversion across both formats to handle unknown nulls
and decimal precision promotion. Fix Avro field-ID detection for legacy
files and publish the read context only after initialization succeeds.
Keep partition handling in the format readers and restore the original
schema-to-schema Project signature.

Cover split planning, task serialization, partition evolution, and
equality deletes on identity columns omitted from the output projection.
@wgtmac
wgtmac force-pushed the codex/partition-column-reading branch from 7e94460 to 2d73d2f Compare December 1, 2026 15:08

@wgtmac wgtmac 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 for improving this PR! To save another review round, I rebased the branch and pushed a follow-up directly. I narrowed the change to filling missing identity partition columns, so Avro and Parquet keep the stored value whenever the file has the field ID. That also lets us keep the existing Parquet pruning logic.

@wgtmac
wgtmac merged commit 7bb9f48 into apache:main Dec 1, 2026
12 of 15 checks passed
manuzhang added a commit to manuzhang/iceberg-cpp that referenced this pull request Dec 1, 2026
Preserve identity partition precedence from apache#1068 and apply the
per-file name-mapping rules clarified in apache/iceberg#19037.

Co-authored-by: Manu Zhang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Codex <[email protected]>
manuzhang added a commit to manuzhang/iceberg-cpp that referenced this pull request Dec 1, 2026
Preserve identity partition precedence from apache#1068 and apply the
per-file name-mapping rules clarified in apache/iceberg#19037.

Co-authored-by: Manu Zhang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Codex <[email protected]>
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.

4 participants