parthchandra commented on code in PR #5138:
URL: https://github.com/apache/datafusion-comet/pull/5138#discussion_r3732929900


##########
native/common/src/schema.rs:
##########
@@ -0,0 +1,378 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Helpers for reconciling the Arrow type an operator actually produced with 
the type Spark
+//! catalyst declared.
+//!
+//! Arrow treats nested field nullability as part of `DataType` identity, so a 
column whose nested
+//! `nullable` flags are narrower than the declared type is rejected by
+//! `RecordBatch::try_new_with_options` even though the data is fine — a 
non-null child is a strict
+//! subset of a nullable one. Every Comet boundary that stamps a declared 
schema onto a runtime
+//! array therefore normalizes first instead of asserting. See
+//! <https://github.com/apache/datafusion-comet/issues/5137> for the 
boundaries and
+//! <https://github.com/apache/datafusion-comet/issues/4515> for the upstream 
drift itself.
+
+use arrow::array::{ArrayRef, RecordBatch, RecordBatchOptions};
+use arrow::compute::{cast_with_options, CastOptions};
+use arrow::datatypes::{DataType, FieldRef, SchemaRef};
+use datafusion::common::DataFusionError;
+use std::sync::Arc;
+
+/// Builds a `RecordBatch` with `schema` from `columns`, casting any column 
whose Arrow type
+/// differs from the declared field type. `operator` names the caller and is 
used only in error
+/// messages.
+///
+/// This is the normalizing counterpart to stamping `schema` on directly: it 
absorbs the
+/// return-type drift — most commonly a nested `nullable` flag — that native 
kernels and non-Parquet
+/// sources introduce, the same way `ScanExec` absorbs it at the FFI boundary.
+///
+/// Reconciliation follows `schema` in both directions, so it will also narrow 
a nullable nested
+/// child to non-null when that is what `schema` declares. That is not 
silently lossy: arrow's
+/// `StructArray::try_new` rejects unmasked nulls under a non-nullable field, 
so data that cannot
+/// survive the narrowing errors here rather than producing an array that 
misreports itself.

Review Comment:
   I don't think this is covered in the test. Maybe add a test that stamps a 
nullable-child array carrying a real null against a non-null-declared schema 
and asserts it errors?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to