adriangb commented on code in PR #17281: URL: https://github.com/apache/datafusion/pull/17281#discussion_r2300933932
########## datafusion/common/src/nested_struct.rs: ########## @@ -159,14 +200,23 @@ pub fn cast_column(source_col: &ArrayRef, target_field: &Field) -> Result<ArrayR pub fn validate_struct_compatibility( source_fields: &[FieldRef], target_fields: &[FieldRef], -) -> Result<bool> { +) -> Result<()> { // Check compatibility for each target field for target_field in target_fields { // Look for matching field in source by name if let Some(source_field) = source_fields .iter() .find(|f| f.name() == target_field.name()) { + // Ensure nullability is compatible. It is invalid to cast a nullable + // source field to a non-nullable target field as this may discard + // null values. Review Comment: I assume this means that you can't cast null values into a non-nullable schema. Is that right? ########## datafusion/expr-common/src/columnar_value.rs: ########## @@ -210,9 +210,22 @@ impl ColumnarValue { ) -> Result<ColumnarValue> { let cast_options = cast_options.cloned().unwrap_or(DEFAULT_CAST_OPTIONS); match self { - ColumnarValue::Array(array) => Ok(ColumnarValue::Array( - kernels::cast::cast_with_options(array, cast_type, &cast_options)?, - )), + ColumnarValue::Array(array) => match cast_type { + // fix https://github.com/apache/datafusion/issues/17285 + DataType::Struct(_) => { + let field = Field::new("", cast_type.clone(), true); + Ok(ColumnarValue::Array(cast_column( + array, + &field, + &cast_options, + )?)) + } + _ => Ok(ColumnarValue::Array(kernels::cast::cast_with_options( + array, + cast_type, + &cast_options, + )?)), + }, Review Comment: Nice! Would it be possible to isolate this fix into it's own PR? -- 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