YiwenWu commented on code in PR #3712:
URL: https://github.com/apache/calcite/pull/3712#discussion_r1512071516


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -4928,6 +4928,37 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("regexp_contains(cast(null as varchar), cast(null as 
varchar))");
   }
 
+  @Test void testRegexpFunc() {
+    final SqlOperatorFixture f = fixture().setFor(SqlLibraryOperators.REGEXP);
+    checkRegexpFunc(f, FunctionAlias.of(SqlLibraryOperators.REGEXP));
+    checkRegexpFunc(f, FunctionAlias.of(SqlLibraryOperators.REGEXP_LIKE));
+  }
+
+  void checkRegexpFunc(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+    final SqlFunction function = functionAlias.function;
+    final String fn = function.getName();
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkBoolean(fn + "('abc def ghi', 'abc')", true);
+      f.checkBoolean(fn + "('abc def ghi', '[a-z]+')", true);
+      f.checkBoolean(fn + "('[email protected]', 
'@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+')", true);
+      f.checkBoolean(fn + "('[email protected]', '@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+')", 
false);
+      f.checkBoolean(fn + "('5556664422', '^\\d{10}$')", false);
+      f.checkBoolean(fn + "('11555666442233', '^\\d{10}$')", false);
+      f.checkBoolean(fn + "('55566644221133', '\\d{10}')", false);
+      f.checkBoolean(fn + "('55as56664as422', '\\d{10}')", false);
+      f.checkBoolean(fn + "('55as56664as422', '')", true);
+
+      f.checkQuery("select " + fn + "('abc def ghi', 'abc')");
+      f.checkQuery("select " + fn + "('[email protected]', 
'@[a-zA-Z0-9-]+\\\\.[a-zA-Z0-9-.]+')");
+      f.checkQuery("select " + fn + "('55as56664as422', '\\d{10}')");
+
+      f.checkNull(fn + "('abc def ghi', cast(null as varchar))");
+      f.checkNull(fn + "(cast(null as varchar), 'abc')");
+      f.checkNull(fn + "(cast(null as varchar), cast(null as varchar))");
+    };
+    f0.forEachLibrary(list(functionAlias.libraries), consumer);

Review Comment:
   Although `RLIKE` and `REGEXP` have the same implementation, their function 
calling methods differ, so they are divided into different tests.
   - `RLIKE`:  'str' RLIKE 'regex'
   - `REGEXP`|`REGEXP_LIKE` : fn('str',  'regex').
   
   In addition, we can abstract a method to support different Function calling 
modes, but I may think it is not necessary at present
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to