comphead commented on code in PR #307:
URL: https://github.com/apache/datafusion-comet/pull/307#discussion_r1583667605
##########
core/src/execution/datafusion/expressions/cast.rs:
##########
@@ -103,10 +125,76 @@ impl Cast {
(DataType::LargeUtf8, DataType::Boolean) => {
Self::spark_cast_utf8_to_boolean::<i64>(&array,
self.eval_mode)?
}
- _ => cast_with_options(&array, to_type, &CAST_OPTIONS)?,
+ (
+ DataType::Utf8,
+ DataType::Int8 | DataType::Int16 | DataType::Int32 |
DataType::Int64,
+ ) => Self::cast_string_to_int::<i32>(to_type, &array,
self.eval_mode)?,
+ (
+ DataType::LargeUtf8,
+ DataType::Int8 | DataType::Int16 | DataType::Int32 |
DataType::Int64,
+ ) => Self::cast_string_to_int::<i64>(to_type, &array,
self.eval_mode)?,
+ (
+ DataType::Dictionary(key_type, value_type),
+ DataType::Int8 | DataType::Int16 | DataType::Int32 |
DataType::Int64,
+ ) if key_type.as_ref() == &DataType::Int32
+ && (value_type.as_ref() == &DataType::Utf8
+ || value_type.as_ref() == &DataType::LargeUtf8) =>
+ {
+ // TODO: we are unpacking a dictionary-encoded array and then
performing
+ // the cast. We could potentially improve performance here by
casting the
+ // dictionary values directly without unpacking the array
first, although this
+ // would add more complexity to the code
+ match value_type.as_ref() {
+ DataType::Utf8 => {
+ let unpacked_array =
+ cast_with_options(&array, &DataType::Utf8,
&CAST_OPTIONS)?;
+ Self::cast_string_to_int::<i32>(to_type,
&unpacked_array, self.eval_mode)?
+ }
+ DataType::LargeUtf8 => {
+ let unpacked_array =
+ cast_with_options(&array, &DataType::LargeUtf8,
&CAST_OPTIONS)?;
+ Self::cast_string_to_int::<i64>(to_type,
&unpacked_array, self.eval_mode)?
+ }
+ _ => unreachable!("invalid value type for
dictionary-encoded string array"),
Review Comment:
```suggestion
dt => unreachable!(
"{}",
format!("invalid value type {dt} for dictionary-encoded
string array")
),
```
--
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]