vinodkc commented on code in PR #38419: URL: https://github.com/apache/spark/pull/38419#discussion_r1082023362
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala: ########## @@ -1432,6 +1681,53 @@ case class Logarithm(left: Expression, right: Expression) newLeft: Expression, newRight: Expression): Logarithm = copy(left = newLeft, right = newRight) } +trait BaseBinaryExpression extends BinaryExpression + with ExpectsInputTypes + with Serializable + with ImplicitCastInputTypes { + val child: Expression + val scale: Expression + override def left: Expression = child + override def right: Expression = scale + override def nullable: Boolean = true + override def foldable: Boolean = child.foldable + + /** + * Expected input types from child expressions. The i-th position in the returned seq indicates + * the type requirement for the i-th child. + * + * The possible values at each position are: + * 1. a specific data type, such as LongType or StringType. + * 2. a non-leaf abstract data type, + * such as NumericType, IntegralType, FractionalType. + */ + override def inputTypes: Seq[AbstractDataType] = Seq(NumericType, IntegerType) + + // Avoid repeated evaluation since `scale` is a constant int, + // avoid unnecessary `child` evaluation in both codegen and non-codegen eval + // by checking if scaleV == null as well. + protected lazy val scaleV: Any = scale.eval(EmptyRow) + + protected lazy val scaleValue: Int = scaleV.asInstanceOf[Int] + + override def checkInputDataTypes(): TypeCheckResult = { Review Comment: other related udfs `ceil` , `floor` also does not work with dynamic values. To make it consistent with those udfs, here `scale`is made constant . This part of the code was moved from `class RoundBase ` to new trait `BaseBinaryExpression` -- 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