This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 8bca01e30ae [SPARK-44523][SQL] Filter's maxRows/maxRowsPerPartition is 
0 if condition is FalseLiteral
8bca01e30ae is described below

commit 8bca01e30ae2dd0df06ec96926ad481a1a7050a2
Author: Yuming Wang <[email protected]>
AuthorDate: Tue Jul 25 12:06:06 2023 +0900

    [SPARK-44523][SQL] Filter's maxRows/maxRowsPerPartition is 0 if condition 
is FalseLiteral
    
    ### What changes were proposed in this pull request?
    
    This PR updates Filter's maxRows/maxRowsPerPartition to 0 if condition is 
`FalseLiteral`.
    
    ### Why are the changes needed?
    
    Provide an accurate value, as some optimization rules use this value to 
optimize queries.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Unit test.
    
    Closes #42126 from wangyum/SPARK-44523.
    
    Lead-authored-by: Yuming Wang <[email protected]>
    Co-authored-by: Yuming Wang <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 .../sql/catalyst/plans/logical/basicLogicalOperators.scala    | 11 +++++++++--
 .../apache/spark/sql/catalyst/plans/LogicalPlanSuite.scala    |  6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
index 4bb830662a3..57e4b31dbe0 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
@@ -303,8 +303,15 @@ case class Filter(condition: Expression, child: 
LogicalPlan)
   extends OrderPreservingUnaryNode with PredicateHelper {
   override def output: Seq[Attribute] = child.output
 
-  override def maxRows: Option[Long] = child.maxRows
-  override def maxRowsPerPartition: Option[Long] = child.maxRowsPerPartition
+  override def maxRows: Option[Long] = condition match {
+    case Literal.FalseLiteral => Some(0L)
+    case _ => child.maxRows
+  }
+
+  override def maxRowsPerPartition: Option[Long] = condition match {
+    case Literal.FalseLiteral => Some(0L)
+    case _ => child.maxRowsPerPartition
+  }
 
   final override val nodePatterns: Seq[TreePattern] = Seq(FILTER)
 
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/plans/LogicalPlanSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/plans/LogicalPlanSuite.scala
index 1d533e9d0d4..a3bdfd07aee 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/plans/LogicalPlanSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/plans/LogicalPlanSuite.scala
@@ -139,4 +139,10 @@ class LogicalPlanSuite extends SparkFunSuite {
     assert(sample.maxRows === Some(200))
     assert(sample.maxRowsPerPartition === Some(68))
   }
+
+  test("SPARK-44523: Filter's maxRows/maxRowsPerPartition is 0 if condition is 
FalseLiteral") {
+    val query = Range(0, 100, 1, 10)
+    assert(query.where(Literal.FalseLiteral).maxRows.contains(0))
+    assert(query.where(Literal.FalseLiteral).maxRowsPerPartition.contains(0))
+  }
 }


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

Reply via email to