Skip to content

Commit 8fedd4f

Browse files
committed
Add microbenchmark for comparison expressions
1 parent 6ec70ae commit 8fedd4f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.spark.sql.benchmark
21+
22+
case class ComparisonExprConfig(
23+
name: String,
24+
query: String,
25+
extraCometConfigs: Map[String, String] = Map.empty)
26+
27+
/**
28+
* Comprehensive benchmark for Comet comparison and predicate expressions. To run this benchmark:
29+
* {{{
30+
* SPARK_GENERATE_BENCHMARK_FILES=1 make benchmark-org.apache.spark.sql.benchmark.CometComparisonExpressionBenchmark
31+
* }}}
32+
* Results will be written to "spark/benchmarks/CometComparisonExpressionBenchmark-**results.txt".
33+
*/
34+
object CometComparisonExpressionBenchmark extends CometBenchmarkBase {
35+
36+
private val comparisonExpressions = List(
37+
ComparisonExprConfig("equal_to", "SELECT c_int = c_int2 FROM parquetV1Table"),
38+
ComparisonExprConfig("not_equal_to", "SELECT c_int != c_int2 FROM parquetV1Table"),
39+
ComparisonExprConfig("less_than", "SELECT c_int < c_int2 FROM parquetV1Table"),
40+
ComparisonExprConfig("less_than_or_equal", "SELECT c_int <= c_int2 FROM parquetV1Table"),
41+
ComparisonExprConfig("greater_than", "SELECT c_int > c_int2 FROM parquetV1Table"),
42+
ComparisonExprConfig("greater_than_or_equal", "SELECT c_int >= c_int2 FROM parquetV1Table"),
43+
ComparisonExprConfig("equal_null_safe", "SELECT c_int <=> c_int2 FROM parquetV1Table"),
44+
ComparisonExprConfig("is_null", "SELECT c_int IS NULL FROM parquetV1Table"),
45+
ComparisonExprConfig("is_not_null", "SELECT c_int IS NOT NULL FROM parquetV1Table"),
46+
ComparisonExprConfig("is_nan_float", "SELECT isnan(c_float) FROM parquetV1Table"),
47+
ComparisonExprConfig("is_nan_double", "SELECT isnan(c_double) FROM parquetV1Table"),
48+
ComparisonExprConfig("and", "SELECT (c_int > 0) AND (c_int2 < 100) FROM parquetV1Table"),
49+
ComparisonExprConfig("or", "SELECT (c_int > 0) OR (c_int2 < 100) FROM parquetV1Table"),
50+
ComparisonExprConfig("not", "SELECT NOT (c_int > 0) FROM parquetV1Table"),
51+
ComparisonExprConfig(
52+
"in_list",
53+
"SELECT c_int IN (1, 10, 100, 1000, 10000) FROM parquetV1Table"),
54+
ComparisonExprConfig(
55+
"not_in_list",
56+
"SELECT c_int NOT IN (1, 10, 100, 1000, 10000) FROM parquetV1Table"))
57+
58+
override def runCometBenchmark(mainArgs: Array[String]): Unit = {
59+
val values = 1024 * 1024
60+
61+
runBenchmarkWithTable("Comparison expression benchmarks", values) { v =>
62+
withTempPath { dir =>
63+
withTempTable("parquetV1Table") {
64+
prepareTable(
65+
dir,
66+
spark.sql(s"""
67+
SELECT
68+
CASE WHEN value % 10 = 0 THEN NULL ELSE CAST((value % 100000) - 50000 AS INT) END AS c_int,
69+
CASE WHEN value % 10 = 1 THEN NULL ELSE CAST((value % 1000) AS INT) END AS c_int2,
70+
CASE
71+
WHEN value % 50 = 2 THEN NULL
72+
WHEN value % 50 = 3 THEN CAST('NaN' AS FLOAT)
73+
ELSE CAST((value % 10000) / 100.0 AS FLOAT)
74+
END AS c_float,
75+
CASE
76+
WHEN value % 50 = 4 THEN NULL
77+
WHEN value % 50 = 5 THEN CAST('NaN' AS DOUBLE)
78+
ELSE CAST((value % 10000) / 100.0 AS DOUBLE)
79+
END AS c_double
80+
FROM $tbl
81+
"""))
82+
83+
comparisonExpressions.foreach { config =>
84+
runExpressionBenchmark(config.name, v, config.query, config.extraCometConfigs)
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)