andygrove commented on code in PR #461:
URL: https://github.com/apache/datafusion-comet/pull/461#discussion_r1614789127
##########
core/src/execution/datafusion/expressions/cast.rs:
##########
@@ -622,14 +590,89 @@ impl Cast {
self.eval_mode,
from_type,
to_type,
- )?
+ )
+ }
+ _ if Self::is_datafusion_spark_compatible(from_type, to_type) => {
+ // use DataFusion cast only when we know that it is compatible
with Spark
+ Ok(cast_with_options(&array, to_type, &CAST_OPTIONS)?)
}
_ => {
- // when we have no Spark-specific casting we delegate to
DataFusion
- cast_with_options(&array, to_type, &CAST_OPTIONS)?
+ // we should never reach this code because the Scala code
should be checking
+ // for supported cast operations and falling back to Spark for
anything that
+ // is not yet supported
+ Err(CometError::Internal(format!(
+ "Native cast invoked for unsupported cast from
{from_type:?} to {to_type:?}"
+ )))
}
};
- Ok(spark_cast(cast_result, from_type, to_type))
+ Ok(spark_cast(cast_result?, from_type, to_type))
+ }
+
+ /// Determines if DataFusion supports the given cast in a way that is
+ /// compatible with Spark
+ fn is_datafusion_spark_compatible(from_type: &DataType, to_type:
&DataType) -> bool {
+ if from_type == to_type {
+ return true;
+ }
+ match from_type {
+ DataType::Boolean => matches!(
+ to_type,
+ DataType::Int8
+ | DataType::Int16
+ | DataType::Int32
+ | DataType::Int64
+ | DataType::Float32
+ | DataType::Float64
+ | DataType::Utf8
Review Comment:
This test relies on a cast that we do not yet support and enables
`COMET_CAST_ALLOW_INCOMPATIBLE` to allow it. I will revert the last change and
add a comment about this
--
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]