feat(avro): apply column default values when reading missing fields#800
Open
huan233usc wants to merge 4 commits into
Open
feat(avro): apply column default values when reading missing fields#800huan233usc wants to merge 4 commits into
huan233usc wants to merge 4 commits into
Conversation
huan233usc
force-pushed
the
feat/default-values-read-avro
branch
from
July 12, 2026 21:10
75bd63f to
950f4dc
Compare
…3/4) When a column is present in the read schema but missing from an Avro data file (written before the column existed), fill it with the column's v3 initial-default instead of null. Reuses the shared arrow/literal_util materializer (merged in apache#792) and adds AppendDefaultToBuilder for the row-by-row Avro decode paths, plus a kDefault projection branch in the Avro schema/data projection. Part 3 of the v3 column-default-values work (POC apache#731), built on the schema support in apache#746 and the Parquet read path in apache#792.
Row-oriented Avro decode needs per-builder appends, while Parquet uses batch MakeDefaultArray. Share ToArrowScalar only; don't put the Avro shape into the shared arrow literal util.
huan233usc
force-pushed
the
feat/default-values-read-avro
branch
from
July 20, 2026 04:38
0961b90 to
9e1605f
Compare
huan233usc
marked this pull request as ready for review
July 20, 2026 04:39
There was a problem hiding this comment.
Pull request overview
Adds Avro read-path support for Iceberg v3 initial-default column defaults, ensuring that when projected (table) schema fields are missing from older Avro files, readers materialize the specified defaults instead of null.
Changes:
- Avro schema projection: project missing fields with
initial-defaultasFieldProjection::Kind::kDefault. - Avro decode paths (generic + direct): materialize
kDefaultby appending the literal default into Arrow builders via a new Avro-localAppendDefaultToBuilder. - Tests: add unit coverage for default appends and an end-to-end Avro read test exercising schema evolution with defaults.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/iceberg/avro/avro_schema_util.cc | Projects missing fields with initial-default as kDefault. |
| src/iceberg/avro/avro_data_util.cc | Implements and uses AppendDefaultToBuilder to materialize kDefault during generic Avro decoding. |
| src/iceberg/avro/avro_direct_decoder.cc | Materializes kDefault during direct decoding into Arrow builders. |
| src/iceberg/avro/avro_data_util_internal.h | Exposes AppendDefaultToBuilder for reuse across Avro decode implementations. |
| src/iceberg/test/avro_data_test.cc | Adds unit tests covering default materialization behavior. |
| src/iceberg/test/avro_test.cc | Adds end-to-end test for reading missing fields with defaults using an evolved schema. |
Precompute cast scalars in FieldProjection attributes via PrepareDefaultScalars at reader init so per-row default fills only call AppendScalar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Part 3 of 4 of Iceberg v3 column default-value support (POC #731), built on the
schema layer (#746) and the Parquet read path (#792).
When a column is present in the read (table) schema but absent from an Avro data
file — because the column was added after those rows were written — fill it with
the column's v3
initial-defaultinstead ofnull.Changes
avro_schema_util.cc): when a field is missing from thefile and carries an
initial-default, project it asFieldProjection::Kind::kDefault, mirroring the generic / Parquet paths.avro_data_util.cc,avro_direct_decoder.cc): materializethe
kDefaultbranch through an Avro-localAppendDefaultToBuilderhelper.It reuses the shared
ToArrowScalarconversion, while keeping Avro'srow-by-row
ArrayBuilderappend behavior out of the shared Arrow utility.Tests
avro_data_test:AppendDefaultToBuilderappends a value and casts to thebuilder type;
AppendDatumToBuilderfills missing required and optionaldefault fields.
avro_test: end-to-end — write an Avro file with an old schema, then read itthrough
ReaderFactoryRegistrywith an evolved schema carrying defaults(
ReadMissingFieldsWithDefaults).Stack
addColumn/updateColumnDefault(feat: support v3 column default values in UpdateSchema (3/4) #793)Draft while the earlier PRs in the stack settle.