advancedxy commented on code in PR #424:
URL: https://github.com/apache/datafusion-comet/pull/424#discussion_r1623199710


##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -244,111 +283,214 @@ fn create_hashes_dictionary<K: ArrowDictionaryKeyType>(
 ///
 /// The number of rows to hash is determined by `hashes_buffer.len()`.
 /// `hashes_buffer` should be pre-sized appropriately
-pub fn create_hashes<'a>(
-    arrays: &[ArrayRef],
-    hashes_buffer: &'a mut [u32],
-) -> Result<&'a mut [u32]> {
-    for (i, col) in arrays.iter().enumerate() {
-        let first_col = i == 0;
-        match col.data_type() {
-            DataType::Boolean => {
-                hash_array_boolean!(BooleanArray, col, i32, hashes_buffer);
-            }
-            DataType::Int8 => {
-                hash_array_primitive!(Int8Array, col, i32, hashes_buffer);
-            }
-            DataType::Int16 => {
-                hash_array_primitive!(Int16Array, col, i32, hashes_buffer);
-            }
-            DataType::Int32 => {
-                hash_array_primitive!(Int32Array, col, i32, hashes_buffer);
-            }
-            DataType::Int64 => {
-                hash_array_primitive!(Int64Array, col, i64, hashes_buffer);
-            }
-            DataType::Float32 => {
-                hash_array_primitive_float!(Float32Array, col, f32, i32, 
hashes_buffer);
-            }
-            DataType::Float64 => {
-                hash_array_primitive_float!(Float64Array, col, f64, i64, 
hashes_buffer);
-            }
-            DataType::Timestamp(TimeUnit::Second, _) => {
-                hash_array_primitive!(TimestampSecondArray, col, i64, 
hashes_buffer);
-            }
-            DataType::Timestamp(TimeUnit::Millisecond, _) => {
-                hash_array_primitive!(TimestampMillisecondArray, col, i64, 
hashes_buffer);
-            }
-            DataType::Timestamp(TimeUnit::Microsecond, _) => {
-                hash_array_primitive!(TimestampMicrosecondArray, col, i64, 
hashes_buffer);
-            }
-            DataType::Timestamp(TimeUnit::Nanosecond, _) => {
-                hash_array_primitive!(TimestampNanosecondArray, col, i64, 
hashes_buffer);
-            }
-            DataType::Date32 => {
-                hash_array_primitive!(Date32Array, col, i32, hashes_buffer);
-            }
-            DataType::Date64 => {
-                hash_array_primitive!(Date64Array, col, i64, hashes_buffer);
-            }
-            DataType::Utf8 => {
-                hash_array!(StringArray, col, hashes_buffer);
-            }
-            DataType::LargeUtf8 => {
-                hash_array!(LargeStringArray, col, hashes_buffer);
-            }
-            DataType::Binary => {
-                hash_array!(BinaryArray, col, hashes_buffer);
-            }
-            DataType::LargeBinary => {
-                hash_array!(LargeBinaryArray, col, hashes_buffer);
-            }
-            DataType::FixedSizeBinary(_) => {
-                hash_array!(FixedSizeBinaryArray, col, hashes_buffer);
-            }
-            DataType::Decimal128(_, _) => {
-                hash_array_decimal!(Decimal128Array, col, hashes_buffer);
-            }
-            DataType::Dictionary(index_type, _) => match **index_type {
+///
+/// `hash_method` is the hash function to use.
+/// `create_dictionary_hash_method` is the function to create hashes for 
dictionary arrays input.
+macro_rules! create_hashes_internal {
+    ($arrays: ident, $hashes_buffer: ident, $hash_method: ident, 
$create_dictionary_hash_method: ident) => {
+        for (i, col) in $arrays.iter().enumerate() {
+            let first_col = i == 0;
+            match col.data_type() {
+                DataType::Boolean => {
+                    hash_array_boolean!(BooleanArray, col, i32, 
$hashes_buffer, $hash_method);
+                }

Review Comment:
   If I understands your proposal correctly, do you mean something like: 
   ``` rust
       match col.data_type() { 
           DataType::Int8 | DataType::Int16: | DataType::Int32 | 
DataType::Int64 | DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | 
DataType::UInt64 => {
               hash_array_primitive!(get_array_type_of!(col.data_type()), col, 
get_input_native_type_of!(col.data_type()), $hashes_buffer, $hash_method);
           }
           ....
       }
   
   ```
   ?
   
   I tried to implement that, but couldn't find a way to do that. The 
`col.data_type()` is a runtime value, I don't we can infer it in the 
compile-time.



-- 
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

Reply via email to