viirya commented on a change in pull request #25204: [SPARK-28441][SQL][Python] 
Fix error when non-foldable expression is used in correlated scalar subquery
URL: https://github.com/apache/spark/pull/25204#discussion_r307223851
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ##########
 @@ -650,7 +650,9 @@ object ColumnPruning extends Rule[LogicalPlan] {
    */
   private def removeProjectBeforeFilter(plan: LogicalPlan): LogicalPlan = plan 
transformUp {
     case p1 @ Project(_, f @ Filter(_, p2 @ Project(_, child)))
-      if p2.outputSet.subsetOf(child.outputSet) =>
+      if p2.outputSet.subsetOf(child.outputSet) &&
+        // We only remove attribute-only project.
+        p2.projectList.forall(_.isInstanceOf[AttributeReference]) =>
 
 Review comment:
   oh, the issue was seen in previous comment 
https://github.com/apache/spark/pull/25204/commits/33441a32412eacbe84f2b188f046b2959a8b60ee.
 It was overwritten now.
   
   We added a column for count bug. The column checks a always-true leading 
column `alwaysTrueExpr`, returns special value if `alwaysTrueExpr` is null, to 
simulate empty input case.
   
   This column reuses expr id of original output in the subquery. In 
non-foldable expression case, the added column in a potential 
Project-Filter-Project, will be trimmed by `removeProjectBeforeFilter`, because 
the second project meets `p2.outputSet.subsetOf(child.outputSet)`.
   
   My original fix is to create an expr id. Replace original expr id with new 
one in the subquery. Looks complicated. This seems a simple fix, and looks 
reasonable.
   
   

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to