sunchao commented on code in PR #7381:
URL: https://github.com/apache/datafusion-comet/pull/7381#discussion_r4497716995


##########
native/spark-expr/src/struct_funcs/get_struct_field.rs:
##########
@@ -123,6 +125,26 @@ impl PhysicalExpr for GetStructField {
     }
 }
 
+/// The scalar that a one-row array holds. A list wraps the array as is: 
`try_from_array` rebuilds
+/// a list's element field from its name and nullability, which drops metadata 
such as a Variant
+/// element's extension type, so the scalar's type would no longer match 
`data_type`.
+fn single_row_scalar(array: ArrayRef) -> DataFusionResult<ScalarValue> {
+    Ok(match array.data_type() {
+        DataType::List(_) => 
ScalarValue::List(Arc::new(array.as_list::<i32>().clone())),
+        DataType::LargeList(_) => 
ScalarValue::LargeList(Arc::new(array.as_list::<i64>().clone())),
+        DataType::FixedSizeList(_, _) => {
+            
ScalarValue::FixedSizeList(Arc::new(array.as_fixed_size_list().clone()))
+        }
+        DataType::ListView(_) => {
+            
ScalarValue::ListView(Arc::new(array.as_list_view::<i32>().clone()))
+        }
+        DataType::LargeListView(_) => {
+            
ScalarValue::LargeListView(Arc::new(array.as_list_view::<i64>().clone()))
+        }
+        _ => ScalarValue::try_from_array(&array, 0)?,

Review Comment:
   **Preserve the list element field when extracting a dictionary scalar.** I 
used `CreateNamedStruct` with a literal `Dictionary<Int32, List<Int32>>` whose 
list element carries `ARROW:extension:name`, then evaluated `GetStructField` on 
a one-row batch. The dictionary reaches this fallback, where DataFusion 
recursively converts its list value and drops the element metadata. 
`data_type()` still declares that metadata, so `RecordBatch::try_new` rejects 
the resulting column. The same batch validates on base. Could the dictionary 
conversion extract the referenced value through the same metadata-preserving 
path and retain the key type? A regression test can assert that the result 
constructs a batch with the expression’s declared schema. I reproduced this 
through the native API and found no Spark SQL producer for this encoding.



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