Skip to content

Commit

Permalink
inline SpecifiedWindowFrame.defaultWindowFrame().
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxb1987 committed Jan 31, 2018
1 parent dd242ba commit 895e17c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,11 @@ class Analyzer(
WindowExpression(wf, s.copy(frameSpecification = wf.frame))
case we @ WindowExpression(e, s @ WindowSpecDefinition(_, o, UnspecifiedFrame))
if e.resolved =>
val frame = SpecifiedWindowFrame.defaultWindowFrame(o.nonEmpty, acceptWindowFrame = true)
val frame = if (o.nonEmpty) {
SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow)
} else {
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, UnboundedFollowing)
}
we.copy(windowSpec = s.copy(frameSpecification = frame))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,6 @@ case class SpecifiedWindowFrame(
}
}

object SpecifiedWindowFrame {
/**
* @param hasOrderSpecification If the window spec has order by expressions.
* @param acceptWindowFrame If the window function accepts user-specified frame.
* @return the default window frame.
*/
def defaultWindowFrame(
hasOrderSpecification: Boolean,
acceptWindowFrame: Boolean): SpecifiedWindowFrame = {
if (hasOrderSpecification && acceptWindowFrame) {
// If order spec is defined and the window function supports user specified window frames,
// the default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow)
} else {
// Otherwise, the default frame is
// ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, UnboundedFollowing)
}
}
}

case class UnresolvedWindowExpression(
child: Expression,
windowSpec: WindowSpecReference) extends UnaryExpression with Unevaluable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class ExpressionSQLBuilderSuite extends QueryTest with TestHiveSingleton {
}

test("window specification") {
val frame = SpecifiedWindowFrame.defaultWindowFrame(
hasOrderSpecification = true,
acceptWindowFrame = true
)
val frame = SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow)

checkSQL(
WindowSpecDefinition('a.int :: Nil, Nil, frame),
Expand Down

0 comments on commit 895e17c

Please sign in to comment.