You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cloud-fan (via GitHub)" <gi...@apache.org> on 2023/03/01 07:59:26 UTC

[GitHub] [spark] cloud-fan commented on a diff in pull request #40093: [SPARK-42500][SQL] ConstantPropagation supports more cases

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -200,14 +200,20 @@ object ConstantPropagation extends Rule[LogicalPlan] {
 
   private def replaceConstants(condition: Expression, equalityPredicates: EqualityPredicates)
     : Expression = {
-    val constantsMap = AttributeMap(equalityPredicates.map(_._1))
-    val predicates = equalityPredicates.map(_._2).toSet
-    def replaceConstants0(expression: Expression) = expression transform {
+    val allConstantsMap = AttributeMap(equalityPredicates.map(_._1))
+    val allPredicates = equalityPredicates.map(_._2).toSet
+    def replaceConstants0(
+        expression: Expression, constantsMap: AttributeMap[Literal]) = expression transform {
       case a: AttributeReference => constantsMap.getOrElse(a, a)
     }
     condition transform {
-      case e @ EqualTo(_, _) if !predicates.contains(e) => replaceConstants0(e)
-      case e @ EqualNullSafe(_, _) if !predicates.contains(e) => replaceConstants0(e)
+      case b: BinaryComparison =>
+        if (!allPredicates.contains(b)) {
+          replaceConstants0(b, allConstantsMap)
+        } else {
+          val excludedEqualityPredicates = equalityPredicates.filterNot(_._2.semanticEquals(b))

Review Comment:
   Can we exclude it first? We should add a new optimizer rule later to do more advanced predicate simplification.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org