spark-test commented on code in PR #59437:
URL: https://github.com/apache/spark/pull/59437#discussion_r4511754235
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -1429,6 +1429,19 @@ trait CommutativeExpression extends Expression {
f: PartialFunction[CommutativeExpression, Seq[Expression]]):
Seq[Expression] =
gatherCommutative(this, f).sortBy(_.hashCode())
+ /**
+ * Reorders only the two direct children of a binary commutative operator,
without flattening
+ * adjacent operators. Used when the operator is commutative but not
associative, e.g.
+ * floating-point addition and multiplication.
+ */
+ protected def orderBinaryCommutative(
Review Comment:
**Nit (P3):** This helper introduces a per-operator path, but the central
contract text was not updated. The `Expression.canonicalized` scaladoc
(Expression.scala:311-319) still says that adjacent same-class
`CommutativeExpression`s are gathered and reordered from the root and that
`canonicalized` is computed only on that root, and the `MultiCommutativeOp`
scaladoc (Expression.scala:1471-1473) lists `Add` and `Multiply` without
exception. Resolved FLOAT/DOUBLE `Add` and `Multiply` now never gather, never
build a `MultiCommutativeOp`, and compute `canonicalized` at every node, so a
maintainer relying on those docs could reintroduce the flattening this PR
removes. Both scaladocs could name the exception and point to
`orderBinaryCommutative`.
**Verification:**
- **Inspection:** The Expression.canonicalized and MultiCommutativeOp
scaladocs name the Add and Multiply result types that use per-operator
ordering, and that set matches the condition implemented in Add.canonicalized
and Multiply.canonicalized.
--
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]