Skip to content

Commit

Permalink
Fix escape for StringRegExpression (#2775) (#2776)
Browse files Browse the repository at this point in the history
* fix

* fmt

* fix

---------

Co-authored-by: shiyuhang <[email protected]>
  • Loading branch information
ti-chi-bot and shiyuhang0 committed Mar 28, 2024
1 parent 53f79a7 commit ce46f0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ import org.apache.spark.sql.functions.{col, sum}

class IssueTestSuite extends BaseTiSparkTest {

test("test like escape") {
val dbTable = "tispark_test.like_escape"
tidbStmt.execute(s"drop table if exists $dbTable")
tidbStmt.execute(s"CREATE TABLE $dbTable (`name` varchar(64) NOT NULL)")
tidbStmt.execute(s"insert into $dbTable values('ab%H')")
val df = spark.sql(s"select count(*) from $dbTable where name like '%\\%H%'")
assert(df.collect().head.get(0) == 1)

}

test("test tiflash overflow in unsigned bigint") {
if (!enableTiFlashTest) {
cancel("tiflash test not enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ public TypedKey getTypedLiteral(int prefixLength) {

@Override
public List<Expression> getChildren() {
// For LIKE statement, an extra ESCAPE parameter is required as the third parameter for
// ScalarFunc.
// However in Spark ESCAPE is not supported so we simply set this value to zero.
return ImmutableList.of(left, reg, Constant.create(0, IntegerType.BIGINT));
// LIKE statement use '\' as escape character because Spark use it as escape character too.
return ImmutableList.of(left, reg, Constant.create(92, IntegerType.BIGINT));
}

@Override
Expand Down

0 comments on commit ce46f0c

Please sign in to comment.