-
Notifications
You must be signed in to change notification settings - Fork 117
feat(avro): apply column default values when reading missing fields #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
351a895
9e1605f
0e4c6a4
289a7c9
1b8045b
7de6e6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,14 +19,48 @@ | |
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include <arrow/array/builder_base.h> | ||
| #include <arrow/scalar.h> | ||
| #include <avro/GenericDatum.hh> | ||
|
|
||
| #include "iceberg/arrow/metadata_column_util_internal.h" | ||
| #include "iceberg/expression/literal.h" | ||
| #include "iceberg/schema_util.h" | ||
|
|
||
| namespace iceberg::avro { | ||
|
|
||
| /// \brief Cached Arrow scalar for a `kDefault` field projection. | ||
| /// | ||
| /// Materialized once (see `PrepareDefaultScalars`) so row-by-row Avro decode only | ||
| /// needs `AppendScalar` instead of repeating `ToArrowScalar` / `CastTo` per row. | ||
| struct AvroDefaultAttributes : FieldProjection::ExtraAttributes { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this follow the |
||
| std::shared_ptr<::arrow::Scalar> scalar; | ||
| }; | ||
|
|
||
| /// \brief Precompute cast Arrow scalars for every `kDefault` field under `projection`. | ||
| /// | ||
| /// Walks `root_builder` in lockstep with the projection so each default is cast to the | ||
| /// builder's Arrow type once per scan. Safe to call repeatedly; existing | ||
| /// `AvroDefaultAttributes` entries are left unchanged. | ||
| Status PrepareDefaultScalars(SchemaProjection& projection, | ||
| ::arrow::ArrayBuilder* root_builder); | ||
|
|
||
| /// \brief Append a literal once to `builder` while decoding Avro row-by-row. | ||
| /// | ||
| /// Used to materialize `FieldProjection::Kind::kDefault`. Shares `ToArrowScalar` with | ||
| /// Parquet's batch path (`MakeDefaultArray`); the append shape stays Avro-local because | ||
| /// Avro builds Arrow arrays via per-row `ArrayBuilder`s rather than whole-column arrays. | ||
| /// Prefer the `FieldProjection` overload after `PrepareDefaultScalars` so the scalar is | ||
| /// reused across rows. | ||
| Status AppendDefaultToBuilder(const Literal& literal, ::arrow::ArrayBuilder* builder); | ||
|
|
||
| /// \brief Append a `kDefault` projection, reusing a scalar cached on | ||
| /// `projection.attributes` when present. | ||
| Status AppendDefaultToBuilder(const FieldProjection& projection, | ||
| ::arrow::ArrayBuilder* builder); | ||
|
|
||
| /// \brief Append an Avro datum to an Arrow array builder. | ||
| /// | ||
| /// This function handles schema evolution by using the provided projection to map | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.