andygrove commented on code in PR #2932:
URL: https://github.com/apache/datafusion-comet/pull/2932#discussion_r2629170811


##########
spark/src/test/scala/org/apache/spark/sql/benchmark/CometCastBenchmark.scala:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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 scala.util.Try
+
+import org.apache.spark.benchmark.Benchmark
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{DataType, LongType}
+
+import org.apache.comet.CometConf
+import org.apache.comet.expressions.{CometCast, CometEvalMode}
+import org.apache.comet.serde.{Compatible, Incompatible, Unsupported}
+
+/**
+ * Benchmark to measure Comet execution performance. To run this benchmark:
+ * {{{
+ *   SPARK_GENERATE_BENCHMARK_FILES=1 make 
benchmark-org.apache.spark.sql.benchmark.CometCastBenchmark
+ * }}}
+ *
+ * Results will be written to 
"spark/benchmarks/CometCastBenchmark-**results.txt".
+ */
+
+object CometCastBenchmark extends CometBenchmarkBase {
+
+  override def getSparkSession: SparkSession = {
+    val session = super.getSparkSession
+    session.conf.set("parquet.enable.dictionary", "false")
+    session.conf.set("spark.sql.shuffle.partitions", "2")
+    session
+  }
+
+  // Wrapper on SQL cast function
+  case class BenchCastExpression(name: DataType) {
+    override def toString: String = s"${name.sql}"
+  }
+
+  def castExprSQL(castExpr: BenchCastExpression, input: String): String = {
+    s"CAST ($input AS $castExpr)"
+  }
+
+  private val castExpressionList = 
CometCast.supportedTypes.map(BenchCastExpression(_))
+
+  override def runCometBenchmark(args: Array[String]): Unit = {
+
+    //  TODO : Create all possible input datatypes. We only have Long inputs 
for now
+    castExpressionList.foreach { castExpr =>
+      Seq(true, false).foreach { k =>
+        CometCast.isSupported(
+          LongType,
+          castExpr.name,
+          None,
+          if (k) CometEvalMode.ANSI else CometEvalMode.LEGACY) match {
+          case Compatible(notes) =>
+            runBenchmarkWithTable(s"Running benchmark $castExpr)", 1024 * 1024 
* 10) { v =>
+              castBenchmark(v, castExpr, isAnsiMode = k)
+            }
+          case Incompatible(notes) => None
+          case Unsupported(notes) => None
+        }
+      }
+    }
+  }
+
+  def castBenchmark(values: Int, castExpr: BenchCastExpression, isAnsiMode: 
Boolean): Unit = {
+
+    val benchmark =
+      new Benchmark(
+        s"Cast function to : ${castExpr} , ansi mode enabled : ${isAnsiMode}",
+        values,
+        output = output)
+
+    val functionSQL = castExprSQL(castExpr, "value")
+    val query = s"SELECT $functionSQL FROM $tbl"
+
+    benchmark.addCase(
+      s"SQL Parquet - Spark Cast expr to : ${castExpr} , ansi mode enabled : 
${isAnsiMode}") {
+      _ =>
+        withSQLConf(SQLConf.ANSI_ENABLED.key -> isAnsiMode.toString) {
+          Try { spark.sql(query).noop() }
+        }
+    }
+
+    benchmark.addCase(
+      s"SQL Parquet - Comet Cast expr to : ${castExpr} , ansi mode enabled : 
${isAnsiMode}") {
+      _ =>
+        withSQLConf(
+          CometConf.COMET_ENABLED.key -> "true",
+          CometConf.COMET_EXEC_ENABLED.key -> "true",
+          SQLConf.ANSI_ENABLED.key -> isAnsiMode.toString) {
+          Try { spark.sql(query).noop() }

Review Comment:
   This query isn't running in Comet:
   
   ```
   *(1) Project [cast(value#5L as boolean) AS value#62]
   +- *(1) SerializeFromObject [input[0, bigint, false] AS value#5L]
      +- *(1) MapElements 
org.apache.spark.sql.benchmark.CometBenchmarkBase$$Lambda$1543/0x0000734b34c5d7e0@588b45cc,
 obj#4: bigint
         +- *(1) DeserializeToObject staticinvoke(class java.lang.Long, 
ObjectType(class java.lang.Long), valueOf, id#0L, true, false, true), obj#3: 
java.lang.Long
            +- *(1) Range (0, 10485760, step=1, splits=1)
   
   Project
   +- SerializeFromObject
      +- MapElements
         +- DeserializeToObject
            +-  Range [COMET: Range is not supported]
   ```
   
   I don't understand the setup here, but we really want a simple `select 
cast(col_name AS data_type) from tbl`. 
   



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