parthchandra commented on code in PR #1374:
URL: https://github.com/apache/datafusion-comet/pull/1374#discussion_r1948989419


##########
spark/src/test/scala/org/apache/spark/sql/CometTestBase.scala:
##########
@@ -116,12 +116,49 @@ abstract class CometTestBase
     require(absTol > 0 && absTol <= 1e-6, s"absTol $absTol is out of range (0, 
1e-6]")
 
     actualAnswer.toSeq.zip(expectedAnswer.toSeq).foreach {
+      case (actual: Float, expected: Float) =>
+        def isPosInfinity(value: Float): Boolean = {
+          value.isPosInfinity || value == 3.4028235e38
+        }
+
+        if ((actual.isNaN && expected.isNaN) ||
+          (isPosInfinity(actual) && isPosInfinity(expected)) ||
+          (actual.isNegInfinity && expected.isNegInfinity)) {
+          // ok
+        } else {
+
+          def almostEqual(a: Double, b: Double, tolerance: Double = 1e-6f): 
Boolean = {
+            Math.abs(a - b) <= tolerance * Math.max(Math.abs(a), Math.abs(b))
+          }
+
+          assert(
+            almostEqual(actual, expected),
+            s"actual answer $actual not within $absTol of correct answer 
$expected")
+        }
+
       case (actual: Double, expected: Double) =>
-        if (!actual.isNaN && !expected.isNaN) {
+        def isPosInfinity(value: Double): Boolean = {
+          value.isPosInfinity || value == 3.4028235e38
+        }
+
+        if ((actual.isNaN && expected.isNaN) ||
+          (isPosInfinity(actual) && isPosInfinity(expected)) ||
+          (actual.isNegInfinity && expected.isNegInfinity)) {
+          // ok
+        } else {
+
+          def almostEqual(a: Double, b: Double, tolerance: Double = 1e-6f): 
Boolean = {

Review Comment:
   Same implementation as above



##########
spark/src/test/scala/org/apache/spark/sql/CometTestBase.scala:
##########
@@ -116,12 +116,49 @@ abstract class CometTestBase
     require(absTol > 0 && absTol <= 1e-6, s"absTol $absTol is out of range (0, 
1e-6]")
 
     actualAnswer.toSeq.zip(expectedAnswer.toSeq).foreach {
+      case (actual: Float, expected: Float) =>
+        def isPosInfinity(value: Float): Boolean = {
+          value.isPosInfinity || value == 3.4028235e38
+        }
+
+        if ((actual.isNaN && expected.isNaN) ||
+          (isPosInfinity(actual) && isPosInfinity(expected)) ||
+          (actual.isNegInfinity && expected.isNegInfinity)) {
+          // ok
+        } else {
+
+          def almostEqual(a: Double, b: Double, tolerance: Double = 1e-6f): 
Boolean = {

Review Comment:
   Looks like there are multiple identical definitions of `almostEqual`? 



##########
spark/src/test/scala/org/apache/comet/CometFuzzTestSuite.scala:
##########
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet
+
+import scala.util.Random
+
+import org.apache.hadoop.fs.Path
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
+import org.apache.spark.sql.types._
+
+import org.apache.comet.testing.{DataGenOptions, ParquetGenerator}
+
+class CometFuzzTestSuite extends CometTestBase with AdaptiveSparkPlanHelper {
+
+  private val fuzzTestEnabled: Boolean = sys.env.contains("COMET_FUZZ_TEST")
+
+  test("aggregates") {
+    assume(fuzzTestEnabled)
+    withTempDir { dir =>
+      val path = new Path(dir.toURI.toString, "test.parquet")
+      val filename = path.toString
+      val random = new Random(42)
+      withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+        ParquetGenerator.makeParquetFile(random, spark, filename, 10000, 
DataGenOptions())
+      }
+      val table = spark.read.parquet(filename).coalesce(1)
+      table.createOrReplaceTempView("t1")
+
+      val groupingFields: Array[StructField] = 
table.schema.fields.filterNot(isNumeric)
+
+      // test grouping by each non-numeric column, grouping by all non-numeric 
columns, and no grouping
+      val groupByIndividualCols: Seq[Seq[String]] = groupingFields.map(f => 
Seq(f.name)).toSeq
+      val groupByAllCols: Seq[Seq[String]] = 
Seq(groupingFields.map(_.name).toSeq)
+      val noGroup: Seq[Seq[String]] = Seq(Seq.empty)
+      val groupings: Seq[Seq[String]] = groupByIndividualCols ++ 
groupByAllCols ++ noGroup
+
+      val scanTypes = Seq(
+        CometConf.SCAN_NATIVE_COMET
+          /*CometConf.SCAN_NATIVE_DATAFUSION,

Review Comment:
   Do we plan to have these scan implementations also added to the fuzz testing 
at some point?



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