ritikam2 commented on code in PR #40116:
URL: https://github.com/apache/spark/pull/40116#discussion_r1140652247
##########
sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala:
##########
@@ -89,9 +89,22 @@ class RelationalGroupedDataset protected[sql](
case expr: NamedExpression => expr
case a: AggregateExpression if
a.aggregateFunction.isInstanceOf[TypedAggregateExpression] =>
UnresolvedAlias(a, Some(Column.generateAlias))
- case expr: Expression => Alias(expr, toPrettySQL(expr))()
+ case ag: UnresolvedFunction if (containsStar(Seq(ag))) || ag.isDistinct =>
+ UnresolvedAlias(expr, None)
+ case expr: Expression =>
+ if (containsStar(Seq(expr))) {
+ UnresolvedAlias(expr, None)
+ } else {
+ Alias(expr, toPrettySQL(expr))()
Review Comment:
What should toPrettySQL be generating as alias? Currently it emits
count(unresolvedstar()). I tried count(distinct *) then the query output was:
scala> df.groupBy("id").agg(count_distinct($"*"))
res0: org.apache.spark.sql.DataFrame = [id: bigint, count(distinct *):
bigint]
So I am wondering if the fix is in toPrettySQL or the Analyzer. Analyzer
should be able to handle unresolvedstar aliases.
The original query does not have an alias for the aggregate expression. For
such queries the Origin in Analyzer is (None,,,,..). Whereas if you give a
spark.sql query
spark.sql(" SELECT id, COUNT(DISTINCT *) FROM table GROUP BY id ")
The origin is not none. I wonder if this is what throws off the Analyzer.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]