LuciferYang commented on code in PR #55506:
URL: https://github.com/apache/spark/pull/55506#discussion_r3135750685


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/basicPhysicalOperators.scala:
##########
@@ -303,25 +312,74 @@ case class FilterExec(condition: Expression, child: 
SparkPlan)
             boundOtherPreds.indexWhere(_.exists(e => ExpressionEquals(e) == 
exprEq))
           }.map { case (idx, kvs) => idx -> kvs.map(_._2) }
 
+        // Emit an IsNotNull check, binding against child.output so the inner 
expression
+        // is evaluated with its original nullability (the 
tightened-nullability `output`
+        // is only appropriate inside otherPreds, where the required checks 
have fired).
+        // The `bound.nullable` gate below is defensive -- `IsNotNull` always 
produces a
+        // non-nullable Boolean, so this branch is structurally unreachable 
today; it
+        // mirrors the non-CSE helper's shape to keep future refactors safe.
+        def genNotNull(pred: Expression): String = {
+          val bound = BindReferences.bindReference(pred, child.output)
+          val evaluated = evaluateRequiredVariables(child.output, input, 
pred.references)
+          val ev = ExpressionCanonicalizer.execute(bound).genCode(ctx)
+          val nullCheck = if (bound.nullable) s"${ev.isNull} || " else ""
+          s"""
+             |$evaluated
+             |${ev.code}
+             |if (${nullCheck}!${ev.value}) continue;
+           """.stripMargin
+        }
+
+        val generatedIsNotNullChecks = new Array[Boolean](notNullPreds.length)
+        val extraIsNotNullAttrs = mutable.Set[Attribute]()
+
         val predCode: String = {
           val parts = new StringBuilder
           ctx.withSubExprEliminationExprs(subExprs.states) {
-            boundOtherPreds.zipWithIndex.foreach { case (bound, idx) =>
-              statesByFirstUse.get(idx).foreach { states =>
-                parts.append(ctx.evaluateSubExprEliminationState(states))
-                parts.append('\n')
-              }
-              val ev = ExpressionCanonicalizer.execute(bound).genCode(ctx)
-              val nullCheck = if (bound.nullable) s"${ev.isNull} || " else ""
-              parts.append(ev.code.toString)
-              parts.append(s"\nif (${nullCheck}!${ev.value}) continue;\n")
+            
otherPreds.iterator.zip(boundOtherPreds.iterator).zipWithIndex.foreach {

Review Comment:
   ```suggestion
               otherPreds.zip(boundOtherPreds).zipWithIndex.foreach {
   ```



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