andygrove commented on code in PR #1169:
URL: https://github.com/apache/datafusion-comet/pull/1169#discussion_r1889200032
##########
native/spark-expr/src/cast.rs:
##########
@@ -642,70 +872,66 @@ fn cast_array(
let eval_mode = cast_options.eval_mode;
let cast_result = match (from_type, to_type) {
- (DataType::Utf8, DataType::Boolean) =>
spark_cast_utf8_to_boolean::<i32>(&array, eval_mode),
- (DataType::LargeUtf8, DataType::Boolean) => {
- spark_cast_utf8_to_boolean::<i64>(&array, eval_mode)
- }
- (DataType::Utf8, DataType::Timestamp(_, _)) => {
+ (Utf8, Boolean) => spark_cast_utf8_to_boolean::<i32>(&array,
eval_mode),
+ (LargeUtf8, Boolean) => spark_cast_utf8_to_boolean::<i64>(&array,
eval_mode),
+ (Utf8, Timestamp(_, _)) => {
cast_string_to_timestamp(&array, to_type, eval_mode,
&cast_options.timezone)
}
- (DataType::Utf8, DataType::Date32) => cast_string_to_date(&array,
to_type, eval_mode),
- (DataType::Int64, DataType::Int32)
- | (DataType::Int64, DataType::Int16)
- | (DataType::Int64, DataType::Int8)
- | (DataType::Int32, DataType::Int16)
- | (DataType::Int32, DataType::Int8)
- | (DataType::Int16, DataType::Int8)
+ (Utf8, Date32) => cast_string_to_date(&array, to_type, eval_mode),
+ (Int64, Int32)
+ | (Int64, Int16)
+ | (Int64, Int8)
+ | (Int32, Int16)
+ | (Int32, Int8)
+ | (Int16, Int8)
if eval_mode != EvalMode::Try =>
{
spark_cast_int_to_int(&array, eval_mode, from_type, to_type)
}
- (DataType::Utf8, DataType::Int8 | DataType::Int16 | DataType::Int32 |
DataType::Int64) => {
+ (Utf8, Int8 | Int16 | Int32 | Int64) => {
cast_string_to_int::<i32>(to_type, &array, eval_mode)
}
- (
- DataType::LargeUtf8,
- DataType::Int8 | DataType::Int16 | DataType::Int32 |
DataType::Int64,
- ) => cast_string_to_int::<i64>(to_type, &array, eval_mode),
- (DataType::Float64, DataType::Utf8) =>
spark_cast_float64_to_utf8::<i32>(&array, eval_mode),
- (DataType::Float64, DataType::LargeUtf8) => {
- spark_cast_float64_to_utf8::<i64>(&array, eval_mode)
- }
- (DataType::Float32, DataType::Utf8) =>
spark_cast_float32_to_utf8::<i32>(&array, eval_mode),
- (DataType::Float32, DataType::LargeUtf8) => {
- spark_cast_float32_to_utf8::<i64>(&array, eval_mode)
- }
- (DataType::Float32, DataType::Decimal128(precision, scale)) => {
+ (LargeUtf8, Int8 | Int16 | Int32 | Int64) => {
+ cast_string_to_int::<i64>(to_type, &array, eval_mode)
+ }
+ (Float64, Utf8) => spark_cast_float64_to_utf8::<i32>(&array,
eval_mode),
+ (Float64, LargeUtf8) => spark_cast_float64_to_utf8::<i64>(&array,
eval_mode),
+ (Float32, Utf8) => spark_cast_float32_to_utf8::<i32>(&array,
eval_mode),
+ (Float32, LargeUtf8) => spark_cast_float32_to_utf8::<i64>(&array,
eval_mode),
+ (Float32, Decimal128(precision, scale)) => {
cast_float32_to_decimal128(&array, *precision, *scale, eval_mode)
}
- (DataType::Float64, DataType::Decimal128(precision, scale)) => {
+ (Float64, Decimal128(precision, scale)) => {
cast_float64_to_decimal128(&array, *precision, *scale, eval_mode)
}
- (DataType::Float32, DataType::Int8)
- | (DataType::Float32, DataType::Int16)
- | (DataType::Float32, DataType::Int32)
- | (DataType::Float32, DataType::Int64)
- | (DataType::Float64, DataType::Int8)
- | (DataType::Float64, DataType::Int16)
- | (DataType::Float64, DataType::Int32)
- | (DataType::Float64, DataType::Int64)
- | (DataType::Decimal128(_, _), DataType::Int8)
- | (DataType::Decimal128(_, _), DataType::Int16)
- | (DataType::Decimal128(_, _), DataType::Int32)
- | (DataType::Decimal128(_, _), DataType::Int64)
+ (Float32, Int8)
+ | (Float32, Int16)
+ | (Float32, Int32)
+ | (Float32, Int64)
+ | (Float64, Int8)
+ | (Float64, Int16)
+ | (Float64, Int32)
+ | (Float64, Int64)
+ | (Decimal128(_, _), Int8)
+ | (Decimal128(_, _), Int16)
+ | (Decimal128(_, _), Int32)
+ | (Decimal128(_, _), Int64)
if eval_mode != EvalMode::Try =>
{
spark_cast_nonintegral_numeric_to_integral(&array, eval_mode,
from_type, to_type)
}
- (DataType::Struct(_), DataType::Utf8) => {
- Ok(casts_struct_to_string(array.as_struct(), cast_options)?)
- }
- (DataType::Struct(_), DataType::Struct(_)) => Ok(cast_struct_to_struct(
+ (Struct(_), Utf8) => Ok(casts_struct_to_string(array.as_struct(),
cast_options)?),
+ (Struct(_), Struct(_)) => Ok(cast_struct_to_struct(
array.as_struct(),
from_type,
to_type,
cast_options,
)?),
+ (UInt8 | UInt16 | UInt32 | UInt64, Int8 | Int16 | Int32 | Int64)
+ if cast_options.allow_cast_unsigned_ints =>
+ {
+ Ok(cast_with_options(&array, to_type, &CAST_OPTIONS)?)
Review Comment:
Yes, this was the shortest path to getting something working. It is a hack
and we should look at implementing separate logic for Parquet type conversion.
There will be some overlap with Spark cast, so we will likely need to do some
substantial refactoring.
--
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]