This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git
The following commit(s) were added to refs/heads/main by this push:
new fd90a284 fix: Fallback to Spark for LIKE with custom escape character
(#478)
fd90a284 is described below
commit fd90a284995d7b518c048127773c16605ed5fd44
Author: Sujith Jay Nair <[email protected]>
AuthorDate: Tue May 28 19:53:13 2024 -0400
fix: Fallback to Spark for LIKE with custom escape character (#478)
* Fallback to Spark for LIKE with custom escape character
Currently, LIKE with custom escape character produces incorrect results.
* For custom escape character, provide user with specific info message
* Test case for default escape char with checkSparkAnswerAndOperator
---
.../org/apache/comet/serde/QueryPlanSerde.scala | 33 +++++++++++++---------
.../org/apache/comet/CometExpressionSuite.scala | 18 ++++++++++++
2 files changed, 37 insertions(+), 14 deletions(-)
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 a717e066..06b9bc7f 100644
--- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
+++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
@@ -1074,23 +1074,28 @@ object QueryPlanSerde extends Logging with
ShimQueryPlanSerde with CometExprShim
None
}
- case Like(left, right, _) =>
- // TODO escapeChar
- val leftExpr = exprToProtoInternal(left, inputs)
- val rightExpr = exprToProtoInternal(right, inputs)
+ case Like(left, right, escapeChar) =>
+ if (escapeChar == '\\') {
+ val leftExpr = exprToProtoInternal(left, inputs)
+ val rightExpr = exprToProtoInternal(right, inputs)
- if (leftExpr.isDefined && rightExpr.isDefined) {
- val builder = ExprOuterClass.Like.newBuilder()
- builder.setLeft(leftExpr.get)
- builder.setRight(rightExpr.get)
+ if (leftExpr.isDefined && rightExpr.isDefined) {
+ val builder = ExprOuterClass.Like.newBuilder()
+ builder.setLeft(leftExpr.get)
+ builder.setRight(rightExpr.get)
- Some(
- ExprOuterClass.Expr
- .newBuilder()
- .setLike(builder)
- .build())
+ Some(
+ ExprOuterClass.Expr
+ .newBuilder()
+ .setLike(builder)
+ .build())
+ } else {
+ withInfo(expr, left, right)
+ None
+ }
} else {
- withInfo(expr, left, right)
+ // TODO custom escape char
+ withInfo(expr, s"custom escape character $escapeChar not supported
in LIKE")
None
}
diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
index 1afdd78e..34c794eb 100644
--- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
+++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
@@ -594,6 +594,24 @@ 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 queryDefaultEscape = sql("select id from names where name like
'%\\_%'")
+ checkSparkAnswerAndOperator(queryDefaultEscape)
+
+ val queryCustomEscape = sql("select id from names where name like '%$_%'
escape '$'")
+ checkAnswer(queryCustomEscape, Row(2) :: Row(3) :: Nil)
+
+ }
+ }
+
test("contains") {
assume(!isSpark32)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]