juntaozhang commented on code in PR #4353:
URL: https://github.com/apache/calcite/pull/4353#discussion_r2069727238


##########
core/src/main/java/org/apache/calcite/sql/SqlOperator.java:
##########
@@ -556,10 +556,28 @@ protected void preValidateCall(SqlValidator validator,
    * {@link SqlCall})
    * @return inferred return type
    */
-  public RelDataType inferReturnType(
-      SqlOperatorBinding opBinding) {
+  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {

Review Comment:
   I'm also a little unsure and need your further guidance:
   here is our main change, in this case there are some duplicated code, 
returnTypeInference and operandTypeInference need change private to protected.
   
   ```
     public RelDataType inferReturnType(
         SqlOperatorBinding opBinding) {
       if (returnTypeInference != null) {
         RelDataType returnType = 
returnTypeInference.inferReturnType(opBinding);
         //=====================
         // here is our main logic, in this case there are some duplicated 
code, returnTypeInference and operandTypeInference need change private to 
protected
        if (opBinding instanceof SqlCallBinding) {
           SqlCallBinding callBinding = (SqlCallBinding) opBinding;
           if (callBinding.isTypeCoercionEnabled()) {
             List<RelDataType> argTypes = new ArrayList<>();
             for (SqlNode operand : callBinding.operands()) {
               RelDataType type = SqlTypeUtil.deriveType(callBinding, operand);
               argTypes.add(type);
             }
             TypeCoercion typeCoercion = 
callBinding.getValidator().getTypeCoercion();
             RelDataType commonType = typeCoercion.getWiderTypeFor(argTypes, 
true);
             if (null != commonType) {
               boolean coerced = typeCoercion.caseWhenCoercion(callBinding);
               if (coerced) {
                 return SqlTypeUtil.deriveType(callBinding);
               }
             }
             throw 
callBinding.newValidationError(RESOURCE.illegalMixingOfTypes());
           }
         }
         //============================
         if (operandTypeInference != null
             && opBinding instanceof SqlCallBinding
             && this instanceof SqlFunction) {
           final SqlCallBinding callBinding = (SqlCallBinding) opBinding;
           final List<RelDataType> operandTypes = 
opBinding.collectOperandTypes();
           if (operandTypes.stream().anyMatch(t -> t.getSqlTypeName() == 
SqlTypeName.ANY)) {
             final RelDataType[] operandTypes2 = operandTypes.toArray(new 
RelDataType[0]);
             operandTypeInference.inferOperandTypes(callBinding, returnType, 
operandTypes2);
             ((SqlValidatorImpl) callBinding.getValidator())
                 .callToOperandTypesMap
                 .put(callBinding.getCall(), 
ImmutableList.copyOf(operandTypes2));
           }
         }
   
         return returnType;
       }
   ```



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