adriangb commented on code in PR #16371:
URL: https://github.com/apache/datafusion/pull/16371#discussion_r2157585906


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -83,17 +85,16 @@ pub struct ListingTableConfig {
     pub options: Option<ListingOptions>,
     /// Tracks the source of the schema information
     schema_source: SchemaSource,
+    /// Optional [`SchemaAdapterFactory`] for creating schema adapters
+    schema_adapter_factory: Option<Arc<dyn SchemaAdapterFactory>>,

Review Comment:
   I feel like this part can be split into its own PR



##########
datafusion/common/src/nested_struct.rs:
##########
@@ -0,0 +1,150 @@
+// 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.
+
+use crate::error::Result;
+use arrow::{
+    array::{new_null_array, Array, ArrayRef, StructArray},
+    compute::cast,
+    datatypes::{DataType::Struct, Field},
+};
+use std::sync::Arc;
+/// Adapt a struct column to match the target field type, handling nested 
structs recursively
+fn adapt_struct_column(
+    source_col: &ArrayRef,
+    target_fields: &[Arc<Field>],
+) -> Result<ArrayRef> {
+    if let Some(struct_array) = 
source_col.as_any().downcast_ref::<StructArray>() {
+        let mut children: Vec<(Arc<Field>, Arc<dyn Array>)> = Vec::new();
+        let num_rows = source_col.len();
+
+        for target_child_field in target_fields {
+            let field_arc = Arc::clone(target_child_field);
+            match struct_array.column_by_name(target_child_field.name()) {
+                Some(source_child_col) => {
+                    let adapted_child =
+                        adapt_column(source_child_col, target_child_field)?;
+                    children.push((field_arc, adapted_child));
+                }
+                None => {
+                    children.push((
+                        field_arc,
+                        new_null_array(target_child_field.data_type(), 
num_rows),
+                    ));
+                }
+            }
+        }
+
+        let struct_array = StructArray::from(children);
+        Ok(Arc::new(struct_array))
+    } else {
+        // If source is not a struct, return null array with target struct type
+        Ok(new_null_array(
+            &Struct(target_fields.to_vec().into()),
+            source_col.len(),
+        ))
+    }

Review Comment:
   I agree this should be an error. I think at this point (reading of the data) 
we should only be doing casting, not coercion or in this case replacement with 
nulls.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to