You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by ag...@apache.org on 2026/08/12 14:27:56 UTC
(datafusion-comet) branch main updated: test: cover the narrowing direction of cast_and_stamp_schema (#5285)
This is an automated email from the ASF dual-hosted git repository.
andygrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git
The following commit(s) were added to refs/heads/main by this push:
new 68cbde1605 test: cover the narrowing direction of cast_and_stamp_schema (#5285)
68cbde1605 is described below
commit 68cbde160549f0605bbede2a2c2c62f2570ff9b8
Author: Andy Grove <ag...@apache.org>
AuthorDate: Wed Aug 12 07:27:50 2026 -0700
test: cover the narrowing direction of cast_and_stamp_schema (#5285)
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.
---
native/common/src/schema.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/native/common/src/schema.rs b/native/common/src/schema.rs
index 2b5995c8c2..312861999f 100644
--- a/native/common/src/schema.rs
+++ b/native/common/src/schema.rs
@@ -340,6 +340,57 @@ mod tests {
))
}
+ /// The narrowing direction of the same reconciliation. Rewriting a nullable child as non-null
+ /// is only safe when the child holds no nulls, so the flag alone must not decide the outcome:
+ /// null-free data narrows, and data with a real null errors instead of producing an array whose
+ /// nullability misreports its own contents.
+ #[test]
+ fn narrowing_a_child_errors_only_when_it_holds_a_null() {
+ let schema = Arc::new(Schema::new(vec![Field::new(
+ "c0",
+ DataType::List(struct_field(false)),
+ true,
+ )]));
+
+ let batch =
+ cast_and_stamp_schema("TestExec", &schema, vec![nullable_flag_list(None)], 2).unwrap();
+ assert_eq!(batch.schema(), schema);
+
+ let err = cast_and_stamp_schema("TestExec", &schema, vec![nullable_flag_list(Some(1))], 2)
+ .unwrap_err();
+ let msg = err.to_string();
+ assert!(msg.contains("TestExec"), "{msg}");
+ assert!(msg.contains("col[0]"), "{msg}");
+ assert!(
+ msg.contains("c0.element.flag: expected non-null Boolean, found nullable Boolean"),
+ "{msg}"
+ );
+ }
+
+ /// `[[{1,_},{2,_}], [{3,_}]]` with a *nullable* `flag` child, null at `null_at` if given.
+ fn nullable_flag_list(null_at: Option<usize>) -> ArrayRef {
+ let flags: Vec<Option<bool>> = (0..3)
+ .map(|i| if Some(i) == null_at { None } else { Some(true) })
+ .collect();
+ let entries = StructArray::new(
+ Fields::from(vec![
+ Field::new("id", DataType::Int64, true),
+ Field::new("flag", DataType::Boolean, true),
+ ]),
+ vec![
+ Arc::new(Int64Array::from(vec![1, 2, 3])) as ArrayRef,
+ Arc::new(arrow::array::BooleanArray::from(flags)),
+ ],
+ None,
+ );
+ Arc::new(ListArray::new(
+ struct_field(true),
+ OffsetBuffer::new(vec![0, 2, 3].into()),
+ Arc::new(entries),
+ None,
+ ))
+ }
+
#[test]
fn stamps_equal_types_without_copying() {
let schema = Arc::new(Schema::new(vec![Field::new("c0", DataType::Int32, true)]));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org