cloud-fan commented on code in PR #39722:
URL: https://github.com/apache/spark/pull/39722#discussion_r1090479431
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala:
##########
@@ -407,6 +408,74 @@ object BinaryArithmetic {
def unapply(e: BinaryArithmetic): Option[(Expression, Expression)] =
Some((e.left, e.right))
}
+/**
+ * A helper class used by the Add expression during canonicalization. During
+ * canonicalization, when we have a long tree of Add operations, we use the
MultiAdd expression
+ * to represent that tree instead of creating new Add objects. This class is
added as a memory
+ * optimization for processing large Add operation trees without creating a
large number of
+ * new intermediate objects.
+ * @param operands A sequence of operands that produces an Add tree.
+ * @param evalMode The expression evaluation mode.
+ */
+case class MultiAdd(operands: Seq[Expression], evalMode: EvalMode.Value)
extends Unevaluable {
+ // 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.
+ private def allowPrecisionLoss: Boolean =
SQLConf.get.decimalOperationsAllowPrecisionLoss
+
+ // scalastyle:off
+ // The formula follows Hive which is based on the SQL standard and MS SQL:
+ //
https://cwiki.apache.org/confluence/download/attachments/27362075/Hive_Decimal_Precision_Scale_Support.pdf
+ // https://msdn.microsoft.com/en-us/library/ms190476.aspx
+ // Result Precision: max(s1, s2) + max(p1-s1, p2-s2) + 1
+ // Result Scale: max(s1, s2)
+ // scalastyle:on
+ private def resultDecimalType(p1: Int, s1: Int, p2: Int, s2: Int):
DecimalType = {
Review Comment:
shall we move it to a util function to avoid duplicating the code?
--
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]