Skip to content

Commit

Permalink
For custom escape character, provide user with specific info message
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithjay committed May 28, 2024
1 parent 03d8bb2 commit bfac08a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
33 changes: 19 additions & 14 deletions spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -981,23 +981,28 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
None
}

case Like(left, right, escapeChar) if escapeChar == '\\' =>
// 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,12 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
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)
val queryDefaultEscape = sql("select id from names where name like '%\\_%'")
checkAnswer(queryDefaultEscape, Row(2) :: Row(3) :: Nil)

val queryCustomEscape = sql("select id from names where name like '%$_%' escape '$'")
checkAnswer(queryCustomEscape, Row(2) :: Row(3) :: Nil)

}
}

Expand Down

0 comments on commit bfac08a

Please sign in to comment.