cloud-fan commented on code in PR #39722:
URL: https://github.com/apache/spark/pull/39722#discussion_r1092171113


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -1335,3 +1335,70 @@ trait CommutativeExpression extends Expression {
       f: PartialFunction[CommutativeExpression, Seq[Expression]]): 
Seq[Expression] =
     gatherCommutative(this, f).sortBy(_.hashCode())
 }
+
+/**
+ * A helper class used by the Commutative expressions during canonicalization. 
During
+ * canonicalization, when we have a long tree of commutative operations, we 
use the MultiCommutative
+ * expression to represent that tree instead of creating new commutative 
objects.
+ * This class is added as a memory optimization for processing large 
commutative operation trees
+ * without creating a large number of new intermediate objects.
+ * The MultiCommutativeOp memory optimization is applied to the following 
commutative
+ * expressions:
+ *      Add, Multiply, And, Or, BitwiseAnd, BitwiseOr, BitwiseXor.
+ * @param operands A sequence of operands that produces a commutative 
expression tree.
+ * @param evalMode The optional expression evaluation mode.
+ * @param originalRoot Root operator of the commutative expression tree before 
canonicalization.
+ *                     This object reference is used to deduce the return 
dataType of Add and
+ *                     Multiply operations when the input datatype is decimal.
+ */
+case class MultiCommutativeOp(
+  operands: Seq[Expression],
+  evalMode: Option[EvalMode.Value])(originalRoot: Expression) extends 
Unevaluable {

Review Comment:
   shall we add one more parameter `opCls: Class[_]`? Otherwise a bunch of 
`Add` can be equal to a bunch of `Multiply`



-- 
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]

Reply via email to