Repository: pingcap/tispark (language: python)

Issue:
Fix escape for StringRegExpression
### What problem does this PR solve? <!--add issue link with summary if exists-->

TiSpark does not support escape in like expression before.


### What is changed and how it works?


### Check List <!--REMOVE the items that are not applicable-->

Tests <!-- At least one of them must be included. -->

 - Unit test
 - Integration test
 - Manual test (add detailed scripts or steps below)
 - No code

Code changes

 - Has exported function/method change
 - Has exported variable/fields change
 - Has interface methods change
 - Has persistent data change

Side effects

 - Possible performance regression
 - Increased code complexity
 - Breaking backward compatibility

Related changes

 - Need to cherry-pick to the release branch
 - Need to update the documentation
 - Need to update the `tidb-ansible` repository
 - Need to be included in the release note



Discussion / hints:

Fix patch:
diff --git a/tikv-client/src/main/java/com/pingcap/tikv/expression/StringRegExpression.java b/tikv-client/src/main/java/com/pingcap/tikv/expression/StringRegExpression.java
index 9672c4a406..eaeafebe42 100644
--- a/tikv-client/src/main/java/com/pingcap/tikv/expression/StringRegExpression.java
+++ b/tikv-client/src/main/java/com/pingcap/tikv/expression/StringRegExpression.java
@@ -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


Test patch:
diff --git a/core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala b/core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala
index 2b6eb22adb..2109adb532 100644
--- a/core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala
+++ b/core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala
@@ -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")