chucheng92 commented on code in PR #3705:
URL: https://github.com/apache/calcite/pull/3705#discussion_r1507110136
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java:
##########
@@ -1326,6 +1327,48 @@ public static void adjustTypeForArrayConstructor(
}
}
+ /**
+ * When the array_append and array_prepend element does not equal the array
component type
+ * make explicit casting.
+ *
+ * @param componentType derived array component type
+ * @param opBinding description of call
+ */
+ public static void adjustTypeForArrayFunctionConstructor(
+ RelDataType componentType, RelDataType elementType, SqlOperatorBinding
opBinding) {
+ if (opBinding instanceof SqlCallBinding) {
+ requireNonNull(componentType, "array component type");
+ caseTypeForArrayFunctionConstructor(componentType, elementType,
opBinding);
+ }
+ }
+
+ /**
+ * Implicit conversion of data types in array_append and array_prepend based
on the types
+ * of componentType and elementType.
+ *
+ * @param componentType derived array component type
+ * @param elementType derived array elementType type
+ * @param opBinding description of call
+ */
+ public static void caseTypeForArrayFunctionConstructor(
+ RelDataType componentType, RelDataType elementType, SqlOperatorBinding
opBinding) {
+ switch (elementType.getSqlTypeName().getName()) {
+ case "DOUBLE":
+ case "FLOAT":
+ case "BIGINT":
+ case "DECIMAL":
+ adjustTypeForMultisetConstructor3(
+ elementType, elementType, (SqlCallBinding) opBinding);
+ break;
+ default:
+ if (!componentType.getSqlTypeName().getName().equals("UNKNOWN")) {
Review Comment:
if you pass targetType, just cast array to this target type and cast element
to this targetType is enough. no need to list these types. It's vulnerable.
--
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]