Commit 2816c89
[SPARK-10988] [SQL] Reduce duplication in Aggregate2's expression rewriting logic
In `aggregate/utils.scala`, there is a substantial amount of duplication in the expression-rewriting logic. As a prerequisite to supporting imperative aggregate functions in `TungstenAggregate`, this patch refactors this file so that the same expression-rewriting logic is used for both `SortAggregate` and `TungstenAggregate`.
In order to allow both operators to use the same rewriting logic, `TungstenAggregationIterator. generateResultProjection()` has been updated so that it first evaluates all declarative aggregate functions' `evaluateExpression`s and writes the results into a temporary buffer, and then uses this temporary buffer and the grouping expressions to evaluate the final resultExpressions. This matches the logic in SortAggregateIterator, where this two-pass approach is necessary in order to support imperative aggregates. If this change turns out to cause performance regressions, then we can look into re-implementing the single-pass evaluation in a cleaner way as part of a followup patch.
Since the rewriting logic is now shared across both operators, this patch also extracts that logic and places it in `SparkStrategies`. This makes the rewriting logic a bit easier to follow, I think.
Author: Josh Rosen <[email protected]>
Closes #9015 from JoshRosen/SPARK-10988.1 parent 9e66a53 commit 2816c89
File tree
5 files changed
+143
-196
lines changed- sql/core/src
- main/scala/org/apache/spark/sql/execution
- aggregate
- test/scala/org/apache/spark/sql/execution/aggregate
5 files changed
+143
-196
lines changedLines changed: 52 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
203 | | - | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | | - | |
| 210 | + | |
207 | 211 | | |
208 | | - | |
209 | | - | |
210 | | - | |
| 212 | + | |
| 213 | + | |
211 | 214 | | |
212 | 215 | | |
213 | 216 | | |
| |||
220 | 223 | | |
221 | 224 | | |
222 | 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 | + | |
223 | 260 | | |
224 | 261 | | |
225 | 262 | | |
226 | 263 | | |
227 | 264 | | |
228 | 265 | | |
229 | 266 | | |
230 | | - | |
| 267 | + | |
231 | 268 | | |
232 | | - | |
233 | | - | |
| 269 | + | |
| 270 | + | |
234 | 271 | | |
235 | 272 | | |
236 | 273 | | |
237 | 274 | | |
238 | | - | |
| 275 | + | |
239 | 276 | | |
240 | | - | |
241 | | - | |
| 277 | + | |
| 278 | + | |
242 | 279 | | |
243 | 280 | | |
244 | 281 | | |
245 | | - | |
| 282 | + | |
246 | 283 | | |
247 | 284 | | |
248 | | - | |
249 | | - | |
| 285 | + | |
| 286 | + | |
250 | 287 | | |
251 | 288 | | |
252 | 289 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| 82 | + | |
80 | 83 | | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TungstenAggregationIterator.scala
Lines changed: 18 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| 79 | + | |
75 | 80 | | |
| 81 | + | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| |||
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
283 | 296 | | |
284 | | - | |
| 297 | + | |
285 | 298 | | |
286 | 299 | | |
287 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
288 | 303 | | |
289 | 304 | | |
290 | 305 | | |
291 | 306 | | |
292 | | - | |
293 | | - | |
| 307 | + | |
294 | 308 | | |
295 | 309 | | |
296 | 310 | | |
| |||
0 commit comments