zephyr: widen inferred parquet schema via pa.unify_schemas#5142
Merged
ravwojdyla merged 1 commit intomainfrom Apr 23, 2026
Merged
zephyr: widen inferred parquet schema via pa.unify_schemas#5142ravwojdyla merged 1 commit intomainfrom
ravwojdyla merged 1 commit intomainfrom
Conversation
d59176a to
82bb2fa
Compare
``_accumulate_tables`` infers its schema from the first micro-batch (``_MICRO_BATCH_SIZE=8``). If those first records happen to have ``None`` for a field — or to lack a field that appears later — downstream batches that would legitimately widen the schema either crashed with ``ArrowInvalid: Invalid null value`` or (in the new-field case) were silently truncated by ``pa.Table.from_pylist``. Extract the schema-mismatch raise into ``_raise_schema_mismatch`` and add a ``_build_table`` helper that unify-widens the inferred schema on mismatch and reconciles chunks on yield via ``concat_tables(promote_options="permissive")``. Genuine incompatibilities (e.g. int vs string) still raise with both schemas + inference origin shown, so operators can diagnose without extra instrumentation. An explicit caller-provided schema is treated as a contract: mismatches raise without silent widening. Tests cover: null→concrete widening, new-field-appears-later (previously silently dropped), and int-vs-string conflict surfacing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
82bb2fa to
6094008
Compare
rjpower
approved these changes
Apr 23, 2026
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.
_accumulate_tablesinfers schema from the first_MICRO_BATCH_SIZE=8records — so if those records haveNonefor an optional field, the field gets pinned topa.null()and later records with real values crash withArrowInvalid: Invalid null valuecommon-pile/stackv2's nestedmetadata.gha_language(959 null / 1041 str across ~2000 records) was deterministically failingpa.Table.from_pylistsilently drops top-level keys missing from the pinned schema — any new column appearing in a later batch was being truncated without a signal 1pa.unify_schemasand rebuild the batch against the widened schema; reconcile prior chunks on yield viaconcat_tables(promote_options="permissive")intvsstringfor the same field) still raise with both schemas + inference origin shown, so operators can diagnose without extra instrumentationTest plan
test_write_parquet_file_widens_null_to_concrete_type— null→string widening succeeds and lands the widened schema on disktest_write_parquet_file_captures_fields_appearing_in_later_batches— new field survives to disk instead of being silently droppedtest_write_parquet_file_raises_on_incompatible_type_conflict— int vs string still surfaces as a clear error🤖 Generated with Claude Code
Footnotes
this silent-drop behavior was a latent data-loss bug; the new extra-keys detection catches it and routes through the same widen path. ↩