Skip to content

Commit

Permalink
Hive partition pruning support Contains, StartsWith and EndsWith pred…
Browse files Browse the repository at this point in the history
…icate
  • Loading branch information
wangyum committed Nov 16, 2020
1 parent 0046222 commit 9c40971
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -753,6 +753,15 @@ private[client] class Shim_v0_13 extends Shim_v0_12 {
ExtractableLiteral(value), ExtractAttribute(SupportedAttribute(name))) =>
Some(s"$value ${op.symbol} $name")

case Contains(ExtractAttribute(SupportedAttribute(name)), ExtractableLiteral(value)) =>
Some(s"$name like " + (("\".*" + value.drop(1)).dropRight(1) + ".*\""))

case StartsWith(ExtractAttribute(SupportedAttribute(name)), ExtractableLiteral(value)) =>
Some(s"$name like " + (value.dropRight(1) + ".*\""))

case EndsWith(ExtractAttribute(SupportedAttribute(name)), ExtractableLiteral(value)) =>
Some(s"$name like " + ("\".*" + value.drop(1)))

case And(expr1, expr2) if useAdvanced =>
val converted = convert(expr1) ++ convert(expr2)
if (converted.isEmpty) {
Expand Down
Expand Up @@ -272,6 +272,24 @@ class HivePartitionFilteringSuite(version: String)
day1 :: day2 :: Nil)
}

test("getPartitionsByFilter: chunk contains bb") {
testMetastorePartitionFiltering(
attr("chunk").contains("bb"),
(20170101 to 20170103, 0 to 4, Seq("bb")) :: Nil)
}

test("getPartitionsByFilter: chunk startsWith b") {
testMetastorePartitionFiltering(
attr("chunk").startsWith("b"),
(20170101 to 20170103, 0 to 4, Seq("ba", "bb")) :: Nil)
}

test("getPartitionsByFilter: chunk endsWith b") {
testMetastorePartitionFiltering(
attr("chunk").endsWith("b"),
(20170101 to 20170103, 0 to 4, Seq("ab", "bb")) :: Nil)
}

private def testMetastorePartitionFiltering(
filterExpr: Expression,
expectedDs: Seq[Int],
Expand Down

0 comments on commit 9c40971

Please sign in to comment.