AngersZhuuuu commented on a change in pull request #27861: 
[SPARK-30707][SQL]Window function set partitionSpec as order spec when 
orderSpec is empty
URL: https://github.com/apache/spark/pull/27861#discussion_r390793409
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -1691,7 +1691,15 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   override def visitWindowDef(ctx: WindowDefContext): WindowSpecDefinition = 
withOrigin(ctx) {
     // CLUSTER BY ... | PARTITION BY ... ORDER BY ...
     val partition = ctx.partition.asScala.map(expression)
-    val order = ctx.sortItem.asScala.map(visitSortItem)
+    val order = if (ctx.sortItem.asScala.nonEmpty) {
+      ctx.sortItem.asScala.map(visitSortItem)
+    } else {
+      // Same default behaviors like hive, when order spec is null
 
 Review comment:
   > From the ANSI SQL spec: `If WD has no window ordering clause, then the 
window ordering is implementation-dependent, and all rows are peers.`
   > 
   > I don't think this is a bug fix but rather a new feature. We need to 
justify it: what's the behavior of other popular SQL systems like presto, 
snowflake, redshift, etc.? And what's the benefit for end users?
   
   I will check other SQL system later.
   In our production, one benefit is we can migrate hive sql to spark sql  
smother and don't need to rewrite sql one by one

----------------------------------------------------------------
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]

Reply via email to