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


##########
spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala:
##########
@@ -1452,17 +1452,55 @@ class CometExpressionSuite extends CometTestBase with 
AdaptiveSparkPlanHelper {
         withTable(table) {
           sql(s"create table $table(col string, a int, b float) using parquet")
           sql(s"""
-             |insert into $table values
-             |('Spark SQL  ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), 
('苹果手机', NULL, 3.999999)
-             |, ('Spark SQL  ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), 
('苹果手机', NULL, 3.999999)
-             |""".stripMargin)
-          checkSparkAnswerAndOperator("""
-               |select
-               |md5(col), md5(cast(a as string)), md5(cast(b as string)),
-               |hash(col), hash(col, 1), hash(col, 0), hash(col, a, b), 
hash(b, a, col),
-               |sha2(col, 0), sha2(col, 256), sha2(col, 224), sha2(col, 384), 
sha2(col, 512), sha2(col, 128)
-               |from test
+               |insert into $table values
+               |('Spark SQL  ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), 
('苹果手机', NULL, 3.999999)
+               |, ('Spark SQL  ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), 
('苹果手机', NULL, 3.999999)
                |""".stripMargin)
+          checkSparkAnswerAndOperator("""
+              |select
+              |md5(col), md5(cast(a as string)), md5(cast(b as string)),
+              |hash(col), hash(col, 1), hash(col, 0), hash(col, a, b), hash(b, 
a, col),
+              |sha2(col, 0), sha2(col, 256), sha2(col, 224), sha2(col, 384), 
sha2(col, 512), sha2(col, 128)
+              |from test
+              |""".stripMargin)
+        }
+      }
+    }
+  }
+
+  test("hash functions with random input") {
+    val dataGen = DataGenerator.DEFAULT
+    // sufficient number of rows to create dictionary encoded ArrowArray.
+    val randomNumRows = 1000

Review Comment:
   Some note here: 
   I'm not 100 percent sure how we could trigger a dictionary array in the 
native side from Spark.
   
   When the random number is small, such as 100/200, there's no dictionary 
array involved in the native side, although the parquet should be written as 
all columns dictionary encoded.
   
   I tweaked a bit and settled with 1000, which triggers a dictionary encoded 
ArrowArray in the rust side.



##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -363,78 +368,64 @@ mod tests {
     use crate::execution::datafusion::spark_hash::{create_hashes, pmod};
     use datafusion::arrow::array::{ArrayRef, Int32Array, Int64Array, 
Int8Array, StringArray};
 
-    macro_rules! test_hashes {
-        ($ty:ty, $values:expr, $expected:expr) => {
-            let i = Arc::new(<$ty>::from($values)) as ArrayRef;
-            let mut hashes = vec![42; $values.len()];
+    macro_rules! test_hashes_internal {
+        ($input: expr, $len: expr, $expected: expr) => {
+            let i = $input as ArrayRef;
+            let mut hashes = vec![42; $len];
             create_hashes(&[i], &mut hashes).unwrap();
             assert_eq!(hashes, $expected);
         };
     }
 
+    fn test_murmur3_hash<I: Clone, T: arrow_array::Array + 
From<Vec<Option<I>>> + 'static>(

Review Comment:
   refactor a bit, so that we don't have to write for both non-null and 
nullable input.
   
   It will also be useful if we add more hash function support.



##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -95,19 +98,8 @@ pub(crate) fn spark_compatible_murmur3_hash<T: 
AsRef<[u8]>>(data: T, seed: u32)
     }
 }
 
-#[test]
-fn test_murmur3() {

Review Comment:
   This is moved to the `test_str` function in the ending of this file. It 
doesn't compare hashes and expected before.



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