chucheng92 commented on code in PR #3705:
URL: https://github.com/apache/calcite/pull/3705#discussion_r1514073661
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1181,13 +1181,26 @@ private static RelDataType
arrayAppendPrependReturnType(SqlOperatorBinding opBin
final RelDataType arrayType = opBinding.collectOperandTypes().get(0);
final RelDataType componentType = arrayType.getComponentType();
final RelDataType elementType = opBinding.collectOperandTypes().get(1);
+ requireNonNull(componentType, () -> "componentType of " + arrayType);
+
RelDataType type =
opBinding.getTypeFactory().leastRestrictive(
ImmutableList.of(componentType, elementType));
+ requireNonNull(type, "inferred array element type");
+
if (elementType.isNullable()) {
type = opBinding.getTypeFactory().createTypeWithNullability(type, true);
}
- requireNonNull(type, "inferred array element type");
+
+ // make explicit CAST for array elements and inserted element to the
biggest type
+ // if array component type not equals to inserted element type
+ if (!componentType.equalsSansFieldNames(elementType)) {
+ // 0, 1 is the operand index to be CAST
Review Comment:
here can be optimized. If `arrayComponentType` or inserted element type it
is already the same as `leastRestrictiveType`, there is no need to cast it.
--
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]