cloud-fan commented on code in PR #36698:
URL: https://github.com/apache/spark/pull/36698#discussion_r885221860
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala:
##########
@@ -208,6 +210,76 @@ case class Abs(child: Expression, failOnError: Boolean =
SQLConf.get.ansiEnabled
override protected def withNewChildInternal(newChild: Expression): Abs =
copy(child = newChild)
}
+/**
+ * The child class should override decimalType method to report the result
data type which must
+ * follow the description of `DecimalPrecision`.
+ *
+ * When `spark.sql.decimalOperations.allowPrecisionLoss` is set to true, if
the precision / scale
+ * needed are out of the range of available values, the scale is reduced up to
6, in order to
+ * prevent the truncation of the integer part of the decimals.
+ *
+ * Rounds the decimal to given scale and check whether the decimal can fit in
provided precision
+ * or not. If not, if `nullOnOverflow` is `true`, it returns `null`; otherwise
an
+ * `ArithmeticException` is thrown.
+ */
+trait DecimalArithmetic extends BinaryArithmetic {
+ protected val nullOnOverflow: Boolean = !failOnError
+ protected val allowPrecisionLoss: Boolean =
SQLConf.get.decimalOperationsAllowPrecisionLoss
+
+ override def checkInputDataTypes(): TypeCheckResult = (left.dataType,
right.dataType) match {
+ case (_: DecimalType, _: DecimalType) =>
+ // We allow eval decimal type with different precision and scale, and
change the precision
+ // and scale before return result.
+ TypeCheckResult.TypeCheckSuccess
+ case _ => super.checkInputDataTypes()
+ }
+
+ /** Name of the function for this expression on a [[Decimal]] type. */
+ protected def decimalMethod: String =
+ throw
QueryExecutionErrors.notOverrideExpectedMethodsError("DecimalArithmetic",
Review Comment:
which sub-class does not override it?
--
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]