cloud-fan commented on a change in pull request #32488:
URL: https://github.com/apache/spark/pull/32488#discussion_r638809187
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala
##########
@@ -21,15 +21,15 @@ import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.Literal.FalseLiteral
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule
-import org.apache.spark.sql.catalyst.trees.TreePattern.BINARY_COMPARISON
+import org.apache.spark.sql.catalyst.trees.TreePattern.{BINARY_COMPARISON, IN}
import org.apache.spark.sql.types._
/**
- * Unwrap casts in binary comparison operations with patterns like following:
+ * Unwrap casts in binary comparison or `In` operations with patterns like
following:
*
- * `BinaryComparison(Cast(fromExp, toType), Literal(value, toType))`
- * or
- * `BinaryComparison(Literal(value, toType), Cast(fromExp, toType))`
+ * - `BinaryComparison(Cast(fromExp, toType), Literal(value, toType))`
+ * - `BinaryComparison(Literal(value, toType), Cast(fromExp, toType))`
+ * - `In(Cast(fromExp, toType), Seq(Literal(v1, toType), Literal(v2, toType),
...)`
Review comment:
So we are relying on the assumption that `UnwrapCastInBinaryComparison`
happens before `OptimizeIn`.
This is fragile as the execution order of the rules in the same batch is
pretty unpredictable, and may change over time if code factor happens, new
optimization rules added, etc.
It's better to make sure these catalyst rules are orthogonal, and that why
`In` and `InSet` usually appears together: if a rule needs to handle In, it
usually should handle InSet as well.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala
##########
@@ -21,15 +21,15 @@ import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.Literal.FalseLiteral
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule
-import org.apache.spark.sql.catalyst.trees.TreePattern.BINARY_COMPARISON
+import org.apache.spark.sql.catalyst.trees.TreePattern.{BINARY_COMPARISON, IN}
import org.apache.spark.sql.types._
/**
- * Unwrap casts in binary comparison operations with patterns like following:
+ * Unwrap casts in binary comparison or `In` operations with patterns like
following:
*
- * `BinaryComparison(Cast(fromExp, toType), Literal(value, toType))`
- * or
- * `BinaryComparison(Literal(value, toType), Cast(fromExp, toType))`
+ * - `BinaryComparison(Cast(fromExp, toType), Literal(value, toType))`
+ * - `BinaryComparison(Literal(value, toType), Cast(fromExp, toType))`
+ * - `In(Cast(fromExp, toType), Seq(Literal(v1, toType), Literal(v2, toType),
...)`
Review comment:
So we are relying on the assumption that `UnwrapCastInBinaryComparison`
happens before `OptimizeIn`.
This is fragile as the execution order of the rules in the same batch is
pretty unpredictable, and may change over time if code factor happens, new
optimization rules added, etc.
It's better to make sure these catalyst rules are orthogonal, and that's why
`In` and `InSet` usually appears together: if a rule needs to handle In, it
usually should handle InSet as well.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]