Skip to content

test: cover the narrowing direction of cast_and_stamp_schema - #5285

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:test/5137-narrowing-error-test
Open

test: cover the narrowing direction of cast_and_stamp_schema#5285
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:test/5137-narrowing-error-test

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Follow-up to review feedback on #5138: #5138 (comment)

Rationale for this change

The doc comment on cast_and_stamp_schema claims that reconciliation follows the declared schema in both directions, and that narrowing a nullable nested child to non-null is not silently lossy because arrow's StructArray::try_new rejects unmasked nulls under a non-nullable field. That claim was not covered by a test, so nothing would catch it if the narrowing direction ever started producing an array whose nullability flag misreports its own contents.

What changes are included in this PR?

One test in native/common/src/schema.rs, narrowing_a_child_errors_only_when_it_holds_a_null. It stamps a List(Struct(nullable Boolean)) array against a schema declaring the child non-null, twice:

  • null-free data narrows successfully and comes back with the declared schema
  • the same shape carrying a real null in the child errors, and the message names the operator, the column index, and the dotted path c0.element.flag

The two cases together pin that the child's nullable flag alone does not decide the outcome: the data does.

No production code changes.

How are these changes tested?

cargo test -p datafusion-comet-common schema:: (10 passed).

The doc on cast_and_stamp_schema claims that narrowing a nullable nested
child to non-null is not silently lossy because arrow rejects unmasked
nulls under a non-nullable field, but no test pinned that. Add one that
stamps a nullable-child array against a non-null-declared schema both
with and without a real null, so the flag alone does not decide the
outcome.
@andygrove
andygrove requested a review from parthchandra August 7, 2026 02:52

@parthchandra parthchandra left a comment

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.

thanks for adding the test @andygrove

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.

2 participants