tanclary commented on code in PR #3079:
URL: https://github.com/apache/calcite/pull/3079#discussion_r1116338764


##########
core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java:
##########
@@ -2027,13 +2050,38 @@ private static class TimestampDiffConvertlet implements 
SqlRexConvertlet {
                 qualifier.getParserPosition());
         break;
       }
-      final RelDataType intervalType =
-          cx.getTypeFactory().createTypeWithNullability(
-              cx.getTypeFactory().createSqlIntervalType(qualifier),
-              op1.getType().isNullable() || op2.getType().isNullable());
-      final RexCall rexCall = (RexCall) rexBuilder.makeCall(
-          intervalType, SqlStdOperatorTable.MINUS_DATE,
-          ImmutableList.of(op2, op1));
+
+      RelDataType intervalType;
+      RexCall rexCall;
+      /* This additional logic handles the differing definitions of 'WEEK' 
between BigQuery
+      *  and Calcite. BigQuery considers Sunday as the start of the week, so 
two dates whose
+      *  day difference is <7 may have a week difference of 1 if they occur on 
two different

Review Comment:
   I will update the comment. What I was trying to say is, Calcite currently 
computes the number of weeks between two dates by dividing the number of days 
between them by 7 (and flooring the result). BigQuery however essentially 
checks how many Sundays are between the two dates, which in certain cases 
causes a discrepancy.



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