cloud-fan commented on a change in pull request #34729: URL: https://github.com/apache/spark/pull/34729#discussion_r777974292
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala ########## @@ -279,6 +280,49 @@ case class Ceil(child: Expression) extends UnaryMathExpression(math.ceil, "CEIL" override protected def withNewChildInternal(newChild: Expression): Ceil = copy(child = newChild) } +object Ceil { + def apply(child: Expression, scale: Expression): Expression = { + val scaleV = scale.eval(EmptyRow) + if (scaleV == null) throw new AnalysisException("Scale parameter can not be null") + + scaleV.asInstanceOf[Int] match { + case 0 => Ceil(child) + case x if x < 0 => RoundCeil(Cast(child, LongType), scale) + case _ => RoundCeil(child, scale) + } + } +} + +@ExpressionDescription( + usage = "_FUNC_(expr) - Returns the smallest integer not smaller than `expr`.", + examples = """ + Examples: + > SELECT _FUNC_(-0.1); + 0 + > SELECT _FUNC_(5); + 5 + > SELECT _FUNC_(3.1411, 3); + 3.142 + """, + since = "3.3.0", + group = "math_funcs") +object CeilExpressionBuilder extends ExpressionBuilder { + def build(expressions: Seq[Expression]): Expression = { + if (expressions.length == 1) Ceil(expressions.head) + else if (expressions.length == 2) Ceil(expressions(0), expressions(1)) + else throw new AnalysisException("Function ceil cannot take more than 2 parameters") + } +} + +case class RoundCeil(child: Expression, scale: Expression) + extends RoundBase(child, scale, BigDecimal.RoundingMode.CEILING, "ROUND_CEILING") + with Serializable with ImplicitCastInputTypes { + def this(child: Expression) = this(child, Literal(0)) Review comment: do we need this? -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org