Skip to content

Commit

Permalink
[SPARK-44523][SQL] Filter's maxRows/maxRowsPerPartition is 0 if condi…
Browse files Browse the repository at this point in the history
…tion 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 apache#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]>
  • Loading branch information
2 people authored and HyukjinKwon committed Jul 25, 2023
1 parent b930f7a commit 8bca01e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 8bca01e

Please sign in to comment.