vvysotskyi commented on a change in pull request #1528: DRILL-3610: Add 
TIMESTAMPADD and TIMESTAMPDIFF functions
URL: https://github.com/apache/drill/pull/1528#discussion_r232337818
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/TypeInferenceUtils.java
 ##########
 @@ -555,6 +557,60 @@ public RelDataType inferReturnType(SqlOperatorBinding 
opBinding) {
     }
   }
 
+  private static class DrillTimestampAddTypeInference implements 
SqlReturnTypeInference {
+    private static final SqlReturnTypeInference INSTANCE = new 
DrillTimestampAddTypeInference();
+
+    @Override
+    public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
+      RelDataTypeFactory factory = opBinding.getTypeFactory();
+      // operands count ond order is checked at parsing stage
+      RelDataType inputType = opBinding.getOperandType(2);
+      boolean isNullable = inputType.isNullable() || 
opBinding.getOperandType(1).isNullable();
+
+      SqlTypeName inputTypeName = inputType.getSqlTypeName();
+
+      TimeUnit qualifier = ((SqlLiteral) ((SqlCallBinding) 
opBinding).operand(0)).getValueAs(TimeUnit.class);
+
+      SqlTypeName sqlTypeName;
+
+      // follow up with type inference of reduced expression
+      switch (qualifier) {
+        case DAY:
+        case WEEK:
+        case MONTH:
+        case QUARTER:
+        case YEAR:
+        case NANOSECOND:  // NANOSECOND is not supported by Calcite 
SqlTimestampAddFunction.
+                          // Once it is fixed, NANOSECOND should be moved to 
the group below.
+          sqlTypeName = inputTypeName;
+          break;
+        case MICROSECOND:
+        case MILLISECOND:
+          // for MICROSECOND and MILLISECOND should be specified precision
 
 Review comment:
   Thanks, replaced.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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