vaibhawvipul commented on code in PR #627: URL: https://github.com/apache/datafusion-comet/pull/627#discussion_r1675535745
########## native/core/src/execution/datafusion/expressions/scalar_funcs/hex.rs: ########## @@ -118,65 +118,36 @@ pub(super) fn spark_hex(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFus Ok(ColumnarValue::Array(Arc::new(hexed))) } - DataType::Dictionary(_, value_type) if matches!(**value_type, DataType::Int64) => { + DataType::Dictionary(_, value_type) => { let dict = as_dictionary_array::<Int32Type>(&array); - let hexed_values = as_int64_array(dict.values())?; - let values = hexed_values + let values = match **value_type { + DataType::Int64 => as_int64_array(dict.values())? + .iter() + .map(|v| v.map(hex_int64)) + .collect::<Vec<_>>(), + DataType::Utf8 => as_string_array(dict.values()) + .iter() + .map(|v| v.map(hex_bytes).transpose()) + .collect::<Result<_, _>>()?, + DataType::Binary => as_binary_array(dict.values())? + .iter() + .map(|v| v.map(hex_bytes).transpose()) + .collect::<Result<_, _>>()?, + _ => exec_err!( + "hex got an unexpected argument type: {:?}", + array.data_type() + )?, + }; + + let new_values: Vec<Option<String>> = dict + .keys() .iter() - .map(|v| v.map(hex_int64)) - .collect::<Vec<_>>(); + .map(|key| key.map(|k| values[k as usize].clone()).unwrap_or(None)) + .collect(); - let keys = dict.keys().clone(); - let mut new_keys = Vec::with_capacity(values.len()); + let string_array_values = StringArray::from(new_values); Review Comment: did a small benchmark by timing `hex` testcase in CometExpressionSuite. Old code - 3600 ms New code - 2950ms -- 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