comphead commented on code in PR #7683: URL: https://github.com/apache/datafusion-comet/pull/7683#discussion_r4637038537
########## spark/src/test/scala/org/apache/spark/sql/benchmark/CometMinMaxBenchmark.scala: ########## @@ -0,0 +1,221 @@ +/* + * 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.concurrent.duration._ +import scala.jdk.CollectionConverters._ + +import org.apache.hadoop.fs.Path +import org.apache.parquet.hadoop.ParquetFileReader +import org.apache.parquet.hadoop.util.HadoopInputFile +import org.apache.spark.benchmark.Benchmark +import org.apache.spark.sql.Row +import org.apache.spark.sql.catalyst.expressions.aggregate.Partial +import org.apache.spark.sql.comet.{CometBaseAggregateExec, CometNativeScanExec} +import org.apache.spark.sql.internal.SQLConf + +import org.apache.comet.CometConf + +/** + * Compare MIN/MAX with reader filtering disabled and enabled. Use a native release build: + * + * {{{ + * make benchmark-org.apache.spark.sql.benchmark.CometMinMaxBenchmark -- \ + * 1048576 1,4 ascending,descending,random,constant 5 off,on + * }}} + * + * Arguments are rows, scan partitions, layouts, minimum measured iterations, and mode order. + * Defaults match the example. Repeat with on,off to reverse the case order. A smoke run can use + * 16384 rows and three iterations. Timings include planning and collection; fixture creation, + * Spark result comparisons, plan checks, and metric collection run outside timings. Metrics come + * from an untimed execution. Page indexes and decoder row filters are disabled to isolate + * row-group pruning. Each file has multiple row groups and runs in a separate scan task. + */ +object CometMinMaxBenchmark extends CometBenchmarkBase { + + private val modes = Map("off" -> false, "on" -> true) + private val filterConfig = CometConf.COMET_EXEC_AGGREGATE_DYNAMIC_FILTER_ENABLED.key + + private val nativeConfigs = Seq( + CometConf.COMET_ENABLED.key -> "true", + CometConf.COMET_EXEC_ENABLED.key -> "true", + CometConf.COMET_NATIVE_SCAN_ENABLED.key -> "true", + CometConf.COMET_BATCH_SIZE.key -> "4096", + CometConf.COMET_PARQUET_ROW_FILTER_PUSHDOWN_ENABLED.key -> "false", + CometConf.COMET_RESPECT_DATAFUSION_CONFIGS.key -> "true", + "spark.comet.datafusion.execution.parquet.enable_page_index" -> "false", + SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false", + SQLConf.LEAF_NODE_DEFAULT_PARALLELISM.key -> "1", + SQLConf.FILES_OPEN_COST_IN_BYTES.key -> "4194304") + + private def writeInput( + directory: String, + rows: Int, + partitions: Int, + layout: String): (Long, Seq[Int]) = { + val key = layout match { + case "ascending" => s"id - ${rows / 2}" + case "descending" => s"${rows / 2} - id - 1" + case "random" => s"pmod(xxhash64(id), $rows) - ${rows / 2}" + case "constant" => "0" + } + withSQLConf(CometConf.COMET_ENABLED.key -> "false") { + spark + .range(0, rows.toLong, 1, partitions) + .selectExpr(s"CAST($key AS INT) AS k") + .write + // Fixed-width, uncompressed pages keep constant values from collapsing into one group. + .option("compression", "uncompressed") + .option("parquet.writer.version", "v1") + .option("parquet.enable.dictionary", "false") + // Target eight row groups per file, including for constant data. + .option("parquet.block.size", (rows.toLong / partitions * 4 / 8).toString) + .parquet(directory) + } + val path = new Path(directory) + val files = path + .getFileSystem(spark.sessionState.newHadoopConf()) + .listStatus(path) + .filter(_.getPath.getName.endsWith(".parquet")) + require(files.length == partitions, s"Expected $partitions files, found ${files.length}") + val rowGroups = files.toSeq.map { file => + val reader = ParquetFileReader.open( + HadoopInputFile.fromPath(file.getPath, spark.sessionState.newHadoopConf())) + try reader.getFooter.getBlocks.asScala.size + finally reader.close() + } + require(rowGroups.forall(_ > 1), s"Expected multiple row groups per file: $rowGroups") + (files.map(_.getLen).max, rowGroups) Review Comment: This file listing and row-group counting block is identical to the one in `CometTopKBenchmark.writeInput`. The `nativeConfigs` list (lines 56-66) and the `readerWork` metric list (lines 136-144) are also identical to the TopK benchmark. Could these move into `CometBenchmarkBase` as protected helpers (for example one that returns the max file length and per-file row-group counts for a directory, plus shared scan configs and a reader-metrics formatter) and be used by both benchmarks? Then a future change to the fixture checks or the disabled page-index and decoder-filter settings applies to both. -- 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]
