caicancai commented on code in PR #3911:
URL: https://github.com/apache/calcite/pull/3911#discussion_r1713008789


##########
core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java:
##########
@@ -2135,11 +2137,34 @@ private static class TimestampAddConvertlet implements 
SqlRexConvertlet {
       final RexNode op2;
       switch (call.operandCount()) {
       case 2:
-        // BigQuery-style 'TIMESTAMP_ADD(timestamp, interval)'
-        final SqlBasicCall operandCall = call.operand(1);
-        qualifier  = operandCall.operand(1);
-        op1 = cx.convertExpression(operandCall.operand(0));
-        op2 = cx.convertExpression(call.operand(0));
+        // Oracle-style 'ADD_MONTHS(date, integer months)'
+        if (call.getOperator() == SqlLibraryOperators.ADD_MONTHS) {
+          qualifier = new SqlIntervalQualifier(TimeUnit.MONTH, null, 
SqlParserPos.ZERO);
+          RexNode op = cx.convertExpression(call.operand(1));
+          RelDataTypeFactory typeFactory = cx.getTypeFactory();
+
+          // In Calcite, cast('1.2' as integer) is invalid.
+          // For details, see 
https://issues.apache.org/jira/browse/CALCITE-1439
+          // When trying to cast a string value to an integer type, Calcite may
+          // encounter errors if the string value cannot be successfully 
converted.
+          // To handle this, the string needs to be first converted to a 
double type,
+          // and then the double value can be converted to an integer type.
+          // Since the final target type is integer, converting the string to 
double first
+          // will not lose precision for the add_months operation.
+          if (op.getType().getSqlTypeName() == SqlTypeName.CHAR) {

Review Comment:
   I have tested all the boundary tests I think and it is compatible. This is 
my method and argument. If you have any questions, you are welcome to discuss.



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