DonnyZone commented on a change in pull request #1862: [CALCITE-3864] Add 
Implementation for SqlLibraryOperators.CONCAT_FUNCTION in SqlFunctions and 
correct the return type inference of SqlLibraryOperators.CONCAT_FUNCTION
URL: https://github.com/apache/calcite/pull/1862#discussion_r397741431
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
 ##########
 @@ -655,6 +655,54 @@ public int size() {
         return ret;
       };
 
+
+  /**
+   * Type-inference strategy for String concatenation.
+   * For example,
+   *
+   * concat(cast('a' as varchar(2)), cast('b' as varchar(3)),cast('c' as 
varchar(2)))
+   * returns varchar(7),
+   *
+   * concat(cast('a' as varchar), cast('b' as varchar(2), cast('c' as 
varchar(2))))
+   * returns varchar,
+   *
+   * concat(cast('a' as varchar(65535)), cast('b' as varchar(2)), cast('c' as 
varchar(2)))
+   * returns varchar
+   */
+  public static final SqlReturnTypeInference MULTIVALENT_STRING_SUM_PRECISION =
+      opBinding -> {
+        boolean hasPrecisionNotSpecifiedOperand = false;
+        int typePrecision;
+        long amount = 0;
+        List<RelDataType> operandTypes = opBinding.collectOperandTypes();
+        for (RelDataType operandType: operandTypes) {
 
 Review comment:
   You can directly break the iteration when: 1) encountering 
`PRECISION_NOT_SPECIFIED`, 2) `amount` large than max precision.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to