snuyanzin commented on code in PR #3590:
URL: https://github.com/apache/calcite/pull/3590#discussion_r1435295317
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -8897,56 +8898,44 @@ private void testCurrentDateFunc(Pair<String,
Hook.Closeable> pair) {
f0.forEachLibrary(list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE), consumer);
}
- @Test void testStartsWithFunction() {
+ /** Tests the {@code STARTS_WITH} and {@code STARTSWITH} operator. */
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("startsWithAliases")
+ void testStartsWithFunction2(FunctionAlias functionAlias) {
final SqlOperatorFixture f0 = fixture();
- f0.setFor(SqlLibraryOperators.STARTS_WITH);
+ final SqlFunction function = functionAlias.function;
+ f0.setFor(function);
+ final String alias = functionAlias.alias;
final Consumer<SqlOperatorFixture> consumer = f -> {
- f.checkBoolean("starts_with('12345', '123')", true);
- f.checkBoolean("starts_with('12345', '1243')", false);
- f.checkBoolean("starts_with(x'11', x'11')", true);
- f.checkBoolean("starts_with(x'112211', x'33')", false);
- f.checkFails("^starts_with('aabbcc', x'aa')^",
- "Cannot apply 'STARTS_WITH' to arguments of type "
- + "'STARTS_WITH\\(<CHAR\\(6\\)>, <BINARY\\(1\\)>\\)'\\.
Supported "
- + "form\\(s\\): 'STARTS_WITH\\(<STRING>, <STRING>\\)'",
+ f.checkBoolean(alias + "('12345', '123')", true);
+ f.checkBoolean(alias + "('12345', '1243')", false);
+ f.checkBoolean(alias + "(x'11', x'11')", true);
+ f.checkBoolean(alias + "(x'112211', x'33')", false);
+ f.checkFails("^" + alias + "('aabbcc', x'aa')^",
+ "Cannot apply '" + function.getName() + "' to arguments of type "
+ + "'" + function.getName() + "\\(<CHAR\\(6\\)>,
<BINARY\\(1\\)>\\)'\\. Supported "
+ + "form\\(s\\): '" + function.getName() + "\\(<STRING>,
<STRING>\\)'",
false);
- f.checkNull("starts_with(null, null)");
- f.checkNull("starts_with('12345', null)");
- f.checkNull("starts_with(null, '123')");
- f.checkBoolean("starts_with('', '123')", false);
- f.checkBoolean("starts_with('', '')", true);
- f.checkNull("starts_with(x'aa', null)");
- f.checkNull("starts_with(null, x'aa')");
- f.checkBoolean("starts_with(x'1234', x'')", true);
- f.checkBoolean("starts_with(x'', x'123456')", false);
- f.checkBoolean("starts_with(x'', x'')", true);
+ f.checkNull(alias + "(null, null)");
+ f.checkNull(alias + "('12345', null)");
+ f.checkNull(alias + "(null, '123')");
+ f.checkBoolean(alias + "('', '123')", false);
+ f.checkBoolean(alias + "('', '')", true);
+ f.checkNull(alias + "(x'aa', null)");
+ f.checkNull(alias + "(null, x'aa')");
+ f.checkBoolean(alias + "(x'1234', x'')", true);
+ f.checkBoolean(alias + "(x'', x'123456')", false);
+ f.checkBoolean(alias + "(x'', x'')", true);
};
- f0.forEachLibrary(list(SqlLibrary.BIG_QUERY, SqlLibrary.POSTGRESQL),
consumer);
+ f0.forEachLibrary(list(functionAlias.libraries), consumer);
}
- /** Tests for Snowflake's {@code STARTSWITH} function. */
- @Test void testSnowflakeStartsWithFunction() {
- final SqlOperatorFixture f = fixture().withLibrary(SqlLibrary.SNOWFLAKE);
- f.setFor(SqlLibraryOperators.STARTSWITH);
- f.checkBoolean("startswith('12345', '123')", true);
- f.checkBoolean("startswith('12345', '1243')", false);
- f.checkBoolean("startswith(x'11', x'11')", true);
- f.checkBoolean("startswith(x'112211', x'33')", false);
- f.checkFails("^startswith('aabbcc', x'aa')^",
- "Cannot apply 'STARTSWITH' to arguments of type "
- + "'STARTSWITH\\(<CHAR\\(6\\)>, <BINARY\\(1\\)>\\)'\\. Supported "
- + "form\\(s\\): 'STARTSWITH\\(<STRING>, <STRING>\\)'",
- false);
- f.checkNull("startswith(null, null)");
- f.checkNull("startswith('12345', null)");
- f.checkNull("startswith(null, '123')");
- f.checkBoolean("startswith('', '123')", false);
- f.checkBoolean("startswith('', '')", true);
- f.checkNull("startswith(x'aa', null)");
- f.checkNull("startswith(null, x'aa')");
- f.checkBoolean("startswith(x'1234', x'')", true);
- f.checkBoolean("startswith(x'', x'123456')", false);
- f.checkBoolean("startswith(x'', x'')", true);
+ static Stream<FunctionAlias> startsWithAliases() {
+ return Stream.of(
+ FunctionAlias.of(
+ SqlLibraryOperators.STARTS_WITH,
+ "starts_with", SqlLibrary.BIG_QUERY, SqlLibrary.POSTGRESQL),
+ FunctionAlias.of(SqlLibraryOperators.STARTSWITH, "startswith",
SqlLibrary.SNOWFLAKE));
Review Comment:
yes, makes sense, changed it, also added similar approach to retrieve
libraries
--
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]