Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update the UnitTest for aggregation constant folding
  • Loading branch information
chenghao-intel committed Apr 30, 2014
commit 80f9f1871640c718c6c4b3f627aec99b52b1f96d
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ object NullPropagation extends Rule[LogicalPlan] {
// Skip redundant folding of literals.
case l: Literal => l
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to skip literals since none of the conditions below can ever match a raw literal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if put the literal matching in the beginning, maybe helpful avoid the further pattern matching of the rest rules. Just a tiny performance optimization for Literal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By that logic it would be an optimization to skip any class that won't match the cases below. Why is Literal a special case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as the rule ConstantFolding, NullPropagation won't do any transformation for Literal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but in the case of ConstantFolding the subsequent pattern will match Literal, since a Literal is technically foldable. Matching the next pattern causes the rule to invoke the expression evaluator and create an identical, wasted object.

In NullPropogation, a Literal will not match any of the later rules. So in essence you are second guessing the code generated by the pattern matcher. While there may be extreme cases where that is required for performance, I don't think this is one of them.

case e @ Count(Literal(null, _)) => Literal(0, e.dataType)
case e @ Sum(Literal(null, _)) => Literal(null, e.dataType)
case e @ Average(Literal(null, _)) => Literal(null, e.dataType)
case e @ Sum(Literal(c, _)) if(c == 0) => Literal(0, e.dataType)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not like the previous implementation, I didn't add the null value as Child expression for both Sum and Average in the rule, cause Hive will throw semantic exception.

case e @ Average(Literal(c, _)) if(c == 0) => Literal(0.0, e.dataType)
case e @ IsNull(c) if c.nullable == false => Literal(false, BooleanType)
case e @ IsNotNull(c) if c.nullable == false => Literal(true, BooleanType)
case e @ GetItem(Literal(null, _), _) => Literal(null, e.dataType)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
0.0 0 0 0 3
2.0 0 2 0 1
4.0 0 4 0 1
5.0 0 15 0 3
8.0 0 8 0 1
9.0 0 9 0 1
10.0 0 10 0 1
11.0 0 11 0 1
12.0 0 24 0 2
15.0 0 30 0 2
17.0 0 17 0 1
18.0 0 36 0 2
19.0 0 19 0 1
20.0 0 20 0 1
24.0 0 48 0 2
26.0 0 52 0 2
27.0 0 27 0 1
28.0 0 28 0 1
30.0 0 30 0 1
33.0 0 33 0 1
34.0 0 34 0 1
35.0 0 105 0 3
37.0 0 74 0 2
41.0 0 41 0 1
42.0 0 84 0 2
43.0 0 43 0 1
44.0 0 44 0 1
47.0 0 47 0 1
51.0 0 102 0 2
53.0 0 53 0 1
54.0 0 54 0 1
57.0 0 57 0 1
58.0 0 116 0 2
64.0 0 64 0 1
65.0 0 65 0 1
66.0 0 66 0 1
67.0 0 134 0 2
69.0 0 69 0 1
70.0 0 210 0 3
72.0 0 144 0 2
74.0 0 74 0 1
76.0 0 152 0 2
77.0 0 77 0 1
78.0 0 78 0 1
80.0 0 80 0 1
82.0 0 82 0 1
83.0 0 166 0 2
84.0 0 168 0 2
85.0 0 85 0 1
86.0 0 86 0 1
87.0 0 87 0 1
90.0 0 270 0 3
92.0 0 92 0 1
95.0 0 190 0 2
96.0 0 96 0 1
97.0 0 194 0 2
98.0 0 196 0 2
100.0 0 200 0 2
103.0 0 206 0 2
104.0 0 208 0 2
105.0 0 105 0 1
111.0 0 111 0 1
113.0 0 226 0 2
114.0 0 114 0 1
116.0 0 116 0 1
118.0 0 236 0 2
119.0 0 357 0 3
120.0 0 240 0 2
125.0 0 250 0 2
126.0 0 126 0 1
128.0 0 384 0 3
129.0 0 258 0 2
131.0 0 131 0 1
133.0 0 133 0 1
134.0 0 268 0 2
136.0 0 136 0 1
137.0 0 274 0 2
138.0 0 552 0 4
143.0 0 143 0 1
145.0 0 145 0 1
146.0 0 292 0 2
149.0 0 298 0 2
150.0 0 150 0 1
152.0 0 304 0 2
153.0 0 153 0 1
155.0 0 155 0 1
156.0 0 156 0 1
157.0 0 157 0 1
158.0 0 158 0 1
160.0 0 160 0 1
162.0 0 162 0 1
163.0 0 163 0 1
164.0 0 328 0 2
165.0 0 330 0 2
166.0 0 166 0 1
167.0 0 501 0 3
168.0 0 168 0 1
169.0 0 676 0 4
170.0 0 170 0 1
172.0 0 344 0 2
174.0 0 348 0 2
175.0 0 350 0 2
176.0 0 352 0 2
177.0 0 177 0 1
178.0 0 178 0 1
179.0 0 358 0 2
180.0 0 180 0 1
181.0 0 181 0 1
183.0 0 183 0 1
186.0 0 186 0 1
187.0 0 561 0 3
189.0 0 189 0 1
190.0 0 190 0 1
191.0 0 382 0 2
192.0 0 192 0 1
193.0 0 579 0 3
194.0 0 194 0 1
195.0 0 390 0 2
196.0 0 196 0 1
197.0 0 394 0 2
199.0 0 597 0 3
200.0 0 400 0 2
201.0 0 201 0 1
202.0 0 202 0 1
203.0 0 406 0 2
205.0 0 410 0 2
207.0 0 414 0 2
208.0 0 624 0 3
209.0 0 418 0 2
213.0 0 426 0 2
214.0 0 214 0 1
216.0 0 432 0 2
217.0 0 434 0 2
218.0 0 218 0 1
219.0 0 438 0 2
221.0 0 442 0 2
222.0 0 222 0 1
223.0 0 446 0 2
224.0 0 448 0 2
226.0 0 226 0 1
228.0 0 228 0 1
229.0 0 458 0 2
230.0 0 1150 0 5
233.0 0 466 0 2
235.0 0 235 0 1
237.0 0 474 0 2
238.0 0 476 0 2
239.0 0 478 0 2
241.0 0 241 0 1
242.0 0 484 0 2
244.0 0 244 0 1
247.0 0 247 0 1
248.0 0 248 0 1
249.0 0 249 0 1
252.0 0 252 0 1
255.0 0 510 0 2
256.0 0 512 0 2
257.0 0 257 0 1
258.0 0 258 0 1
260.0 0 260 0 1
262.0 0 262 0 1
263.0 0 263 0 1
265.0 0 530 0 2
266.0 0 266 0 1
272.0 0 544 0 2
273.0 0 819 0 3
274.0 0 274 0 1
275.0 0 275 0 1
277.0 0 1108 0 4
278.0 0 556 0 2
280.0 0 560 0 2
281.0 0 562 0 2
282.0 0 564 0 2
283.0 0 283 0 1
284.0 0 284 0 1
285.0 0 285 0 1
286.0 0 286 0 1
287.0 0 287 0 1
288.0 0 576 0 2
289.0 0 289 0 1
291.0 0 291 0 1
292.0 0 292 0 1
296.0 0 296 0 1
298.0 0 894 0 3
302.0 0 302 0 1
305.0 0 305 0 1
306.0 0 306 0 1
307.0 0 614 0 2
308.0 0 308 0 1
309.0 0 618 0 2
310.0 0 310 0 1
311.0 0 933 0 3
315.0 0 315 0 1
316.0 0 948 0 3
317.0 0 634 0 2
318.0 0 954 0 3
321.0 0 642 0 2
322.0 0 644 0 2
323.0 0 323 0 1
325.0 0 650 0 2
327.0 0 981 0 3
331.0 0 662 0 2
332.0 0 332 0 1
333.0 0 666 0 2
335.0 0 335 0 1
336.0 0 336 0 1
338.0 0 338 0 1
339.0 0 339 0 1
341.0 0 341 0 1
342.0 0 684 0 2
344.0 0 688 0 2
345.0 0 345 0 1
348.0 0 1740 0 5
351.0 0 351 0 1
353.0 0 706 0 2
356.0 0 356 0 1
360.0 0 360 0 1
362.0 0 362 0 1
364.0 0 364 0 1
365.0 0 365 0 1
366.0 0 366 0 1
367.0 0 734 0 2
368.0 0 368 0 1
369.0 0 1107 0 3
373.0 0 373 0 1
374.0 0 374 0 1
375.0 0 375 0 1
377.0 0 377 0 1
378.0 0 378 0 1
379.0 0 379 0 1
382.0 0 764 0 2
384.0 0 1152 0 3
386.0 0 386 0 1
389.0 0 389 0 1
392.0 0 392 0 1
393.0 0 393 0 1
394.0 0 394 0 1
395.0 0 790 0 2
396.0 0 1188 0 3
397.0 0 794 0 2
399.0 0 798 0 2
400.0 0 400 0 1
401.0 0 2005 0 5
402.0 0 402 0 1
403.0 0 1209 0 3
404.0 0 808 0 2
406.0 0 1624 0 4
407.0 0 407 0 1
409.0 0 1227 0 3
411.0 0 411 0 1
413.0 0 826 0 2
414.0 0 828 0 2
417.0 0 1251 0 3
418.0 0 418 0 1
419.0 0 419 0 1
421.0 0 421 0 1
424.0 0 848 0 2
427.0 0 427 0 1
429.0 0 858 0 2
430.0 0 1290 0 3
431.0 0 1293 0 3
432.0 0 432 0 1
435.0 0 435 0 1
436.0 0 436 0 1
437.0 0 437 0 1
438.0 0 1314 0 3
439.0 0 878 0 2
443.0 0 443 0 1
444.0 0 444 0 1
446.0 0 446 0 1
448.0 0 448 0 1
449.0 0 449 0 1
452.0 0 452 0 1
453.0 0 453 0 1
454.0 0 1362 0 3
455.0 0 455 0 1
457.0 0 457 0 1
458.0 0 916 0 2
459.0 0 918 0 2
460.0 0 460 0 1
462.0 0 924 0 2
463.0 0 926 0 2
466.0 0 1398 0 3
467.0 0 467 0 1
468.0 0 1872 0 4
469.0 0 2345 0 5
470.0 0 470 0 1
472.0 0 472 0 1
475.0 0 475 0 1
477.0 0 477 0 1
478.0 0 956 0 2
479.0 0 479 0 1
480.0 0 1440 0 3
481.0 0 481 0 1
482.0 0 482 0 1
483.0 0 483 0 1
484.0 0 484 0 1
485.0 0 485 0 1
487.0 0 487 0 1
489.0 0 1956 0 4
490.0 0 490 0 1
491.0 0 491 0 1
492.0 0 984 0 2
493.0 0 493 0 1
494.0 0 494 0 1
495.0 0 495 0 1
496.0 0 496 0 1
497.0 0 497 0 1
498.0 0 1494 0 3
Loading