Uh oh!
There was an error while loading. Please reload this page.
[BEAM-9641] Support ZetaSQL DATE type as a Beam LogicalType - #11272
Conversation
3003dbb to
cca562dCompareTheNeuralBit
commented
Apr 20, 2020
What do you think about going ahead and defining the date logical type in cc: @reuvenlax |
robinyqiu
commented
Apr 28, 2020
Done. Thanks for the suggestion. I made the |
There was a problem hiding this comment.
nit: Can you clean up the style and call equals on the constant instead of logicalId (which could be null).
There was a problem hiding this comment.
what about using a switch statement? Is there any style guidance on using switch on a String in java?
There was a problem hiding this comment.
Done. I hope I could use a switch statement here, but unfortunately there is no constant IDENTIFIER defined in the LogicalType class. (I could add it to each concrete SQL logical type I create, but I don't think that is a good style.)
There was a problem hiding this comment.
nit: Call equals on constant to avoid null issues.
There was a problem hiding this comment.
nit: This order of equals is awesome!
There was a problem hiding this comment.
I think it is worth documenting that the Long is an offset from an epoch (and what that epoch is).
There was a problem hiding this comment.
If I'm reading the correctly, LocalDate is the in memory type (a struct) and Long is the wire format (an offset from epoch)? This conversion could be quite expensive. It appears the Calc nodes both take an offset in this case, when we start to think about performance we might need to change the in memory type to be offset based.
There was a problem hiding this comment.
(If changing the in memory type is going to be difficult in the future, consider doing that now.)
There was a problem hiding this comment.
That is unfortunate... but what in-memory type should we use instead? joda.time.LocalDate uses a millisecond long, do we want to add another joda dependency?
We could access the base type (wire format type) directly in SQL with Row#getBaseValue, but unfortunately Rows store logical types as the input type (in memory format type), so that wouldn't actually avoid a conversion.
There was a problem hiding this comment.
I guess java.sql.Date is another option for a java type backed by millis.
There was a problem hiding this comment.
We should consider not using a JVM, it adds performance overhead too. 🤓
I'm reasonably convinced the wire format is good and the conversion here is lossless, so if there isn't a easy drop-in replacement leave this as is.
There was a problem hiding this comment.
I think Andrew is basically suggesting using a PassThroughLogicalType<Long> as a logical type for DATE. I think we could definitely consider this if performance becomes a problem in the future. (It's not easy to change the in-memory type for Date after it is made public, but we can easily define a new SqlDate.) For now I think we can leave it as is. It's more human readable (e.g. writing tests for DATE type in spec tests is simpler).
apilloud
commented
Apr 30, 2020
Oops, forgot to include in my comments: ZetaSQL's range is much smaller than the underlying type, can you add a test or two for that? How do out of range values fail? (Also worth asking, do we need any special treatment for boundary conditions ( |
robinyqiu
commented
May 6, 2020
Ah, just realized that the previous comments were not sent out. |
robinyqiu
commented
May 6, 2020
Could you help trigger the tests again? For the comment on range: Thanks for pointing it out. I overlooked this problem. I would like to create a separate PR to address it, along with range testing for other types as well. |
apilloud
commented
May 6, 2020
retest this please |
robinyqiu
commented
May 6, 2020
The failing test |
apilloud
commented
May 7, 2020
Run Java PreCommit |
apilloud
commented
May 7, 2020
Run SQL Postcommit |
robinyqiu
commented
May 14, 2020
Rebased against master. Please run precommit tests again. |
apilloud
commented
May 14, 2020
retest this please |
1 similar comment
apilloud
commented
May 14, 2020
retest this please |
robinyqiu
commented
May 15, 2020
Java PreCommit failed due to a build failure. Please help run again. |
TheNeuralBit
commented
May 15, 2020
Run Java PreCommit |
2 similar comments
TheNeuralBit
commented
May 15, 2020
Run Java PreCommit |
TheNeuralBit
commented
May 18, 2020
Run Java PreCommit |
Something just occurred to me - are there any tests that use the DATE Type in an aggregation (e.g. MAX)? I'd think that would run into the same issue I have in #11456 (processing logical types using their representation) |
apilloud
commented
May 21, 2020
Interesting question. You should probably add a test for JOIN as well, which will have a similar class of problems. |
robinyqiu
commented
May 21, 2020
No. Thanks for bringing this up. I think it is likely to run into the problem. |
This PR adds support of all ZetaSQL (BigQuery Standard SQL) DATE functions to BeamSQL:
r: @apilloud
cc: @TheNeuralBit@kennknowles
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
R: @username).[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
Post-Commit Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.