From 03d8bb2dbca1cf928a2035bc436b834eeb0fef78 Mon Sep 17 00:00:00 2001 From: Sujith Jay Nair Date: Mon, 27 May 2024 19:32:37 -0400 Subject: [PATCH] Fallback to Spark for LIKE with custom escape character Currently, LIKE with custom escape character produces incorrect results. --- .../org/apache/comet/serde/QueryPlanSerde.scala | 2 +- .../org/apache/comet/CometExpressionSuite.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala index 6eda0547f..33e789080 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -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) diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala index 3683c8d44..83f6ad917 100644 --- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala +++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala @@ -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)