Skip to content

Commit 1356d51

Browse files
committed
feat: do not fallback to Spark for distincts
1 parent 554abaf commit 1356d51

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,15 @@ object QueryPlanSerde extends Logging with CometExprShim {
558558
binding: Boolean,
559559
conf: SQLConf): Option[AggExpr] = {
560560

561+
// Support Count(distinct single_value)
562+
// COUNT(DISTINCT x) - supported
563+
// COUNT(DISTINCT x, x) - supported through transition to COUNT(DISTINCT x)
564+
// COUNT(DISTINCT x, y) - not supported
565+
if (aggExpr.isDistinct && (aggExpr.aggregateFunction.prettyName.toLowerCase == "count" && aggExpr.aggregateFunction.children.length == 1)) {
566+
withInfo(aggExpr, s"Distinct aggregate not supported for: $aggExpr")
567+
return None
568+
}
569+
561570
val fn = aggExpr.aggregateFunction
562571
val cometExpr = aggrSerdeMap.get(fn.getClass)
563572
cometExpr match {

spark/src/test/scala/org/apache/comet/CometFuzzAggregateSuite.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class CometFuzzAggregateSuite extends CometFuzzTestBase {
3030
if (usingDataSourceExec) {
3131
assert(1 == collectNativeScans(cometPlan).length)
3232
}
33+
34+
checkSparkAnswerAndOperator(sql)
3335
}
3436
}
3537

0 commit comments

Comments
 (0)