Skip to content

Commit 39b8193

Browse files
committed
[SPARK-2716][SQL] Don't check resolved for having filters.
For queries like `... HAVING COUNT(*) > 9` the expression is always resolved since it contains no attributes. This was causing us to avoid doing the Having clause aggregation rewrite. Author: Michael Armbrust <[email protected]> Closes #1640 from marmbrus/havingNoRef and squashes the following commits: 92d3901 [Michael Armbrust] Don't check resolved for having filters.
1 parent 2c35666 commit 39b8193

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class Analyzer(catalog: Catalog, registry: FunctionRegistry, caseSensitive: Bool
159159
object UnresolvedHavingClauseAttributes extends Rule[LogicalPlan] {
160160
def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
161161
case filter @ Filter(havingCondition, aggregate @ Aggregate(_, originalAggExprs, _))
162-
if !filter.resolved && aggregate.resolved && containsAggregate(havingCondition) => {
162+
if aggregate.resolved && containsAggregate(havingCondition) => {
163163
val evaluatedCondition = Alias(havingCondition, "havingCondition")()
164164
val aggExprsWithHaving = evaluatedCondition +: originalAggExprs
165165

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
0
2+
5
3+
12
4+
15
5+
18
6+
24
7+
26
8+
35
9+
37
10+
42
11+
51
12+
58
13+
67
14+
70
15+
72
16+
76
17+
83
18+
84
19+
90
20+
95
21+
97
22+
98
23+
100
24+
103
25+
104
26+
113
27+
118
28+
119
29+
120
30+
125
31+
128
32+
129
33+
134
34+
137
35+
138
36+
146
37+
149
38+
152
39+
164
40+
165
41+
167
42+
169
43+
172
44+
174
45+
175
46+
176
47+
179
48+
187
49+
191
50+
193
51+
195
52+
197
53+
199
54+
200
55+
203
56+
205
57+
207
58+
208
59+
209
60+
213
61+
216
62+
217
63+
219
64+
221
65+
223
66+
224
67+
229
68+
230
69+
233
70+
237
71+
238
72+
239
73+
242
74+
255
75+
256
76+
265
77+
272
78+
273
79+
277
80+
278
81+
280
82+
281
83+
282
84+
288
85+
298
86+
307
87+
309
88+
311
89+
316
90+
317
91+
318
92+
321
93+
322
94+
325
95+
327
96+
331
97+
333
98+
342
99+
344
100+
348
101+
353
102+
367
103+
369
104+
382
105+
384
106+
395
107+
396
108+
397
109+
399
110+
401
111+
403
112+
404
113+
406
114+
409
115+
413
116+
414
117+
417
118+
424
119+
429
120+
430
121+
431
122+
438
123+
439
124+
454
125+
458
126+
459
127+
462
128+
463
129+
466
130+
468
131+
469
132+
478
133+
480
134+
489
135+
492
136+
498

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ case class TestData(a: Int, b: String)
3030
*/
3131
class HiveQuerySuite extends HiveComparisonTest {
3232

33+
createQueryTest("having no references",
34+
"SELECT key FROM src GROUP BY key HAVING COUNT(*) > 1")
35+
3336
createQueryTest("boolean = number",
3437
"""
3538
|SELECT

0 commit comments

Comments
 (0)