Commit 4b60dca
authored
test: make expression benchmark harness fair and reproducible (#5371)
* test: make expression benchmark harness fair and reproducible
`runExpressionBenchmark` backs 27 benchmark suites. Four defects made its
output untrustworthy.
Apply `spark.sql.optimizer.excludedRules` to both arms rather than the Comet
arm only, and append to the existing value instead of overwriting it. Excluding
`ConstantFolding` for Comet alone let Spark fold expressions over literal
arguments away entirely: for `select space(2) from parquetV1Table` the Spark
plan was `Project [ AS space(2)]`, doing no per-row work, so that row reported
a Comet regression that does not exist.
Warn when the Spark baseline plan does no work beyond scanning and projecting
bare attributes or literals, which means the optimizer removed the benchmarked
expression. Any other node counts as work, so the join and aggregate suites are
unaffected.
Route both that warning and the existing not-fully-native warning to `output`,
so they land in the results file above the affected table rather than scrolling
past on the console. Running the suites with this in place shows `translate` in
`CometStringExpressionBenchmark` and eight `c_short` cases in
`CometCastNumericToNumericBenchmark` falling back to a JVM `Project`, meaning
those rows labelled "Comet" were measuring Spark.
Generate the base table from a pure function of the row id instead of an
unseeded `scala.util.Random`, so runs are comparable. Seeding a driver-side
`Random` would not have worked: the closure runs per row on the executor.
Part of #5363.
* refactor: simplify benchmark harness plan checks and warning output
Write warnings through `Benchmark.out`, which already tees the console and
the results file, instead of hand-rolling the tee. This also keeps the warning
ordered against the results table, since both now go through the same stream.
Collapse `isTrivialPlan` to a single negated `exists` over the plan, dropping
the mid-method `return`, the second traversal and the one-use `unwrapAlias`.
Drop the untimed `noop()` from the Spark baseline check. Before execution
`stripAQEPlan` already yields the initial physical plan, which carries the
projections the check inspects; the nodes missing pre-execution are the
codegen and columnar-transition wrappers the check classifies as no-work
anyway. The Comet check keeps its execution, because AQE can re-plan a join
after the first stage completes.
Use `ConstantFolding.ruleName` rather than a hardcoded class name, and
`Utils.stringToSeq` rather than an open-coded comma-list parser.
* test: benchmark space over a column, and flag row-invariant projections
Excluding `ConstantFolding` on both arms made the `space(2)` plans symmetric
but not the work. Given a literal, Comet's native `space` receives a
`ColumnarValue::Scalar`, builds one string per batch and lets DataFusion
broadcast it, while Spark's `StringSpace` calls `UTF8String.blankString` once
per row. Benchmark `space(c2)` over a new non-negative integer column instead,
so both engines evaluate the expression on every row.
The plan check could not catch this, because the retained `ProjectExec` looks
like real work either way. Add a second check for projections that reference no
input column: their value is the same for every row, so an engine is free to
evaluate them once per batch, and engines differ on whether they do.
Nondeterministic expressions are excluded, since `rand()` also references no
column but genuinely evaluates per row.
Verified that the old query trips the new warning, that the new one does not,
and that `floor(rand() * 100)` does not.
* fix: drop unused string interpolator flagged by scalafix1 parent a74839c commit 4b60dca
2 files changed
Lines changed: 145 additions & 32 deletions
File tree
- spark/src/test/scala/org/apache/spark/sql/benchmark
Lines changed: 134 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
| 32 | + | |
| 33 | + | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
100 | 105 | | |
101 | 106 | | |
102 | | - | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
125 | 131 | | |
126 | 132 | | |
127 | 133 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
135 | 144 | | |
136 | | - | |
137 | | - | |
138 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
139 | 171 | | |
140 | | - | |
141 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
142 | 176 | | |
143 | 177 | | |
144 | 178 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
160 | 192 | | |
161 | 193 | | |
162 | 194 | | |
163 | 195 | | |
164 | | - | |
| 196 | + | |
165 | 197 | | |
166 | 198 | | |
167 | 199 | | |
168 | 200 | | |
169 | 201 | | |
170 | 202 | | |
171 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
172 | 260 | | |
173 | 261 | | |
174 | 262 | | |
| |||
291 | 379 | | |
292 | 380 | | |
293 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
0 commit comments