Skip to content
Closed
Prev Previous commit
Next Next commit
change another way
  • Loading branch information
gatorsmile committed Jul 9, 2016
commit d135b77b2d3dd2f9f6ae160bfb24b73df34d3995
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] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying this out! Yea looks like it's doable. Let's remove it first and do it in follow-ups, to make this PR surgical.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create a JIRA first and discuss with others to decide if it's useful to support all integral types in limit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me revert it back. Thanks!

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