XuQianJin-Stars commented on code in PR #3830:
URL: https://github.com/apache/calcite/pull/3830#discussion_r1663875977
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7464,30 +7471,57 @@ void checkRegexpExtract(SqlOperatorFixture f0,
FunctionAlias functionAlias) {
/** Tests {@code ARRAY_REVERSE} function from BigQuery. */
@Test void testArrayReverseFunc() {
+ final SqlFunction func = SqlLibraryOperators.ARRAY_REVERSE;
final SqlOperatorFixture f0 = fixture();
- f0.setFor(SqlLibraryOperators.ARRAY_REVERSE);
+ f0.setFor(func);
f0.checkFails("^array_reverse(array[1])^",
"No match found for function signature ARRAY_REVERSE\\(<INTEGER
ARRAY>\\)", false);
- final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.BIG_QUERY);
- f.checkScalar("array_reverse(array[1])", "[1]",
- "INTEGER NOT NULL ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[1, 2])", "[2, 1]",
- "INTEGER NOT NULL ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[null, 1])", "[1, null]",
- "INTEGER ARRAY NOT NULL");
- // elements cast
- f.checkScalar("array_reverse(array[cast(1 as tinyint), 2])", "[2, 1]",
- "INTEGER NOT NULL ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[null, 1, cast(2 as tinyint)])", "[2, 1,
null]",
- "INTEGER ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[cast(1 as bigint), 2])", "[2, 1]",
- "BIGINT NOT NULL ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[null, 1, cast(2 as bigint)])", "[2, 1,
null]",
- "BIGINT ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[cast(1 as decimal), 2])", "[2, 1]",
- "DECIMAL(19, 0) NOT NULL ARRAY NOT NULL");
- f.checkScalar("array_reverse(array[null, 1, cast(2 as decimal)])", "[2, 1,
null]",
- "DECIMAL(19, 0) ARRAY NOT NULL");
+ checkArrayReverseFunc(f0, func, list(SqlLibrary.BIG_QUERY));
+ }
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6445">[CALCITE-6445]
+ * Add REVERSE function (enabled in Spark library)</a>. */
+ @Test void testReverseSparkFunc() {
+ final SqlFunction func = SqlLibraryOperators.REVERSE_SPARK;
+ final SqlOperatorFixture f0 = fixture();
+ f0.setFor(func);
+ Iterable<SqlLibrary> libraries = list(SqlLibrary.SPARK);
+ checkArrayReverseFunc(f0, func, libraries);
+ checReverseFunc(f0, func, libraries);
+ }
+
+ void checkArrayReverseFunc(SqlOperatorFixture f0, SqlFunction function,
+ Iterable<? extends SqlLibrary> libraries) {
+ final String fn = function.getName();
+ final Consumer<SqlOperatorFixture> consumer = f -> {
+ f.checkScalar(fn + "(array[1])", "[1]",
+ "INTEGER NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[1, 2])", "[2, 1]",
+ "INTEGER NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[null, 1])", "[1, null]",
+ "INTEGER ARRAY NOT NULL");
+ // elements cast
+ f.checkScalar(fn + "(array[cast(1 as tinyint), 2])", "[2, 1]",
+ "INTEGER NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[null, 1, cast(2 as tinyint)])", "[2, 1,
null]",
+ "INTEGER ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[cast(1 as bigint), 2])", "[2, 1]",
+ "BIGINT NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[null, 1, cast(2 as bigint)])", "[2, 1, null]",
+ "BIGINT ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[cast(1 as decimal), 2])", "[2, 1]",
+ "DECIMAL(19, 0) NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[null, 1, cast(2 as decimal)])", "[2, 1,
null]",
+ "DECIMAL(19, 0) ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[CAST(2.1 as decimal(17)),
2.1111111111111119])",
+ "[2.1111111111111119, 2.1]", "DECIMAL(19, 2) NOT NULL ARRAY NOT
NULL");
+ f.checkScalar(fn + "(array[CAST(2.1 as double), 2.1111111111111119])",
+ "[2.111111111111112, 2.1]", "DOUBLE NOT NULL ARRAY NOT NULL");
+ f.checkScalar(fn + "(array[null])", "[null]", "NULL ARRAY NOT NULL");
+ f.checkNull(fn + "(cast(null as integer array))");
Review Comment:
Add a test Case for Reversing a String with Special Characters:
Purpose: To verify the functionality of the string reversal for strings
containing special characters.
Input: 'a!b@c#'
Expected Output: '#c@b!a'
This test case aims to ensure that the `REVERSE` function can correctly
reverse the order of characters in a string, taking into account any special or
non-alphanumeric characters that may be 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]