-
Notifications
You must be signed in to change notification settings - Fork 268
chore: Improve support - benchmarking suite #3014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coderfender
wants to merge
7
commits into
apache:main
Choose a base branch
from
coderfender:improve_benchmarking_suite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5d8eea
ansi_suport_benchmarking
coderfender 0aed807
ansi_suport_benchmarking
coderfender a8b065b
ansi_suport_benchmarking
coderfender 8cf710c
ansi_suport_benchmarking
coderfender 593b788
ansi_suport_benchmarking_fmt
coderfender b5e61b1
improve_benchmark
coderfender 1027c85
improve_benchmark
coderfender File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ import org.apache.spark.benchmark.Benchmark | |
| import org.apache.spark.sql.{DataFrame, DataFrameWriter, Row, SparkSession} | ||
| import org.apache.spark.sql.execution.benchmark.SqlBasedBenchmark | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.DecimalType | ||
| import org.apache.spark.sql.types.{DataType, DecimalType} | ||
|
|
||
| import org.apache.comet.CometConf | ||
| import org.apache.comet.CometSparkSessionExtensions | ||
|
|
@@ -88,26 +88,52 @@ trait CometBenchmarkBase extends SqlBasedBenchmark { | |
| } | ||
| } | ||
|
|
||
| /** Runs function `f` with Comet on and off. */ | ||
| final def runWithComet(name: String, cardinality: Long)(f: => Unit): Unit = { | ||
| val benchmark = new Benchmark(name, cardinality, output = output) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer being used and needed as well IMO |
||
| benchmark.addCase(s"$name - Spark ") { _ => | ||
| withSQLConf(CometConf.COMET_ENABLED.key -> "false") { | ||
| f | ||
| } | ||
| /** | ||
| * Creates a table with ANSI-safe values that won't overflow in arithmetic operations. Use this | ||
| * instead of runBenchmarkWithTable for arithmetic/aggregate benchmarks. | ||
| */ | ||
| protected def runBenchmarkWithSafeTable( | ||
| benchmarkName: String, | ||
| values: Int, | ||
| useDictionary: Boolean = false)(f: Int => Any): Unit = { | ||
| withTempTable(tbl) { | ||
| import spark.implicits._ | ||
| spark | ||
| .range(values) | ||
| .map(i => if (useDictionary) i % 5 else i % 10000) | ||
| .createOrReplaceTempView(tbl) | ||
| runBenchmark(benchmarkName)(f(values)) | ||
| } | ||
| } | ||
|
|
||
| benchmark.addCase(s"$name - Comet") { _ => | ||
| withSQLConf( | ||
| CometConf.COMET_ENABLED.key -> "true", | ||
| CometConf.COMET_EXEC_ENABLED.key -> "true", | ||
| SQLConf.ANSI_ENABLED.key -> "false") { | ||
| f | ||
| } | ||
| /** | ||
| * Generates ANSI-safe data for casting from Long to the specified target type. Returns a SQL | ||
| * expression that transforms the base "value" column to be within safe ranges. | ||
| * | ||
| * @param targetType | ||
| * The target data type for casting | ||
| * @return | ||
| * SQL expression to generate safe data | ||
| */ | ||
| protected def generateAnsiSafeData(targetType: DataType): String = { | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| // we generate long inputs initially and this case statement translates them into right data type so that the code doesn't fail in ANSI mode | ||
| targetType match { | ||
| case ByteType => "CAST((value % 128) AS BIGINT)" | ||
| case ShortType => "CAST((value % 32768) AS BIGINT)" | ||
| case IntegerType => "CAST((value % 2147483648) AS BIGINT)" | ||
| case LongType => "value" | ||
| case FloatType => "CAST((value % 1000000) AS BIGINT)" | ||
| case DoubleType => "value" | ||
| case _: DecimalType => "CAST((value % 100000000) AS BIGINT)" | ||
| case StringType => "CAST(value AS STRING)" | ||
| case BooleanType => "CAST((value % 2) AS BIGINT)" | ||
| case DateType => "CAST((value % 18262) AS BIGINT)" | ||
| case TimestampType => "value" | ||
| case BinaryType => "value" | ||
| case _ => "value" | ||
| } | ||
|
|
||
| benchmark.run() | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -127,37 +153,48 @@ trait CometBenchmarkBase extends SqlBasedBenchmark { | |
| name: String, | ||
| cardinality: Long, | ||
| query: String, | ||
| isAnsiMode: Boolean, | ||
| extraCometConfigs: Map[String, String] = Map.empty): Unit = { | ||
|
|
||
| val benchmark = new Benchmark(name, cardinality, output = output) | ||
|
|
||
| benchmark.addCase("Spark") { _ => | ||
| withSQLConf(CometConf.COMET_ENABLED.key -> "false") { | ||
| spark.sql(query).noop() | ||
| withSQLConf( | ||
| CometConf.COMET_ENABLED.key -> "false", | ||
| SQLConf.ANSI_ENABLED.key -> isAnsiMode.toString) { | ||
| runSparkCommand(spark, query, isAnsiMode) | ||
| } | ||
| } | ||
|
|
||
| benchmark.addCase("Comet (Scan)") { _ => | ||
| withSQLConf( | ||
| CometConf.COMET_ENABLED.key -> "true", | ||
| CometConf.COMET_EXEC_ENABLED.key -> "false") { | ||
| spark.sql(query).noop() | ||
| CometConf.COMET_EXEC_ENABLED.key -> "false", | ||
| SQLConf.ANSI_ENABLED.key -> isAnsiMode.toString) { | ||
| runSparkCommand(spark, query, isAnsiMode) | ||
| } | ||
| } | ||
|
|
||
| val cometExecConfigs = Map( | ||
| CometConf.COMET_ENABLED.key -> "true", | ||
| CometConf.COMET_EXEC_ENABLED.key -> "true", | ||
| "spark.sql.optimizer.constantFolding.enabled" -> "false") ++ extraCometConfigs | ||
| "spark.sql.optimizer.constantFolding.enabled" -> "false", | ||
| SQLConf.ANSI_ENABLED.key -> isAnsiMode.toString) ++ extraCometConfigs | ||
|
|
||
| benchmark.addCase("Comet (Scan + Exec)") { _ => | ||
| withSQLConf(cometExecConfigs.toSeq: _*) { | ||
| spark.sql(query).noop() | ||
| runSparkCommand(spark, query, isAnsiMode) | ||
| } | ||
| } | ||
|
|
||
| benchmark.run() | ||
| } | ||
|
|
||
| private def runSparkCommand(spark: SparkSession, query: String, isANSIMode: Boolean): Unit = { | ||
| // With ANSI-safe data generation, queries should not throw exceptions | ||
| spark.sql(query).noop() | ||
| } | ||
|
|
||
| protected def prepareTable(dir: File, df: DataFrame, partition: Option[String] = None): Unit = { | ||
| val testDf = if (partition.isDefined) { | ||
| df.write.partitionBy(partition.get) | ||
|
|
@@ -250,7 +287,9 @@ trait CometBenchmarkBase extends SqlBasedBenchmark { | |
| useDictionary: Boolean): DataFrame = { | ||
| import spark.implicits._ | ||
|
|
||
| val div = if (useDictionary) 5 else values | ||
| // Use safe range to avoid overflow in decimal operations | ||
| val maxValue = 10000 | ||
| val div = if (useDictionary) 5 else maxValue | ||
| spark | ||
| .range(values) | ||
| .map(_ % div) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added convenient way to run all benchmark through make file