YiwenWu commented on code in PR #3830:
URL: https://github.com/apache/calcite/pull/3830#discussion_r1651069188
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7464,30 +7471,51 @@ 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));
+ }
+
+ /**
+ * Tests {@code REVERSE} function from Spark.
+ */
+ @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]",
Review Comment:
More test cases have been added in `spark.iq`
<img width="341" alt="image"
src="https://github.com/apache/calcite/assets/7956306/3477d4f7-c4fa-48bf-9b4e-bc863db92a2d">
--
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]