Skip to content

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

Open
YinZheng-Sun wants to merge 14 commits into
apache:mainfrom
YinZheng-Sun:codex/partition-column-reading
Open

YinZheng-Sun wants to merge 14 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

Identity-partitioned source columns may be omitted from data files because their 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. Keep the spec pointer consistent with the other task fields.
  • Pass constants through the existing Project entry points and select them during recursive field projection, including primitive leaves of existing structs. There is no separate ProjectConstant or ValidateConstant method. Like the Java reader path, projection trusts the supplied constants.
  • Give constants precedence over physical values and initial defaults, preserving explicit nulls. 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

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.

field.field_id());
}
if (field.transform()->transform_type() == TransformType::kIdentity) {
id_to_constant.emplace(field.source_id(), file.partition.values()[i]);

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.

file.partition.values()[i] uses span operator[] with no bounds check, but PartitionValues::ValueAt already exists for this exact case and returns an invalid argument error if the data file's partition value count doesn't match the spec field count. worth using ValueAt here to avoid undefined behavior on a mismatched partition tuple.

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.

Good catch, thanks! Fixed in a83a681. ConstantsOf() now validates that
file.partition.num_fields() matches spec->fields().size() and returns
InvalidArgument with the file path and spec id on mismatch. It also uses
PartitionValues::ValueAt(i) (via ICEBERG_ASSIGN_OR_RAISE) instead of raw
indexing, so a malformed partition tuple can no longer cause out-of-bounds
access. Added RejectsPartitionValuesNotMatchingSpec to cover this case.

Comment thread src/iceberg/manifest/manifest_group.cc Outdated
return std::optional<std::shared_ptr<FileScanTask>>{std::make_shared<FileScanTask>(
std::move(value.data_file), std::move(delete_files), std::move(residual))};
std::move(value.data_file), std::move(delete_files), std::move(residual),
group_->specs_by_id_.at(spec_id))};

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.

specs_by_id_.at(spec_id) throws std::out_of_range on a missing id, inconsistent with GetManifestEvaluator and GetResidualEvaluator above which look up the same map via find() plus ICEBERG_CHECK with a clear error message.

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.

Agreed, done

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

yinzhengsun added 2 commits November 25, 2026 11:53
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.
…n-reading

# Conflicts:
#	src/iceberg/data/file_scan_task_reader.cc
#	src/iceberg/parquet/parquet_data_util.cc
#	src/iceberg/test/file_scan_task_reader_test.cc
@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
std::vector<std::shared_ptr<DataFile>> delete_files = {},
std::shared_ptr<Expression> filter = nullptr);
std::shared_ptr<Expression> filter = nullptr,
std::shared_ptr<PartitionSpec> spec = nullptr);

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.

FileScanTaskSplitCursor::Next omits this argument, so planned Parquet splits lose the spec and Open rejects them. Pass the parent spec and test a partitioned file through PlanTasks.

options.name_mapping.get()));
ICEBERG_ASSIGN_OR_RAISE(
projection_, BuildProjection(reader_.get(), *read_schema_,
options.name_mapping.get(), options.id_to_constant));

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.

Footer stats still describe the physical values. If the physical column says file and the constant is CN, a name = 'CN' filter can prune every row. Ignore stats for overridden IDs and add a regression with filtering enabled.

}
} else if (field_projection.kind == FieldProjection::Kind::kDefault) {
} else if (field_projection.kind == FieldProjection::Kind::kDefault ||
field_projection.kind == FieldProjection::Kind::kConstant) {

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.

A v3 identity partition can supply Literal::Null(unknown()). Both readers resolve its source type before checking for null and fail. Materialize nulls using the output type.


if (field_projection.kind == FieldProjection::Kind::kDefault) {
if (field_projection.kind == FieldProjection::Kind::kDefault ||
field_projection.kind == FieldProjection::Kind::kConstant) {

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.

An old task can supply decimal(9,2) to a decimal(18,2) projection. Arrow's Scalar::CastTo rejects that widening. Use a decimal-capable cast and cover both Avro decoders.

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.

4 participants