liuyongvs commented on code in PR #3238:
URL: https://github.com/apache/calcite/pull/3238#discussion_r1222475811
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5543,6 +5543,65 @@ private static void checkIf(SqlOperatorFixture f) {
"INTEGER ARRAY NOT NULL");
}
+ /** Tests {@code MAP_FROM_ARRAYS} function from Spark. */
+ @Test void testMapFromArraysFunc() {
+ final SqlOperatorFixture f0 = fixture();
+ f0.setFor(SqlLibraryOperators.MAP_FROM_ARRAYS);
+ f0.checkFails("^map_from_arrays(array[1, 2], array['foo', 'bar'])^",
+ "No match found for function signature MAP_FROM_ARRAYS\\(<INTEGER
ARRAY>, "
+ + "<CHAR\\(3\\) ARRAY>\\)", false);
+
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+ f.checkScalar("map_from_arrays(array[1, 2], array['foo', 'bar'])",
"{1=foo, 2=bar}",
+ "(INTEGER NOT NULL, CHAR(3) NOT NULL) MAP NOT NULL");
+ f.checkScalar("map_from_arrays(array[1, 1, null], array['foo', 'bar',
'name'])",
+ "{1=bar, null=name}", "(INTEGER, CHAR(4) NOT NULL) MAP NOT NULL");
+ f.checkScalar("map_from_arrays(array(), array())",
+ "{}", "(UNKNOWN NOT NULL, UNKNOWN NOT NULL) MAP NOT NULL");
+ f.checkType("map_from_arrays(cast(null as integer array), array['foo',
'bar'])",
+ "(INTEGER NOT NULL, CHAR(3) NOT NULL) MAP");
+ f.checkNull("map_from_arrays(cast(null as integer array), array['foo',
'bar'])");
+
+ f.checkFails("^map_from_arrays(array[1, 2], 2)^",
+ "Cannot apply 'MAP_FROM_ARRAYS' to arguments of type
'MAP_FROM_ARRAYS\\(<INTEGER ARRAY>,"
+ + " <INTEGER>\\)'. Supported form\\(s\\):
'MAP_FROM_ARRAYS\\(<ARRAY>, <ARRAY>\\)'",
+ false);
+ f.checkFails("map_from_arrays(array[1, 2], array['foo'])",
+ "Illegal arguments: The length of the keys array 2 is not equal to the
length "
+ + "of the values array 1 in MAP_FROM_ARRAYS function",
+ true);
+ }
Review Comment:
no need. there is already exist
```
f.checkType("map_from_arrays(cast(null as integer array), array['foo',
'bar'])",
"(INTEGER NOT NULL, CHAR(3) NOT NULL) MAP");
f.checkNull("map_from_arrays(cast(null as integer array), array['foo',
'bar'])");
```
--
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]