kazuyukitanimura commented on a change in pull request #33930:
URL: https://github.com/apache/spark/pull/33930#discussion_r742345065



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated
+  // Return false if the expression may return null without non-null inputs.

Review comment:
       Thanks updated!

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated

Review comment:
       I re-organized the comment, hopefully it is more understandable now.
   In particular, this particular part of the comment **"E.g. `Cast` is 
`NullIntolerant`; however,  cast('Infinity' as integer) is null. Hence, `Cast` 
is not supported `NullIntolerant`"**

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated

Review comment:
       I re-organized the comment, hopefully it is more understandable now.
   In particular, this part of the comment **"E.g. `Cast` is `NullIntolerant`; 
however,  cast('Infinity' as integer) is null. Hence, `Cast` is not supported 
`NullIntolerant`"**

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -446,6 +446,53 @@ object BooleanSimplification extends Rule[LogicalPlan] 
with PredicateHelper {
 }
 
 
+/**
+ * Move/Push `Not` operator if it's beneficial.

Review comment:
       This optimization is actually more than just the case where leaf nodes 
are boolean or null. So in that sense, the generic name should be okay.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated
+  // Return false if the expression may return null without non-null inputs.
+  // E.g. Cast is NullIntolerant; however, cast('Infinity' as integer) returns 
null.
+  // Cannot apply to `ExtractValue` as the query planner uses the trait to 
resolve the columns.
+  // E.g. the planner may resolve column `a` to `a#123`, then IsNull(a#123) 
cannot be optimized
+  // Applying to `EqualTo` is too disruptive for [SPARK-32290] test cases
+  // e with multiple children requires the deterministic check because 
optimizing IsNull(a > b) to
+  // Or(IsNull(a), IsNull(b)), for example, may cause skipping the evaluation 
of b
+  private def supportedNullIntolerant(e: NullIntolerant): Boolean = (e match {
+    case _: Not => true
+    case _: GreaterThan | _: GreaterThanOrEqual | _: LessThan | _: 
LessThanOrEqual

Review comment:
       This is due to earlier feedback in this review. Addressed in this part 
of the comment;
   **"Applying to `EqualTo` is too disruptive for [SPARK-32290] optimization, 
not supported for now."**

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated
+  // Return false if the expression may return null without non-null inputs.

Review comment:
       Thanks updated!

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated

Review comment:
       I re-organized the comment, hopefully it is more understandable now.
   In particular, this particular part of the comment **"E.g. `Cast` is 
`NullIntolerant`; however,  cast('Infinity' as integer) is null. Hence, `Cast` 
is not supported `NullIntolerant`"**

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated

Review comment:
       I re-organized the comment, hopefully it is more understandable now.
   In particular, this part of the comment **"E.g. `Cast` is `NullIntolerant`; 
however,  cast('Infinity' as integer) is null. Hence, `Cast` is not supported 
`NullIntolerant`"**

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -446,6 +446,53 @@ object BooleanSimplification extends Rule[LogicalPlan] 
with PredicateHelper {
 }
 
 
+/**
+ * Move/Push `Not` operator if it's beneficial.

Review comment:
       This optimization is actually more than just the case where leaf nodes 
are boolean or null. So in that sense, the generic name should be okay.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -813,6 +860,39 @@ object NullPropagation extends Rule[LogicalPlan] {
 }
 
 
+/**
+ * Unwrap the input of IsNull/IsNotNull if the input is NullIntolerant
+ * E.g. IsNull(Not(null)) == IsNull(null)
+ */
+object NullDownPropagation extends Rule[LogicalPlan] {
+  // Not all NullIntolerant can be propagated
+  // Return false if the expression may return null without non-null inputs.
+  // E.g. Cast is NullIntolerant; however, cast('Infinity' as integer) returns 
null.
+  // Cannot apply to `ExtractValue` as the query planner uses the trait to 
resolve the columns.
+  // E.g. the planner may resolve column `a` to `a#123`, then IsNull(a#123) 
cannot be optimized
+  // Applying to `EqualTo` is too disruptive for [SPARK-32290] test cases
+  // e with multiple children requires the deterministic check because 
optimizing IsNull(a > b) to
+  // Or(IsNull(a), IsNull(b)), for example, may cause skipping the evaluation 
of b
+  private def supportedNullIntolerant(e: NullIntolerant): Boolean = (e match {
+    case _: Not => true
+    case _: GreaterThan | _: GreaterThanOrEqual | _: LessThan | _: 
LessThanOrEqual

Review comment:
       This is due to earlier feedback in this review. Addressed in this part 
of the comment;
   **"Applying to `EqualTo` is too disruptive for [SPARK-32290] optimization, 
not supported for now."**




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