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


##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -104,66 +108,110 @@ fn test_murmur3() {
     let _expected = vec![
         142593372, 1485273170, -97053317, 1322437556, -396302900, 814637928,
     ];
+    assert_eq!(_hashes, _expected)
+}
+
+#[inline]
+pub(crate) fn spark_compatible_xxhash64<T: AsRef<[u8]>>(data: T, seed: u64) -> 
u64 {
+    // TODO: Rewrite with a stateless hasher to reduce stack allocation?
+    let mut hasher = XxHash64::with_seed(seed);
+    hasher.write(data.as_ref());
+    hasher.finish()
+}
+
+#[test]
+fn test_xxhash64() {
+    let _hashes = ["", "a", "ab", "abc", "abcd", "abcde"]
+        .into_iter()
+        .map(|s| spark_compatible_xxhash64(s.as_bytes(), 42) as i64)
+        .collect::<Vec<_>>();
+    let _expected = vec![
+        -7444071767201028348,
+        -8582455328737087284,
+        2710560539726725091,
+        1423657621850124518,
+        -6810745876291105281,
+        -990457398947679591,
+    ];
+    assert_eq!(_hashes, _expected);
 }
 
 macro_rules! hash_array {
-    ($array_type:ident, $column: ident, $hashes: ident) => {
+    ($array_type: ident, $column: ident, $hashes: ident, $hash_method: ident) 
=> {
         let array = $column.as_any().downcast_ref::<$array_type>().unwrap();
         if array.null_count() == 0 {
             for (i, hash) in $hashes.iter_mut().enumerate() {
-                *hash = spark_compatible_murmur3_hash(&array.value(i), *hash);
+                *hash = $hash_method(&array.value(i), *hash);
             }
         } else {
             for (i, hash) in $hashes.iter_mut().enumerate() {
                 if !array.is_null(i) {
-                    *hash = spark_compatible_murmur3_hash(&array.value(i), 
*hash);
+                    *hash = $hash_method(&array.value(i), *hash);
                 }
             }
         }
     };
 }
 
 macro_rules! hash_array_primitive {
-    ($array_type:ident, $column: ident, $ty: ident, $hashes: ident) => {
+    ($array_type: ident, $column: ident, $ty: ident, $hashes: ident, 
$hash_method: ident) => {
         let array = $column.as_any().downcast_ref::<$array_type>().unwrap();
         let values = array.values();
 
         if array.null_count() == 0 {
             for (hash, value) in $hashes.iter_mut().zip(values.iter()) {
-                *hash = spark_compatible_murmur3_hash((*value as 
$ty).to_le_bytes(), *hash);
+                *hash = $hash_method((*value as $ty).to_le_bytes(), *hash);
             }
         } else {
             for (i, (hash, value)) in 
$hashes.iter_mut().zip(values.iter()).enumerate() {
                 if !array.is_null(i) {
-                    *hash = spark_compatible_murmur3_hash((*value as 
$ty).to_le_bytes(), *hash);
+                    *hash = $hash_method((*value as $ty).to_le_bytes(), *hash);
+                }
+            }
+        }
+    };
+}
+
+macro_rules! hash_array_primitive_boolean {

Review Comment:
   ```suggestion
   macro_rules! hash_array_boolean {
   ```



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