liuyongvs commented on code in PR #3262:
URL: https://github.com/apache/calcite/pull/3262#discussion_r1241051720
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5646,6 +5646,33 @@ private static void checkIf(SqlOperatorFixture f) {
+ "'SORT_ARRAY\\(<ARRAY>, <BOOLEAN>\\)'", false);
}
+ /** Tests {@code MAP_CONCAT} function from Spark. */
+ @Test void testMapConcatFunc() {
+ final SqlOperatorFixture f0 = fixture();
+ f0.setFor(SqlLibraryOperators.MAP_CONCAT);
+ f0.checkFails("^map_concat(map['foo', 1], map['bar', 2])^",
+ "No match found for function signature MAP_CONCAT\\("
+ + "<\\(CHAR\\(3\\), INTEGER\\) MAP>, <\\(CHAR\\(3\\), INTEGER\\)
MAP>\\)", false);
+
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+ f.checkScalar("map_concat(map['foo', 1], map['bar', 2])", "{foo=1, bar=2}",
+ "(CHAR(3) NOT NULL, INTEGER NOT NULL) MAP NOT NULL");
+ f.checkScalar("map_concat(map['foo', 1], map['bar', 2], map['foo', 2])",
"{foo=2, bar=2}",
+ "(CHAR(3) NOT NULL, INTEGER NOT NULL) MAP NOT NULL");
+ f.checkScalar("map_concat(map[null, 1], map[null, 2])", "{null=2}",
+ "(NULL, INTEGER NOT NULL) MAP NOT NULL");
+ f.checkScalar("map_concat(map[1, 2], map[1, null])", "{1=null}",
+ "(INTEGER NOT NULL, INTEGER) MAP NOT NULL");
+ f.checkNull("map_concat(map['foo', 1], null)");
+ f.checkType("map_concat(map['foo', 1], null)", "(CHAR(3) NOT NULL, INTEGER
NOT NULL) MAP");
+ f.checkNull("map_concat(null, map['foo', 1])");
+ f.checkType("map_concat(null, map['foo', 1])", "(CHAR(3) NOT NULL, INTEGER
NOT NULL) MAP");
+ f.checkFails("^map_concat()^", INVALID_ARGUMENTS_NUMBER, false);
Review Comment:
@MasseGuillaume good catch! spark supports zero arg.
```
@transient override lazy val dataType: MapType = {
if (children.isEmpty) {
MapType(StringType, StringType)
} else {
super.dataType.asInstanceOf[MapType]
}
}
```
and i added the test
--
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]