sunchao commented on code in PR #5638:
URL: https://github.com/apache/datafusion-comet/pull/5638#discussion_r3928748087


##########
spark/src/test/scala/org/apache/spark/sql/benchmark/CometIcebergSystemFunctionBenchmark.scala:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.spark.sql.benchmark
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.catalyst.optimizer.ConstantFolding
+import org.apache.spark.sql.internal.SQLConf
+
+import org.apache.comet.CometConf
+import org.apache.comet.iceberg.IcebergReflection
+
+/**
+ * Benchmark of Iceberg's system functions (`bucket`, `truncate`, `years`, 
`months`, `days`,
+ * `hours`) with Comet on and off. The Spark case is Iceberg's own JVM 
implementation: Spark binds
+ * each function as a `StaticInvoke` of the matching class under
+ * `org.apache.iceberg.spark.functions` and whole-stage codegen calls it once 
per row.
+ *
+ * Every case is run over a no-null column and a column with one null in 
eight, and every case's
+ * output is compared between the two engines over the same corpus that is 
then timed, so a timing
+ * cannot come from an engine that computed something else.
+ *
+ * To run this benchmark:
+ * {{{
+ *   SPARK_GENERATE_BENCHMARK_FILES=1 make 
benchmark-org.apache.spark.sql.benchmark.CometIcebergSystemFunctionBenchmark
+ * }}}
+ * Results will be written to
+ * "spark/benchmarks/CometIcebergSystemFunctionBenchmark-**results.txt".
+ */
+object CometIcebergSystemFunctionBenchmark extends CometBenchmarkBase {
+
+  private val catalog = "benchmark_cat"
+
+  /** One null in eight, matching the null rate of the correctness suite's 
corpus. */
+  private val NullStride = 8
+
+  /**
+   * Column types each transform accepts. `str_dict` holds eight distinct 
values so Parquet
+   * dictionary-encodes it, which is the shape a string partition column 
normally arrives in;
+   * `str` is distinct per row. `truncate` on a decimal is absent because it 
falls back to Spark
+   * (see the Iceberg user guide), so there is no native path to measure.
+   */
+  private val bucketTypes = Seq("int", "long", "dec", "str_dict", "str", 
"bin", "date", "ts")
+  private val truncateTypes = Seq("int", "long", "str_dict", "str", "bin")
+
+  /** (case name, query) for every transform, input type, and null variant. */
+  private def cases: Seq[(String, String)] = {
+    def variants(types: Seq[String])(select: String => String): Seq[(String, 
String)] =
+      for {
+        t <- types
+        (suffix, tag) <- Seq("" -> "", "_n" -> ", nulls")
+      } yield {
+        val column = s"c_$t$suffix"
+        s"$t$tag" -> s"select ${select(column)} from parquetV1Table"
+      }
+
+    val bucket = variants(bucketTypes)(c => s"$catalog.system.bucket(16, $c)")
+      .map { case (name, query) => s"bucket($name)" -> query }
+    val truncate = variants(truncateTypes)(c => s"$catalog.system.truncate(4, 
$c)")
+      .map { case (name, query) => s"truncate($name)" -> query }
+    val temporal = Seq("years", "months", "days").flatMap { fn =>
+      variants(Seq("date", "ts"))(c => s"$catalog.system.$fn($c)").map { case 
(name, query) =>
+        s"$fn($name)" -> query
+      }
+    }
+    val hours = variants(Seq("ts"))(c => s"$catalog.system.hours($c)").map { 
case (name, query) =>
+      s"hours($name)" -> query
+    }
+    bucket ++ truncate ++ temporal ++ hours
+  }
+
+  /**
+   * Fails if the two engines disagree on `query`. Rows are compared 
positionally: both cases read
+   * the same Parquet files with the same partitioning and neither plan 
shuffles, so the scan
+   * order is the same. The confs match the ones the benchmark times.
+   */
+  private def verifyOutputsMatch(name: String, query: String): Unit = {
+    def collect(cometEnabled: Boolean): Array[Row] =
+      withSQLConf(

Review Comment:
   [P1] Keep the benchmark collection helper compatible with Spark 3.x
   
   This method promises `Array[Row]`, but the inherited Spark 3.5 
`SQLHelper.withSQLConf` takes `f: => Unit` and returns `Unit`. Returning the 
wrapper directly therefore does not compile. Spark 4's generic result-returning 
helper masks this difference. The current [Spark 3.5 CI 
job](https://github.com/apache/datafusion-comet/actions/runs/33804169549/job/100811236824)
 reports `found: Unit, required: Array[org.apache.spark.sql.Row]` at this line. 
The Spark 3.4 job and both Celeborn compatibility jobs fail on the same error, 
before their tests can run.
   
   Could you capture the collected rows inside the configuration scope and 
return them afterward, or use an existing cross-version result-returning 
helper? Please verify test compilation on Spark 3.4 and 3.5 as well as the 
Spark 4 profile.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to