caicancai commented on code in PR #3705:
URL: https://github.com/apache/calcite/pull/3705#discussion_r1506166899
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java:
##########
@@ -1326,6 +1327,34 @@ 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 adjustTypeForArrayAppendPrependConstructor(
+ RelDataType componentType, RelDataType elementType, SqlOperatorBinding
opBinding) {
+ if (opBinding instanceof SqlCallBinding) {
+ requireNonNull(componentType, "array component type");
+ switch (elementType.getSqlTypeName().getName()) {
Review Comment:
Why is it written like this?
Because in the case of array_append(array(int), double), the int type in the
array in the array_append function will be converted to the same double type as
elementType, for example
```scala
scala> val df = spark.sql("select array_append(array(2), cast(2 as double))")
df: org.apache.spark.sql.DataFrame = [array_append(array(2), CAST(2 AS
DOUBLE)): array<double>]scala> df.show()
+-----------------------------------------+
|array_append(array(2), CAST(2 AS DOUBLE))|
+-----------------------------------------+
| [2.0, 2.0]|
+-----------------------------------------+
```
In the case of array_append(array(int), tinyint), the tinyint type in the
array_append function is converted into the same int type as comentType.
```scala
scala> val df = spark.sql("select array_append(array(2), cast(2 as
tinyint))")
df: org.apache.spark.sql.DataFrame = [array_append(array(2), CAST(2 AS
TINYINT)): array<int>]scala> df.show()
+------------------------------------------+
|array_append(array(2), CAST(2 AS TINYINT))|
+------------------------------------------+
| [2, 2]|
+------------------------------------------+
```
--
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]