danny0405 commented on a change in pull request #1401: [CALCITE-3280] Add
regexp_replace function (Shuming Li)
URL: https://github.com/apache/calcite/pull/1401#discussion_r317476733
##########
File path: core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java
##########
@@ -99,6 +100,40 @@
assertEquals(true, posixRegex("abcq", "[[:xdigit:]]", false));
}
+ @Test public void testRegexpReplace() {
+ assertEquals("a X c", regexpReplace("a b c", "b", "X"));
+ assertEquals("abc def X", regexpReplace("abc def ghi", "[g-z]+", "X"));
+ assertEquals("X X X", regexpReplace("abc def ghi", "[a-z]+", "X"));
+ assertEquals("X X c", regexpReplace("a b c", "a|b", "X"));
+ assertEquals("a b c", regexpReplace("a b c", "y", "X"));
+
+ assertEquals("num-num", regexpReplace("100-200", "(\\d+)", "num"));
+ assertEquals("###-###", regexpReplace("100-200", "(\\d+)", "###"));
+ assertEquals("100###200", regexpReplace("100-200", "(-)", "###"));
+
+ assertEquals("X X X", regexpReplace("abc def ghi", "[a-z]+", "X", 1));
+ assertEquals("aX X X", regexpReplace("abc def ghi", "[a-z]+", "X", 2));
+ assertEquals("abc def X", regexpReplace("abc def ghi", "[a-z]+", "X", 1,
3));
+ assertEquals("abc def GHI", regexpReplace("abc def GHI", "[a-z]+", "X", 1,
3, "c"));
+ assertEquals("abc def X", regexpReplace("abc def GHI", "[a-z]+", "X", 1,
3, "i"));
Review comment:
Can you give some tests with character "\n" "\t" replacement ? I want to
make sure we handle the Java escapes encoding correctly.
Also can you give at least one case that this function works correctly in
the sql query ? (Not invoked directly)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services