caicancai commented on code in PR #3721: URL: https://github.com/apache/calcite/pull/3721#discussion_r1520938907
########## 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: @macroguo-ghy According to the official website, map_keys and map_values only allow map parameters. ![捕获](https://github.com/apache/calcite/assets/77189278/73e2ef3a-c66a-4f5a-8c61-f51ef74c9e08) I tried to execute this sql in spark-shell, but it reported an error. ![捕获](https://github.com/apache/calcite/assets/77189278/20a1bb1a-4492-473e-a9fa-55e7d42730c8) -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org