bvolpato commented on code in PR #24158:
URL: https://github.com/apache/datafusion/pull/24158#discussion_r3771919383


##########
datafusion/substrait/src/logical_plan/consumer/expr/literal.rs:
##########
@@ -583,13 +700,144 @@ pub(crate) fn from_substrait_literal(
         _ => return not_impl_err!("Unsupported literal_type: {:?}", 
lit.literal_type),
     };
 
+    if let Some(expected_field) = expected_field
+        && scalar_value.data_type() != *expected_field.data_type()
+    {
+        return substrait_err!(
+            "Literal type mismatch: expected {:?} but found {:?}",
+            expected_field.data_type(),
+            scalar_value.data_type()
+        );
+    }
+
     Ok(scalar_value)
 }
 
+fn expected_list_item(
+    expected_field: Option<&Field>,
+    type_variation_reference: u32,
+) -> datafusion::common::Result<Option<&FieldRef>> {
+    let Some(expected_field) = expected_field else {
+        return Ok(None);
+    };
+
+    match (expected_field.data_type(), type_variation_reference) {
+        (DataType::List(item), DEFAULT_CONTAINER_TYPE_VARIATION_REF)
+        | (DataType::LargeList(item), LARGE_CONTAINER_TYPE_VARIATION_REF) => {
+            Ok(Some(item))
+        }
+        (expected, _) => substrait_err!(
+            "Expected List literal to have List or LargeList type, found 
{expected:?}"
+        ),
+    }
+}
+
+fn make_list_scalar(
+    elements: Vec<ScalarValue>,
+    expected_item: &FieldRef,
+    type_variation_reference: u32,
+) -> datafusion::common::Result<ScalarValue> {
+    let values = if elements.is_empty() {
+        new_empty_array(expected_item.data_type())
+    } else {
+        ScalarValue::iter_to_array(elements)?
+    };
+
+    match type_variation_reference {
+        DEFAULT_CONTAINER_TYPE_VARIATION_REF => {
+            Ok(ScalarValue::List(Arc::new(ListArray::new(

Review Comment:
   Non-blocking: could we use `ListArray::try_new` / `LargeListArray::try_new` 
here and propagate the error? A Values plan can declare required list items but 
still contain NULL; conversion then builds a nullable child array, so `new` 
unwraps Arrow validation error and panics instead of returning a DataFusion 
error.



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