liuyongvs commented on code in PR #3236:
URL: https://github.com/apache/calcite/pull/3236#discussion_r1212512287
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5418,6 +5418,39 @@ private static void checkIf(SqlOperatorFixture f) {
f.checkNull("array_length(null)");
}
+ /** Tests {@code SORT_ARRAY} function from Spark. */
+ @Test void testSortArrayFunc() {
+ final SqlOperatorFixture f0 = fixture();
+ f0.setFor(SqlLibraryOperators.SORT_ARRAY);
+ f0.checkFails("^sort_array(array[null, 1, null, 2])^",
+ "No match found for function signature SORT_ARRAY\\(<INTEGER
ARRAY>\\)", false);
+ f0.checkFails("^sort_array(array[null, 1, null, 2], true)^",
+ "No match found for function signature SORT_ARRAY\\(<INTEGER ARRAY>,
<BOOLEAN>\\)", false);
+
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+ f.checkScalar("sort_array(array[2, null, 1])", "[null, 1, 2]",
+ "INTEGER ARRAY NOT NULL");
+ f.checkScalar("sort_array(array(2, null, 1), false)", "[2, 1, null]",
+ "INTEGER ARRAY NOT NULL");
+ f.checkScalar("sort_array(array[true, false, null])", "[null, false,
true]",
+ "BOOLEAN ARRAY NOT NULL");
+ f.checkScalar("sort_array(array[true, false, null], false)", "[true,
false, null]",
+ "BOOLEAN ARRAY NOT NULL");
+ f.checkScalar("sort_array(array[null])", "[null]",
+ "NULL ARRAY NOT NULL");
+ f.checkScalar("sort_array(array())", "[]",
+ "UNKNOWN NOT NULL ARRAY NOT NULL");
+ f.checkNull("sort_array(null)");
+
+ f.checkFails("^sort_array(array[2, null, 1], cast(1 as boolean))^",
+ "Argument to function 'SORT_ARRAY' must be a literal", false);
+ f.checkFails("^sort_array(array[2, null, 1], 1)^",
+ "Cannot apply 'SORT_ARRAY' to arguments of type "
+ + "'SORT_ARRAY\\(<INTEGER ARRAY>, <INTEGER>\\)'\\."
+ + " Supported form\\(s\\): 'SORT_ARRAY\\(<ARRAY>\\)'\n"
+ + "'SORT_ARRAY\\(<ARRAY>, <BOOLEAN>\\)'", false);
+ }
+
/** Tests {@code MAP_KEYS} function from Spark. */
@Test void testMapKeysFunc() {
Review Comment:
comments:
the test aligns with spark
for example
-- !query
select sort_array(array('b', 'd'), '1')
-- !query analysis
org.apache.spark.sql.AnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"1\"",
"inputType" : "\"STRING\"",
"paramIndex" : "2",
"requiredType" : "\"BOOLEAN\"",
"sqlExpr" : "\"sort_array(array(b, d), 1)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 39,
"fragment" : "sort_array(array('b', 'd'), '1')"
} ]
}
--
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]