mbutrovich commented on code in PR #3296: URL: https://github.com/apache/datafusion-comet/pull/3296#discussion_r2732581880
########## spark/src/test/scala/org/apache/spark/sql/benchmark/CometOperatorSerdeBenchmark.scala: ########## @@ -0,0 +1,311 @@ +/* + * 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.nio.file.Files + +import org.apache.spark.benchmark.Benchmark +import org.apache.spark.sql.comet.{CometBatchScanExec, CometIcebergNativeScanExec} +import org.apache.spark.sql.execution.SparkPlan +import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanExec + +import org.apache.comet.CometConf +import org.apache.comet.serde.OperatorOuterClass +import org.apache.comet.serde.operator.CometIcebergNativeScan + +/** + * Benchmark for operator serialization/deserialization roundtrip performance. + * + * This benchmark measures the time to serialize Iceberg FileScanTask objects to protobuf, + * starting from actual Iceberg Java objects rather than pre-constructed protobuf messages. + * + * To run this benchmark: + * {{{ + * SPARK_GENERATE_BENCHMARK_FILES=1 make \ + * benchmark-org.apache.spark.sql.benchmark.CometOperatorSerdeBenchmark + * }}} + * + * Results will be written to "spark/benchmarks/CometOperatorSerdeBenchmark-**results.txt". + */ +object CometOperatorSerdeBenchmark extends CometBenchmarkBase { + + // Check if Iceberg is available in classpath + private def icebergAvailable: Boolean = { + try { + Class.forName("org.apache.iceberg.catalog.Catalog") + true + } catch { + case _: ClassNotFoundException => false + } + } + + // Helper to create temp directory for Iceberg warehouse + private def withTempIcebergDir(f: File => Unit): Unit = { + val dir = Files.createTempDirectory("comet-serde-benchmark").toFile + try { + f(dir) + } finally { + def deleteRecursively(file: File): Unit = { + if (file.isDirectory) { + Option(file.listFiles()).foreach(_.foreach(deleteRecursively)) + } + file.delete() + } + deleteRecursively(dir) + } + } + + /** + * Extracts CometIcebergNativeScanExec from a query plan, unwrapping AQE if present. + */ + private def extractIcebergNativeScanExec( + plan: SparkPlan): Option[CometIcebergNativeScanExec] = { + val unwrapped = plan match { + case aqe: AdaptiveSparkPlanExec => aqe.executedPlan + case other => other + } + + def find(p: SparkPlan): Option[CometIcebergNativeScanExec] = { + p match { + case scan: CometIcebergNativeScanExec => Some(scan) + case _ => p.children.flatMap(find).headOption + } + } + find(unwrapped) + } + + /** + * Reconstructs a CometBatchScanExec from CometIcebergNativeScanExec for benchmarking the + * conversion process. + */ + private def reconstructBatchScanExec( + nativeScan: CometIcebergNativeScanExec): CometBatchScanExec = { + CometBatchScanExec( + wrapped = nativeScan.originalPlan, + runtimeFilters = Seq.empty, + nativeIcebergScanMetadata = Some(nativeScan.nativeIcebergScanMetadata)) + } + + /** + * Creates an Iceberg table with the specified number of partitions. Each partition contains one Review Comment: Is this true? Often when I write in batches to Iceberg tables I get different files for iterations of inserts, and then need to do a compaction after. -- 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]
