Repository navigation
feat(read): read identity partition columns from file scan tasks - #1068
YinZheng-Sun wants to merge 14 commits into
Conversation
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]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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))}; |
There was a problem hiding this comment.
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.
wgtmac
left a comment
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
You're right,thx! Use [0, length - 1) and added ASSERT_TRUE(split->is_split())` before checking that the spec is preserved.
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
Yes, I'd like to continue with this PR. I've addressed all review comments and resolved conflicts,PTAL when you have time, thanks! |
| 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); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
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
id_to_constantmap keyed by source field ID, using the task’s own historicalPartitionSpec. Keep the spec pointer consistent with the other task fields.Projectentry points and select them during recursive field projection, including primitive leaves of existing structs. There is no separateProjectConstantorValidateConstantmethod. Like the Java reader path, projection trusts the supplied constants.Scope
Identity source columns only: bucket and other transforms do not reconstruct source values.
_partition,_spec_idand_fileare 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,GenericReaderand recursive Parquet reader construction. Feedback on spec ownership and the constant-map interface is welcome.Validation
Merged upstream
mainat748162b3and resolved the task-reader and Parquet-reader conflicts. After restoring the original metrics filter interface, rebuilt and passeddata_test(200) andparquet_test(193), plus pre-commit and clang-tidy 22.1.8 on the changed reader and metrics filter. Earlier validation also passedschema_test(566) andavro_test(255).For local Apple-toolchain testing only, an existing upstream
std::ranges::iotacall was temporarily replaced with equivalentstd::iota; the source was restored and that workaround is not committed. Clang-tidy 22.1.8 found two diagnostics in the external AvroGenericDatum.hh; both were reproduced against unmodified upstreamavro_data_util.cc.