mihaibudiu commented on code in PR #5042:
URL: https://github.com/apache/calcite/pull/5042#discussion_r3465002755
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -9281,9 +9284,10 @@ void checkArrayReverseFunc(SqlOperatorFixture f0,
SqlFunction function,
f1.checkType("map_concat(cast(null as map<varchar, int>), map['foo', 1])",
"(VARCHAR NOT NULL, INTEGER) MAP");
- f1.checkFails("^map_concat(map('foo', 1), null)^",
- "Function 'MAP_CONCAT' should all be of type map, "
- + "but it is 'NULL'", false);
+ f1.checkNull("map_concat(map('foo', 1), null)");
Review Comment:
Can you also add a test like MAP_CONCAT(MAP_CONCAT(), MAP[1, 2]). I think
this should work, and the result should be MAP<INT, INT>.
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1763,23 +1763,32 @@ private static RelDataType
deriveTypeArraysZip(SqlOperatorBinding opBinding) {
OperandTypes.ARRAY.or(OperandTypes.ARRAY_BOOLEAN_LITERAL));
private static RelDataType deriveTypeMapConcat(SqlOperatorBinding opBinding)
{
+ final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
if (opBinding.getOperandCount() == 0) {
- final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
- final RelDataType type = typeFactory.createSqlType(SqlTypeName.VARCHAR);
- requireNonNull(type, "type");
+ final RelDataType type = typeFactory.createSqlType(SqlTypeName.ANY);
return SqlTypeUtil.createMapType(typeFactory, type, type, true);
- } else {
- final List<RelDataType> operandTypes = opBinding.collectOperandTypes();
- for (RelDataType operandType : operandTypes) {
- if (!SqlTypeUtil.isMap(operandType)) {
- throw opBinding.newError(
- RESOURCE.typesShouldAllBeMap(
- opBinding.getOperator().getName(),
- operandType.getFullTypeString()));
- }
+ }
+ final List<RelDataType> operandTypes = opBinding.collectOperandTypes();
+ final List<RelDataType> mapTypes = new ArrayList<>();
+ boolean hasNull = false;
+ for (RelDataType operandType : operandTypes) {
+ if (operandType.getSqlTypeName() == SqlTypeName.NULL) {
+ hasNull = true;
+ } else if (SqlTypeUtil.isMap(operandType)) {
+ mapTypes.add(operandType);
+ } else {
+ throw opBinding.newError(
+ RESOURCE.typesShouldAllBeMap(
+ opBinding.getOperator().getName(),
+ operandType.getFullTypeString()));
}
- return
requireNonNull(opBinding.getTypeFactory().leastRestrictive(operandTypes));
}
+ if (mapTypes.isEmpty() || hasNull) {
+ // All arguments are NULL literals, or at least one argument is a NULL
literal;
Review Comment:
at least one null argument.
--
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]