[BEAM-8057] Support ZetaSQL DOUBLE +INF, -INF and NAN - #12292
Conversation
robinyqiu
left a comment
There was a problem hiding this comment.
It's great to see this long-standing issue fixed. Thank you for working on this, Zijie. Please also link to your doc from here after you finish that. Left some comments to further simplify the code.
7e8f3ac to
c1b4f88
Compare
apilloud
left a comment
There was a problem hiding this comment.
LGTM.
I love this approach! It is very clean and keeps most doubles as normal Calcite literals.
Great. Thanks a lot. |
|
I am testing this internally, after the tests pass I will merge it. |
Thanks. |
|
Actually this change unveils a data corruption bug (produces wrong result). It is related to NaN comparison (=, !=, >, >=, <, and <=). For example, if you have a query like the expected result is I dug into this a bit and found it is because Calcite internally does simplification to comparison operations (https://github.com/apache/calcite/blob/3fb68f6c22a7bcbc4cb1fff114bc911b1e31c4de/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L336-L351). So the above expression will be simplified to (you can print the sql query in The simplification is triggered because the 2 operands of One way I can think of to fix this, without affecting other code path, is that we can generate a random double and convert it to |
|
Instead of adding an argument with a random number, make isDeterministic() false: https://github.com/apache/calcite/blob/551e3f5a182a48e20586e40c378224bb63e4bfb3/core/src/main/java/org/apache/calcite/sql/SqlOperator.java#L940 |
|
(There are a few other config parameters in that file, one should stop the optimizer from affecting |
|
Yeah that is definitely a better approach. However checking of So how about we use the old approach for now, and create a JIRA for updating to the new approach after we update to 1.23? (The JIRA should be marked blocked by: https://issues.apache.org/jira/browse/BEAM-9379 (we should change 1.22 to 1.23) |
|
Oh the last comment was replying to your first comment. If other config parameters can do the work we should definitely do that. @ZijieSong946 Could you investigate this a bit next week? |
Acknowledged. |
Got it. I would figure out a possible solution to handle that issue. |
|
I dug into this problem and figured out that we should avoid hitting into the operation simplification branch here (https://github.com/apache/calcite/blob/3530daaa8cad43aad6845b6c79e4bc1ca0e72f5f/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L325). |
|
Thank you Zijie for the investigation. The temporary solution LGTM. I assigned the JIRA to myself because as discussed in meeting I will be updating the vendored Calcite version. This PR failed building because I made some changes to some functions your code depends on. You will need to rebase against master and fix it. |
585939d to
0bff5fc
Compare
Rebased. |
|
Thank you! I will merge it now (tested internally). |
|
The detailed designs for overcoming the inconsistency between Calcite and ZetaSQL DOUBLE +inf/-inf/NaN literal representation: |
This PR supports
+inf,-infandNaNfor ZetaSQL DOUBLE type.ZetaSqlDialectSpecTest.testEQ2passed.IS_INF()andIS_NAN()are supported for ZetaSQL now.r: @apilloud @robinyqiu
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.