Skip to content

Commit 7bbdb07

Browse files
committed
InMemoryTable support StartsWith predicate push down
1 parent 8e5f3c6 commit 7bbdb07

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ case class InMemoryTableScanExec(
237237
if list.forall(ExtractableLiteral.unapply(_).isDefined) && list.nonEmpty =>
238238
list.map(l => statsFor(a).lowerBound <= l.asInstanceOf[Literal] &&
239239
l.asInstanceOf[Literal] <= statsFor(a).upperBound).reduce(_ || _)
240+
241+
case StartsWith(a: AttributeReference, ExtractableLiteral(l)) =>
242+
statsFor(a).lowerBound.substr(0, Length(l)) <= l &&
243+
l <= statsFor(a).upperBound.substr(0, Length(l))
244+
case StartsWith(ExtractableLiteral(l), a: AttributeReference) =>
245+
statsFor(a).lowerBound.substr(0, Length(l)) <= l &&
246+
l <= statsFor(a).upperBound.substr(0, Length(l))
240247
}
241248

242249
lazy val partitionFilters: Seq[Expression] = {

sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/PartitionBatchPruningSuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ class PartitionBatchPruningSuite
170170
}
171171
}
172172

173+
// Support `StartsWith` predicate
174+
checkBatchPruning("SELECT CAST(s AS INT) FROM pruningStringData WHERE s like '18%'", 1, 1) {
175+
180 to 189
176+
}
177+
checkBatchPruning("SELECT CAST(s AS INT) FROM pruningStringData WHERE s like '%'", 5, 11) {
178+
100 to 200
179+
}
180+
173181
// With disable IN_MEMORY_PARTITION_PRUNING option
174182
test("disable IN_MEMORY_PARTITION_PRUNING") {
175183
spark.conf.set(SQLConf.IN_MEMORY_PARTITION_PRUNING.key, false)

0 commit comments

Comments
 (0)