macroguo-ghy commented on code in PR #3721:
URL: https://github.com/apache/calcite/pull/3721#discussion_r1519303692


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java:
##########
@@ -1381,6 +1399,54 @@ private static void adjustTypeForMultisetConstructor(
     }
   }
 
+  /**
+   * Adjusts the types of specified operands in a map operation to match a 
given target type.
+   * This is particularly useful in the context of SQL operations involving 
array functions,
+   * where it's necessary to ensure that all operands have consistent types 
for the operation
+   * to be valid.
+   *
+   * <p>This method operates on the assumption that the operands to be 
adjusted are part of a
+   * {@link SqlCall}, which is bound within a {@link SqlOperatorBinding}. The 
operands to be
+   * cast are identified by their indexes within the {@code operands} list of 
the {@link SqlCall}.
+   * The method performs a dynamic check to determine if an operand is a basic 
call to a map.
+   * If so, it casts each element within the map to the target type.
+   * Otherwise, it casts the operand itself to the target type.
+   *
+   * <p>Example usage: For an operation like
+   * {@code map_values(map('foo', 1, 'bar', cast(1 as double)))},
+   * if map's value targetType is double, this method would ensure that the 
value of the
+   * first map are cast to double.
+   *
+   * @param evenType the {@link RelDataType} to which the operands at even 
positions should be cast
+   * @param oddType the {@link RelDataType} to which the operands at odd 
positions should be cast
+   * @param sqlCallBinding the {@link SqlCallBinding} containing the operands 
to be adjusted
+   */
+  private static void adjustTypeForMapFunctionConstructor(
+      RelDataType evenType, RelDataType oddType, SqlCallBinding 
sqlCallBinding) {
+    SqlCall call = sqlCallBinding.getCall();

Review Comment:
   Do you assume that `call` is a map constructor? I think the `call` can be a 
column , a complex expr (like `map_concat(map('foo', 1), map('bar', 2))`)...
   
   
   If we have a table like
   ```sql
   create table t (id int, map_column map<integer, integer>);
   ```
   
   when we execute a query like
   ```sql
   select map_keys(map_column) from t;
   ```
   
   I think your code will throw an exeception. Can you add more tests for your 
PR? 
   



-- 
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]

Reply via email to