yanghua closed pull request #6659: [FLINK-10281] [table] Table function parse 
regular expression contains backslash failed
URL: https://github.com/apache/flink/pull/6659
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/ExpressionParser.scala
 
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/ExpressionParser.scala
index c0a577dccfd..3ed627a3e03 100644
--- 
a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/ExpressionParser.scala
+++ 
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/ExpressionParser.scala
@@ -186,7 +186,7 @@ object ExpressionParser extends JavaTokenParsers with 
PackratParsers {
       }
 
   lazy val singleQuoteStringLiteral: Parser[Expression] =
-    ("'" + """([^'\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*""" + "'").r 
^^ {
+    ("'" + """([^'\p{Cntrl}]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*""" + "'").r ^^ {
       str => Literal(str.substring(1, str.length - 1))
     }
 
diff --git 
a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/LiteralTest.scala
 
b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/LiteralTest.scala
index 0a60eae0e5f..8a839c0799c 100644
--- 
a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/LiteralTest.scala
+++ 
b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/LiteralTest.scala
@@ -25,6 +25,8 @@ import org.apache.flink.table.api.Types
 import org.apache.flink.table.expressions.utils.{ExpressionTestBase, Func3}
 import org.apache.flink.table.functions.ScalarFunction
 import org.apache.flink.types.Row
+
+import org.junit.Assert.assertEquals
 import org.junit.Test
 
 class LiteralTest extends ExpressionTestBase {
@@ -88,6 +90,19 @@ class LiteralTest extends ExpressionTestBase {
       s"42 and $hello")
   }
 
+  @Test
+  def testParseRegularExpression(): Unit = {
+    assertEquals(
+      "foo([\\w]+)",
+      
(ExpressionParser.parseExpression("'foothebar'.regexExtract('foo([\\w]+)', 1)"))
+        .asInstanceOf[Call].args(1).asInstanceOf[Literal].value)
+
+    assertEquals(
+      "\\d{3}",
+      (ExpressionParser.parseExpression("'123'.similar('\\d{3}')"))
+        .asInstanceOf[Call].args(1).asInstanceOf[Literal].value)
+  }
+
   def testData: Any = {
     val testData = new Row(4)
     testData.setField(0, "trUeX_value")


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to