mikhailnik-db commented on code in PR #48748: URL: https://github.com/apache/spark/pull/48748#discussion_r1843628058
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala: ########## @@ -2219,21 +2219,24 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor numArgs: Int, u: UnresolvedFunction): Expression = { func match { - case owg: SupportsOrderingWithinGroup if u.isDistinct => - throw QueryCompilationErrors.distinctInverseDistributionFunctionUnsupportedError( - owg.prettyName) + case owg: SupportsOrderingWithinGroup if !owg.isDistinctSupported && u.isDistinct => + throw QueryCompilationErrors.distinctWithOrderingFunctionUnsupportedError( + owg.prettyName) case owg: SupportsOrderingWithinGroup - if !owg.orderingFilled && u.orderingWithinGroup.isEmpty => - throw QueryCompilationErrors.inverseDistributionFunctionMissingWithinGroupError( - owg.prettyName) - case owg: SupportsOrderingWithinGroup - if owg.orderingFilled && u.orderingWithinGroup.nonEmpty => - throw QueryCompilationErrors.wrongNumOrderingsForInverseDistributionFunctionError( + if owg.isOrderingMandatory && !owg.orderingFilled && u.orderingWithinGroup.isEmpty => + throw QueryCompilationErrors.functionMissingWithinGroupError(owg.prettyName) + case owg: Mode if owg.orderingFilled && u.orderingWithinGroup.nonEmpty => Review Comment: I described above this case: > Plus this is a strange case, because the actual check of order expressions number happens in withOrderingWithinGroup(...) implementation. This case can match only Mode function if mode(expr) within group (order by expr) syntax is used. And that's because mode(expr) is equivalent to mode() within group (order by expr), and here we actually just ban using two syntaxes simultaneously. I think the code and error message is quite misleading. if `owg.orderingFilled` is true before `withOrderingWithinGroup(u.orderingWithinGroup)` was called means that the implementation makes some hacks to fill it. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org