mbutrovich commented on code in PR #4507:
URL: https://github.com/apache/datafusion-comet/pull/4507#discussion_r3391147971


##########
native/core/src/execution/operators/schema_align.rs:
##########
@@ -0,0 +1,268 @@
+// 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.
+
+//! `SchemaAlignExec` reshapes its child's output so the per-column Arrow type 
and field-level
+//! nullability match what Spark catalyst declared, casting where necessary. 
Sits between a native
+//! subtree and `ShuffleWriterExec` so DataFusion / `datafusion-spark` 
return-type drift is caught
+//! before it reaches shuffle blocks. See
+//! <https://github.com/apache/datafusion-comet/issues/4515> for the running 
list of mismatched
+//! functions.
+
+use arrow::array::{ArrayRef, RecordBatch, RecordBatchOptions};
+use arrow::compute::{cast_with_options, CastOptions};
+use arrow::datatypes::{Field, Schema, SchemaRef};
+use datafusion::common::DataFusionError;
+use datafusion::physical_expr::EquivalenceProperties;
+use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType};
+use datafusion::{
+    execution::TaskContext,
+    physical_plan::{
+        DisplayAs, DisplayFormatType, ExecutionPlan, ExecutionPlanProperties, 
PlanProperties,
+        RecordBatchStream, SendableRecordBatchStream,
+    },
+};
+use futures::{Stream, StreamExt};
+use std::{
+    any::Any,
+    collections::HashSet,
+    pin::Pin,
+    sync::{Arc, Mutex, OnceLock},
+    task::{Context, Poll},
+};
+
+/// Process-wide set of `(column, actual, expected)` signatures we have 
already warned about.
+/// Each schema drift produces the same warning on every partition of every 
query that runs
+/// the offending expression; deduping here keeps logs readable while still 
surfacing each
+/// distinct mismatch once.
+fn warn_dedup() -> &'static Mutex<HashSet<String>> {
+    static SET: OnceLock<Mutex<HashSet<String>>> = OnceLock::new();
+    SET.get_or_init(|| Mutex::new(HashSet::new()))
+}
+
+/// Casts each column of `child`'s output to the data_type Spark catalyst 
declared, widening
+/// nullability to `actual.nullable || expected.nullable`. See
+/// <https://github.com/apache/datafusion-comet/issues/4515>.
+#[derive(Debug)]
+pub struct SchemaAlignExec {

Review Comment:
   Added Rust unit tests for `SchemaAlignExec` in `schema_align.rs`, one per 
concrete drift tracked in #4515:
   
   - `aligns_width_bucket_int32_to_int64` - top-level `Int32` -> `Int64` cast, 
values preserved.
   - `aligns_date_trunc_timestamp_timezone` - `Timestamp(us)` -> `Timestamp(us, 
"UTC")`, instants unchanged.
   - `aligns_collect_set_list_element_nullability` - the interesting one: 
`List(nullable Int32)` -> `List(non-null Int32)`. This narrows the inner 
element nullability, and I wasn't sure arrow's list cast would do that rather 
than fail the re-stamp on DataType inequality. It does. The test confirms the 
cast reshapes the inner field and the batch re-stamps cleanly, so the operator 
genuinely covers the nested `collect_set` case, not just the top-level ones.
   
   All three pass. The module doc-comment also records the intent: each test is 
anchored to a drift pair, so when a function's upstream return type is 
corrected the pair collapses, `try_new_or_passthrough` returns the child 
unwrapped, and the matching test flips to a passthrough assertion. That is the 
signal the workaround for that function can be removed, which lines up with 
wanting this class to eventually go away.
   



-- 
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