Skip to content

Commit

Permalink
add more supported casts
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed May 23, 2024
1 parent 3a1c387 commit 60354bd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/src/execution/datafusion/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ impl Cast {
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 {
match (from_type, to_type) {
(
Expand All @@ -636,6 +638,28 @@ impl Cast {
| DataType::Decimal128(_, _)
| DataType::Utf8,
) => true,
(
DataType::Float32 | DataType::Float64,
DataType::Boolean
| DataType::Int8
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::Float32
| DataType::Float64,
) => true,
(
DataType::Decimal128(_, _),
DataType::Int8
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::Float32
| DataType::Float64,
) => true,
(DataType::Utf8, DataType::Binary) => true,
(DataType::Date32 | DataType::Timestamp(_, _), DataType::Utf8) => true,
(DataType::Timestamp(_, _), DataType::Int64 | DataType::Date32) => true,
_ => false,
}
}
Expand Down

0 comments on commit 60354bd

Please sign in to comment.