cloud-fan 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_r360394479
########## File path: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala ########## @@ -2835,6 +2835,84 @@ 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(("APPROX_COUNT_DISTINCT(a)", 3), ("COUNT(a)", 3), ("FIRST(a)", 1), ("LAST(a)", 3), + ("MAX(a)", 3), ("AVG(a)", 2.0), ("MIN(a)", 1), ("SUM(a)", 6), ("PERCENTILE(a, 1)", 3), + ("PERCENTILE_APPROX(a, 0.5, 100)", 2.0), ("COLLECT_LIST(a)", Seq(1, 2, 3)), + ("COLLECT_SET(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") { + Seq(("PERCENTILE(a, 1)", 3), Review comment: ditto ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org