gianm commented on a change in pull request #7695: Add TIMESTAMPDIFF sql support
URL: https://github.com/apache/incubator-druid/pull/7695#discussion_r285814113
 
 

 ##########
 File path: 
sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeArithmeticOperatorConversion.java
 ##########
 @@ -70,44 +71,67 @@ public DruidExpression toDruidExpression(
       throw new IAE("Expected 2 args, got %s", operands.size());
     }
 
-    final RexNode timeRexNode = operands.get(0);
-    final RexNode shiftRexNode = operands.get(1);
+    final RexNode leftRexNode = operands.get(0);
+    final RexNode rightRexNode = operands.get(1);
 
-    final DruidExpression timeExpr = 
Expressions.toDruidExpression(plannerContext, rowSignature, timeRexNode);
-    final DruidExpression shiftExpr = 
Expressions.toDruidExpression(plannerContext, rowSignature, shiftRexNode);
+    final DruidExpression leftExpr = 
Expressions.toDruidExpression(plannerContext, rowSignature, leftRexNode);
+    final DruidExpression rightExpr = 
Expressions.toDruidExpression(plannerContext, rowSignature, rightRexNode);
 
-    if (timeExpr == null || shiftExpr == null) {
+    if (leftExpr == null || rightExpr == null) {
       return null;
     }
 
-    if (shiftRexNode.getType().getFamily() == 
SqlTypeFamily.INTERVAL_YEAR_MONTH) {
+    if (rightRexNode.getType().getFamily() == 
SqlTypeFamily.INTERVAL_YEAR_MONTH) {
       // timestamp_expr { + | - } <interval_expr> (year-month interval)
       // Period is a value in months.
       return DruidExpression.fromExpression(
           DruidExpression.functionCall(
               "timestamp_shift",
-              timeExpr,
-              shiftExpr.map(
+              leftExpr,
+              rightExpr.map(
                   simpleExtraction -> null,
                   expression -> StringUtils.format("concat('P', %s, 'M')", 
expression)
               ),
               
DruidExpression.fromExpression(DruidExpression.numberLiteral(direction > 0 ? 1 
: -1))
           )
       );
-    } else if (shiftRexNode.getType().getFamily() == 
SqlTypeFamily.INTERVAL_DAY_TIME) {
+    } else if (rightRexNode.getType().getFamily() == 
SqlTypeFamily.INTERVAL_DAY_TIME) {
       // timestamp_expr { + | - } <interval_expr> (day-time interval)
       // Period is a value in milliseconds. Ignore time zone.
       return DruidExpression.fromExpression(
           StringUtils.format(
               "(%s %s %s)",
-              timeExpr.getExpression(),
+              leftExpr.getExpression(),
               direction > 0 ? "+" : "-",
-              shiftExpr.getExpression()
+              rightExpr.getExpression()
           )
       );
+    } else if ((leftRexNode.getType().getFamily() == SqlTypeFamily.TIMESTAMP ||
+        leftRexNode.getType().getFamily() == SqlTypeFamily.DATE) &&
+        (rightRexNode.getType().getFamily() == SqlTypeFamily.TIMESTAMP ||
+        rightRexNode.getType().getFamily() == SqlTypeFamily.DATE)) {
+      final String exprstr;
+      if (call.getType().getSqlTypeName() == SqlTypeName.INTERVAL_MONTH ||
 
 Review comment:
   I think this should include `INTERVAL_YEAR_MONTH` as well. Or, just check if 
the type family is `SqlTypeFamily.INTERVAL_YEAR_MONTH`. It includes all three.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to