-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31519][SQL] Cast in having aggregate expressions returns the wrong result #28294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0acfc57
f04db8e
81c9d47
c75fe08
d4a011c
d4ac6d7
18d857f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import org.apache.spark.sql.catalyst.errors.TreeNodeException | |
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode} | ||
| import org.apache.spark.sql.catalyst.parser.ParserUtils | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, LogicalPlan, UnaryNode} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LeafNode, LogicalPlan, UnaryNode} | ||
| import org.apache.spark.sql.catalyst.trees.TreeNode | ||
| import org.apache.spark.sql.catalyst.util.quoteIdentifier | ||
| import org.apache.spark.sql.connector.catalog.{Identifier, TableCatalog} | ||
|
|
@@ -538,3 +538,14 @@ case class UnresolvedOrdinal(ordinal: Int) | |
| override def nullable: Boolean = throw new UnresolvedException(this, "nullable") | ||
| override lazy val resolved = false | ||
| } | ||
|
|
||
| /** | ||
| * Represents unresolved aggregate with having clause, it is turned by the analyzer into a Filter. | ||
| */ | ||
| case class AggregateWithHaving( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also discussed the naming here: #28294 (comment)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think and adding the cast Both queries return empty results, it seems the HAVING after GROUPING SET resolve expression in select clauses first. Maybe it's another bug, I think we should follow the resolving strategy of table scheme first and then select clause? |
||
| havingCondition: Expression, | ||
| child: Aggregate) | ||
| extends UnaryNode { | ||
| override lazy val resolved: Boolean = false | ||
| override def output: Seq[Attribute] = child.output | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -629,7 +629,12 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging | |
| case p: Predicate => p | ||
| case e => Cast(e, BooleanType) | ||
| } | ||
| Filter(predicate, plan) | ||
| plan match { | ||
| case aggregate: Aggregate => | ||
| AggregateWithHaving(predicate, aggregate) | ||
| case _ => | ||
| Filter(predicate, plan) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we also create having here? This is for global aggregate, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also for GROUPING SET. |
||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave some comments here about why we need this special handling for aggregate with having?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done in c75fe08.