beliefer commented on a change in pull request #26656: [SPARK-27986][SQL]
Support ANSI SQL filter clause for aggregate expression
URL: https://github.com/apache/spark/pull/26656#discussion_r361042960
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
##########
@@ -2835,6 +2835,54 @@ class SQLQuerySuite extends QueryTest with
SharedSparkSession {
checkAnswer(df, Row(1, 3, 4) :: Row(2, 3, 4) :: Row(3, 3, 4) :: Nil)
}
+ test("Support filter clause for aggregate function with hash aggregate") {
+ Seq(("COUNT(a)", 3), ("COLLECT_LIST(a)", Seq(1, 2, 3))).foreach {
funcToResult =>
+ val query = s"SELECT ${funcToResult._1} FILTER (WHERE b > 1) FROM
testData2"
+ val df = sql(query)
+ val physical = df.queryExecution.sparkPlan
+ val aggregateExpressions = physical.collectFirst {
+ case agg: HashAggregateExec => agg.aggregateExpressions
+ case agg: ObjectHashAggregateExec => agg.aggregateExpressions
+ }
+ assert(aggregateExpressions.isDefined)
+ assert(aggregateExpressions.get.size == 1)
+ aggregateExpressions.get.foreach { expr =>
+ assert(expr.filter.isDefined)
+ }
+ checkAnswer(df, Row(funcToResult._2) :: Nil)
+ }
+ }
+
+ test("Support filter clause for aggregate function uses SortAggregateExec") {
+ withSQLConf(SQLConf.USE_OBJECT_HASH_AGG.key -> "false") {
+ val query = s"SELECT PERCENTILE(a, 1) FILTER (WHERE b > 1) FROM
testData2"
+ val df = sql(query)
Review comment:
OK
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]