New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-5757] BigQuery DATE_TRUNC return type should be ARG0 and TIMESTAMP_TRUNC/DATETIME_TRUNC should return TIMESTAMP for DATE/TIMESTAMPs and TIMESTAMP_LTZ for TIMESTAMP_LTZ #3248
Conversation
34723b2
to
e6f0e3f
Compare
DATE_TRUNC(DATETIME "2008-12-25 15:30:00", MONTH) AS datetime_result; | ||
timestamp_result TIMESTAMP_WITH_LOCAL_TIME_ZONE NOT NULL | ||
datetime_result TIMESTAMP NOT NULL | ||
!type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat, I didnt know about !type
in quidem tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah super useful!!
8a5cf83
to
cf7f71b
Compare
* Type-inference strategy that returns the type of the first operand, | ||
* unless it is a DATE, in which case the return type is TIMESTAMP. | ||
*/ | ||
public static final SqlReturnTypeInference ARG0_EXCEPT_DATE = opBinding -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to add a comment referencing [CALCITE-5757] to remind that this is for BQ typing behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, let me know if it's clear enough
final RexBuilder rexBuilder = cx.getRexBuilder(); | ||
RexNode op1 = cx.convertExpression(call.operand(0)); | ||
RexNode op2 = cx.convertExpression(call.operand(1)); | ||
if (op1.getType().getSqlTypeName() == SqlTypeName.DATE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also a comment here discussion why DATE is handled separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
e6f0e3f
to
a6769a9
Compare
The commit message is currently as follows:
That contains 'correct', which is a synonym for 'fix', and is superfluous. Just state the desired behavior. Would the following be better?
|
After you've removed & inlined |
…ESTAMP_TRUNC/DATETIME_TRUNC should return TIMESTAMP for DATE/TIMESTAMPs and TIMESTAMP_LTZ for TIMESTAMP_LTZ
a6769a9
to
7a2af29
Compare
@julianhyde I updated it, also, DATE_TRUNC /should/ return ARG0 and not DATE (in case you wonder why commit message differs from your suggestion) |
Kudos, SonarCloud Quality Gate passed! |
BigQuery TRUNC functions follow the return type behavior described in CALCITE-5757. This PR adjusts the return type for those functions such that it matches the described behavior.
Notable changes include converting a
DATE
to aTIMESTAMP
for theTIMESTAMP_TRUNC
andDATETIME_TRUNC
functions. It also ensures thatDATE_TRUNC
return type is equivalent to the operand type (akaReturnTypes.ARG0
).Prior to this PR, discrepancies included
DATETIME_TRUNC
incorrectly returning aTIMESTAMP_LTZ
if given aTIMESTAMP
argument andDATE_TRUNC
having aDATE
return type even if the argument was aTIMESTAMP
orTIMESTAMP_LTZ
.@julianhyde I opted to just include the TRUNC functions in this PR to keep the review and scope fairly easy (hopefully).