rich7420 commented on code in PR #7405: URL: https://github.com/apache/datafusion-comet/pull/7405#discussion_r4484124791
########## spark/src/test/scala/org/apache/spark/sql/benchmark/CometPlanOutputBenchmark.scala: ########## @@ -0,0 +1,213 @@ +/* + * 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 java.io.File +import java.lang.management.ManagementFactory + +import scala.collection.mutable + +import org.apache.spark.benchmark.Benchmark +import org.apache.spark.sql.DataFrame +import org.apache.spark.sql.comet.CometNativeExec +import org.apache.spark.sql.execution.{QueryExecution, SQLExecution} +import org.apache.spark.sql.internal.SQLConf + +import org.apache.comet.CometConf +import org.apache.comet.vector.NativeUtil + +/** + * Benchmark to measure what it costs to move the output batches of a native plan to the JVM, with + * the Arrow schema of the output sent with every batch or only when it changes + * (`spark.comet.exec.cacheOutputSchema.enabled`). + * + * Most cases read one column of a Parquet table and project it `n` times, so the native plan does + * almost nothing for each of its `n` output columns beyond exporting it. The last case reads `n` + * distinct columns, so the work of the scan grows with `n` as well. The JVM only counts the rows + * of the batches it receives, as a JVM operator that passes batches through would, so these + * results bound the effect on a query from above. + * + * To run this benchmark: + * {{{ + * SPARK_GENERATE_BENCHMARK_FILES=1 make \ + * benchmark-org.apache.spark.sql.benchmark.CometPlanOutputBenchmark + * }}} + * Results will be written to "spark/benchmarks/CometPlanOutputBenchmark-**results.txt". + */ +object CometPlanOutputBenchmark extends CometBenchmarkBase { + + private val narrowRows = 8 * 1024 * 1024 + private val wideRows = 1024 * 1024 + private val wideColumns = 100 + + override def runCometBenchmark(mainArgs: Array[String]): Unit = { + // Keep the plan a scan and a projection under the transition to rows. + spark.conf.set(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key, "false") + withTempPath { dir => + withTempTable("narrow", "wide") { + writeTable( + dir, + "narrow", + spark.sql( + "SELECT id AS i, CAST(id AS STRING) AS s, " + + s"named_struct('a', id, 'b', CAST(id AS STRING)) AS st FROM range($narrowRows)")) + writeTable( + dir, + "wide", + spark.sql( + (0 until wideColumns) + .map(c => s"id + $c AS w$c") + .mkString("SELECT ", ", ", s" FROM range($wideRows)"))) + + for { + (column, typeName) <- Seq( + "i" -> "bigint", + "s" -> "string", + "st" -> "struct<bigint,string>") + n <- Seq(1, 10, 100) + } { + val query = + (0 until n).map(c => s"$column AS c$c").mkString("SELECT ", ", ", " FROM narrow") + runCases(s"$n $typeName output columns, 1 column read", narrowRows, query) Review Comment: The Spark 3.5 strict-warnings build fails here and at lines 92/211 on numeric widening. Please convert these counts to `Long` explicitly. -- 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]
