Skip to content

Commit

Permalink
change another way
Browse files Browse the repository at this point in the history
  • Loading branch information
gatorsmile committed Jul 9, 2016
1 parent 3036847 commit d135b77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2047,14 +2047,14 @@ object EliminateUnions extends Rule[LogicalPlan] {
}

/**
* Converts foldable numeric expressions to integers of [[GlobalLimit]] and [[LocalLimit]] operators
* Converts foldable numeric expressions to integers in [[GlobalLimit]] and [[LocalLimit]] operators
*/
object ResolveLimits extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case g @ GlobalLimit(limitExpr, _) if limitExpr.foldable && isNumeric(limitExpr.eval()) =>
g.copy(limitExpr = Literal(limitExpr.eval().asInstanceOf[Number].intValue(), IntegerType))
g.copy(limitExpr = Literal(Cast(limitExpr, IntegerType).eval(), IntegerType))
case l @ LocalLimit(limitExpr, _) if limitExpr.foldable && isNumeric(limitExpr.eval()) =>
l.copy(limitExpr = Literal(limitExpr.eval().asInstanceOf[Number].intValue(), IntegerType))
l.copy(limitExpr = Literal(Cast(limitExpr, IntegerType).eval(), IntegerType))
}

private def isNumeric(value: Any): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ trait CheckAnalysis extends PredicateHelper {
"The argument to the LIMIT clause must evaluate to a constant value. " +
s"Limit:${limitExpr.sql}")
}
// Analyzer rule ResolveLimits already converts limitExpr to integers.
limitExpr match {
case IntegerLiteral(limit) if limit >= 0 => // OK
case IntegerLiteral(limit) => failAnalysis(
Expand Down

0 comments on commit d135b77

Please sign in to comment.