vinodkc commented on code in PR #38419:
URL: https://github.com/apache/spark/pull/38419#discussion_r1080689566
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala:
##########
@@ -1432,6 +1695,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, e.g. LongType, StringType.
+ * 2. a non-leaf abstract data type,
+ * e.g.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 _scale: Int = scaleV.asInstanceOf[Int]
Review Comment:
`scaleV` is used in some other udfs `ceil`, `floor`, so just renamed
`_scale` to `scaleValue`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]