Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fallback to Spark for LIKE with custom escape character #478

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == '\\' =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tihnk it would be better to have a check for escape char within the match and then call withInfo if the escape char is not \\ so that we can give the user a specific error such as escape char not supported otherwise I think we fall through to the catchall logic and the user will get an error like is not supported, which could be confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andygrove I have made this change in bfac08a. Please review.

// 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
Loading