Skip to content

Commit

Permalink
Fallback to Spark for LIKE with custom escape character
Browse files Browse the repository at this point in the history
Currently, LIKE with custom escape character produces incorrect results.
  • Loading branch information
sujithjay committed May 27, 2024
1 parent cbf4730 commit 03d8bb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
None
}

case Like(left, right, _) =>
case Like(left, right, escapeChar) if escapeChar == '\\' =>
// TODO escapeChar
val leftExpr = exprToProtoInternal(left, inputs)
val rightExpr = exprToProtoInternal(right, inputs)
Expand Down
14 changes: 14 additions & 0 deletions spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}
}

test("like with custom escape") {
val table = "names"
withTable(table) {
sql(s"create table $table(id int, name varchar(20)) using parquet")
sql(s"insert into $table values(1,'James Smith')")
sql(s"insert into $table values(2,'Michael_Rose')")
sql(s"insert into $table values(3,'Robert_R_Williams')")

// Filter column having values that include underscores
val query = sql("select id from names where name like '%$_%' escape '$'")
checkAnswer(query, Row(2) :: Row(3) :: Nil)
}
}

test("contains") {
assume(!isSpark32)

Expand Down

0 comments on commit 03d8bb2

Please sign in to comment.