Skip to content

Commit

Permalink
Merge pull request #38 from lyft/DATA-11063
Browse files Browse the repository at this point in the history
Remove sorted requirement on a window
  • Loading branch information
catalinii authored Jul 1, 2021
2 parents 7fe6aa6 + 07e3acd commit d0718cb
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
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 if (ctx.windowFrame != null &&
ctx.windowFrame().frameType.getType == SqlBaseParser.RANGE) {
// for RANGE window frame, we won't add default order spec
ctx.sortItem.asScala.map(visitSortItem)
} else {
// Same default behaviors like hive, when order spec is null
// set partition spec expression as order spec
ctx.partition.asScala.map { expr =>
SortOrder(expression(expr), Ascending, Ascending.defaultNullOrdering, Seq.empty)
}
}

// RANGE/ROWS BETWEEN ...
val frameSpecOption = Option(ctx.windowFrame).map { frame =>
Expand Down

0 comments on commit d0718cb

Please sign in to comment.