-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
[SPARK-34727][SQL] Fix discrepancy in casting float to timestamp #31819
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gengliangwang
approved these changes
Mar 12, 2021
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
yaooqinn
approved these changes
Mar 12, 2021
HyukjinKwon
approved these changes
Mar 14, 2021
Merged to master. |
HyukjinKwon
pushed a commit
that referenced
this pull request
Mar 16, 2021
### What changes were proposed in this pull request? In non-ANSI mode, casting float to timestamp has different implementation for codegen on and off. Codegen on: 1. Multiply float input by MICROS_PER_SECOND 2. Cast resulting float value to long Codegen off: 1. CAST float input to double input 2. Multiply double input by MICROS_PER_SECOND 3. Cast resulting double value to long In the PR, I propose to align to non-codegen code, and cast input float to double in codegen. ### Why are the changes needed? This fixes the issue which is demonstrated by the code: ```sql spark-sql> CREATE TEMP VIEW v1 AS SELECT 16777215.0f AS f; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:14.951424 ``` The result from the cached view **1970-07-14 07:20:14.951424** is different from un-cached view **1970-07-14 07:20:15**. ### Does this PR introduce _any_ user-facing change? Yes. After the changes, the example above outputs the same timestamp for the cached view: ```sql spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 ``` ### How was this patch tested? By running new test: ``` $ build/sbt "test:testOnly *CastSuite" ``` Closes #31819 from MaxGekk/fix-float-to-timestamp. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
I also merged this to branch-3.1 too |
flyrain
pushed a commit
to flyrain/spark
that referenced
this pull request
Sep 21, 2021
### What changes were proposed in this pull request? In non-ANSI mode, casting float to timestamp has different implementation for codegen on and off. Codegen on: 1. Multiply float input by MICROS_PER_SECOND 2. Cast resulting float value to long Codegen off: 1. CAST float input to double input 2. Multiply double input by MICROS_PER_SECOND 3. Cast resulting double value to long In the PR, I propose to align to non-codegen code, and cast input float to double in codegen. ### Why are the changes needed? This fixes the issue which is demonstrated by the code: ```sql spark-sql> CREATE TEMP VIEW v1 AS SELECT 16777215.0f AS f; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:14.951424 ``` The result from the cached view **1970-07-14 07:20:14.951424** is different from un-cached view **1970-07-14 07:20:15**. ### Does this PR introduce _any_ user-facing change? Yes. After the changes, the example above outputs the same timestamp for the cached view: ```sql spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 ``` ### How was this patch tested? By running new test: ``` $ build/sbt "test:testOnly *CastSuite" ``` Closes apache#31819 from MaxGekk/fix-float-to-timestamp. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
fishcus
pushed a commit
to fishcus/spark
that referenced
this pull request
Jan 12, 2022
### What changes were proposed in this pull request? In non-ANSI mode, casting float to timestamp has different implementation for codegen on and off. Codegen on: 1. Multiply float input by MICROS_PER_SECOND 2. Cast resulting float value to long Codegen off: 1. CAST float input to double input 2. Multiply double input by MICROS_PER_SECOND 3. Cast resulting double value to long In the PR, I propose to align to non-codegen code, and cast input float to double in codegen. ### Why are the changes needed? This fixes the issue which is demonstrated by the code: ```sql spark-sql> CREATE TEMP VIEW v1 AS SELECT 16777215.0f AS f; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:14.951424 ``` The result from the cached view **1970-07-14 07:20:14.951424** is different from un-cached view **1970-07-14 07:20:15**. ### Does this PR introduce _any_ user-facing change? Yes. After the changes, the example above outputs the same timestamp for the cached view: ```sql spark-sql> CACHE TABLE v1; spark-sql> SELECT * FROM v1; 1.6777215E7 spark-sql> SELECT CAST(f AS TIMESTAMP) FROM v1; 1970-07-14 07:20:15 ``` ### How was this patch tested? By running new test: ``` $ build/sbt "test:testOnly *CastSuite" ``` Closes apache#31819 from MaxGekk/fix-float-to-timestamp. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In non-ANSI mode, casting float to timestamp has different implementation for codegen on and off.
Codegen on:
Codegen off:
In the PR, I propose to align to non-codegen code, and cast input float to double in codegen.
Why are the changes needed?
This fixes the issue which is demonstrated by the code:
The result from the cached view 1970-07-14 07:20:14.951424 is different from un-cached view 1970-07-14 07:20:15.
Does this PR introduce any user-facing change?
Yes. After the changes, the example above outputs the same timestamp for the cached view:
How was this patch tested?
By running new test: