[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 <michael@databricks.com>

Closes #1640 from marmbrus/havingNoRef and squashes the following commits:

92d3901 [Michael Armbrust] Don't check resolved for having filters.
This commit is contained in:
Michael Armbrust 2014-07-29 18:14:20 -07:00
parent 2c356665c9
commit 39b8193102
3 changed files with 140 additions and 1 deletions

View file

@ -159,7 +159,7 @@ class Analyzer(catalog: Catalog, registry: FunctionRegistry, caseSensitive: Bool
object UnresolvedHavingClauseAttributes extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
case filter @ Filter(havingCondition, aggregate @ Aggregate(_, originalAggExprs, _))
if !filter.resolved && aggregate.resolved && containsAggregate(havingCondition) => {
if aggregate.resolved && containsAggregate(havingCondition) => {
val evaluatedCondition = Alias(havingCondition, "havingCondition")()
val aggExprsWithHaving = evaluatedCondition +: originalAggExprs

View file

@ -0,0 +1,136 @@
0
5
12
15
18
24
26
35
37
42
51
58
67
70
72
76
83
84
90
95
97
98
100
103
104
113
118
119
120
125
128
129
134
137
138
146
149
152
164
165
167
169
172
174
175
176
179
187
191
193
195
197
199
200
203
205
207
208
209
213
216
217
219
221
223
224
229
230
233
237
238
239
242
255
256
265
272
273
277
278
280
281
282
288
298
307
309
311
316
317
318
321
322
325
327
331
333
342
344
348
353
367
369
382
384
395
396
397
399
401
403
404
406
409
413
414
417
424
429
430
431
438
439
454
458
459
462
463
466
468
469
478
480
489
492
498

View file

@ -30,6 +30,9 @@ case class TestData(a: Int, b: String)
*/
class HiveQuerySuite extends HiveComparisonTest {
createQueryTest("having no references",
"SELECT key FROM src GROUP BY key HAVING COUNT(*) > 1")
createQueryTest("boolean = number",
"""
|SELECT