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


##########
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:
   It is necessary. And it's easy to combine all three. 
`BinaryOperator<String>`. For rlike, pass `(a, b) -> a + " RLIKE " b`; for 
REGEXP, pass `(a, b) -> "REGEXP(" + a + ", " + b + ")".



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