-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20786][SQL][Backport-2.2]Improve ceil and floor handle the value which is not expected #18057
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
Closed
Closed
[SPARK-20786][SQL][Backport-2.2]Improve ceil and floor handle the value which is not expected #18057
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
49 changes: 49 additions & 0 deletions
49
sql/core/src/test/resources/sql-tests/inputs/operators.sql
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| -- unary minus and plus | ||
| select -100; | ||
| select +230; | ||
| select -5.2; | ||
| select +6.8e0; | ||
| select -key, +key from testdata where key = 2; | ||
| select -(key + 1), - key + 1, +(key + 5) from testdata where key = 1; | ||
| select -max(key), +max(key) from testdata; | ||
| select - (-10); | ||
| select + (-key) from testdata where key = 32; | ||
| select - (+max(key)) from testdata; | ||
| select - - 3; | ||
| select - + 20; | ||
| select + + 100; | ||
| select - - max(key) from testdata; | ||
| select + - key from testdata where key = 33; | ||
|
|
||
| -- div | ||
| select 5 / 2; | ||
| select 5 / 0; | ||
| select 5 / null; | ||
| select null / 5; | ||
| select 5 div 2; | ||
| select 5 div 0; | ||
| select 5 div null; | ||
| select null div 5; | ||
|
|
||
| -- other arithmetics | ||
| select 1 + 2; | ||
| select 1 - 2; | ||
| select 2 * 5; | ||
| select 5 % 3; | ||
| select pmod(-7, 3); | ||
|
|
||
|
|
||
| -- ceil and ceiling | ||
| select ceiling(0); | ||
| select ceiling(1); | ||
| select ceil(1234567890123456); | ||
| select ceil(12345678901234567); | ||
| select ceiling(1234567890123456); | ||
| select ceiling(12345678901234567); | ||
|
|
||
| -- floor | ||
| select floor(0); | ||
| select floor(1); | ||
| select floor(1234567890123456); | ||
| select floor(12345678901234567); |
306 changes: 306 additions & 0 deletions
306
sql/core/src/test/resources/sql-tests/results/operators.sql.out
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,306 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 37 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| select -100 | ||
| -- !query 0 schema | ||
| struct<-100:int> | ||
| -- !query 0 output | ||
| -100 | ||
|
|
||
|
|
||
| -- !query 1 | ||
| select +230 | ||
| -- !query 1 schema | ||
| struct<230:int> | ||
| -- !query 1 output | ||
| 230 | ||
|
|
||
|
|
||
| -- !query 2 | ||
| select -5.2 | ||
| -- !query 2 schema | ||
| struct<-5.2:decimal(2,1)> | ||
| -- !query 2 output | ||
| -5.2 | ||
|
|
||
|
|
||
| -- !query 3 | ||
| select +6.8e0 | ||
| -- !query 3 schema | ||
| struct<6.8:decimal(2,1)> | ||
| -- !query 3 output | ||
| 6.8 | ||
|
|
||
|
|
||
| -- !query 4 | ||
| select -key, +key from testdata where key = 2 | ||
| -- !query 4 schema | ||
| struct<(- key):int,key:int> | ||
| -- !query 4 output | ||
| -2 2 | ||
|
|
||
|
|
||
| -- !query 5 | ||
| select -(key + 1), - key + 1, +(key + 5) from testdata where key = 1 | ||
| -- !query 5 schema | ||
| struct<(- (key + 1)):int,((- key) + 1):int,(key + 5):int> | ||
| -- !query 5 output | ||
| -2 0 6 | ||
|
|
||
|
|
||
| -- !query 6 | ||
| select -max(key), +max(key) from testdata | ||
| -- !query 6 schema | ||
| struct<(- max(key)):int,max(key):int> | ||
| -- !query 6 output | ||
| -100 100 | ||
|
|
||
|
|
||
| -- !query 7 | ||
| select - (-10) | ||
| -- !query 7 schema | ||
| struct<(- -10):int> | ||
| -- !query 7 output | ||
| 10 | ||
|
|
||
|
|
||
| -- !query 8 | ||
| select + (-key) from testdata where key = 32 | ||
| -- !query 8 schema | ||
| struct<(- key):int> | ||
| -- !query 8 output | ||
| -32 | ||
|
|
||
|
|
||
| -- !query 9 | ||
| select - (+max(key)) from testdata | ||
| -- !query 9 schema | ||
| struct<(- max(key)):int> | ||
| -- !query 9 output | ||
| -100 | ||
|
|
||
|
|
||
| -- !query 10 | ||
| select - - 3 | ||
| -- !query 10 schema | ||
| struct<(- -3):int> | ||
| -- !query 10 output | ||
| 3 | ||
|
|
||
|
|
||
| -- !query 11 | ||
| select - + 20 | ||
| -- !query 11 schema | ||
| struct<(- 20):int> | ||
| -- !query 11 output | ||
| -20 | ||
|
|
||
|
|
||
| -- !query 12 | ||
| select + + 100 | ||
| -- !query 12 schema | ||
| struct<100:int> | ||
| -- !query 12 output | ||
| 100 | ||
|
|
||
|
|
||
| -- !query 13 | ||
| select - - max(key) from testdata | ||
| -- !query 13 schema | ||
| struct<(- (- max(key))):int> | ||
| -- !query 13 output | ||
| 100 | ||
|
|
||
|
|
||
| -- !query 14 | ||
| select + - key from testdata where key = 33 | ||
| -- !query 14 schema | ||
| struct<(- key):int> | ||
| -- !query 14 output | ||
| -33 | ||
|
|
||
|
|
||
| -- !query 15 | ||
| select 5 / 2 | ||
| -- !query 15 schema | ||
| struct<(CAST(5 AS DOUBLE) / CAST(2 AS DOUBLE)):double> | ||
| -- !query 15 output | ||
| 2.5 | ||
|
|
||
|
|
||
| -- !query 16 | ||
| select 5 / 0 | ||
| -- !query 16 schema | ||
| struct<(CAST(5 AS DOUBLE) / CAST(0 AS DOUBLE)):double> | ||
| -- !query 16 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 17 | ||
| select 5 / null | ||
| -- !query 17 schema | ||
| struct<(CAST(5 AS DOUBLE) / CAST(NULL AS DOUBLE)):double> | ||
| -- !query 17 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 18 | ||
| select null / 5 | ||
| -- !query 18 schema | ||
| struct<(CAST(NULL AS DOUBLE) / CAST(5 AS DOUBLE)):double> | ||
| -- !query 18 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 19 | ||
| select 5 div 2 | ||
| -- !query 19 schema | ||
| struct<CAST((CAST(5 AS DOUBLE) / CAST(2 AS DOUBLE)) AS BIGINT):bigint> | ||
| -- !query 19 output | ||
| 2 | ||
|
|
||
|
|
||
| -- !query 20 | ||
| select 5 div 0 | ||
| -- !query 20 schema | ||
| struct<CAST((CAST(5 AS DOUBLE) / CAST(0 AS DOUBLE)) AS BIGINT):bigint> | ||
| -- !query 20 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 21 | ||
| select 5 div null | ||
| -- !query 21 schema | ||
| struct<CAST((CAST(5 AS DOUBLE) / CAST(NULL AS DOUBLE)) AS BIGINT):bigint> | ||
| -- !query 21 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 22 | ||
| select null div 5 | ||
| -- !query 22 schema | ||
| struct<CAST((CAST(NULL AS DOUBLE) / CAST(5 AS DOUBLE)) AS BIGINT):bigint> | ||
| -- !query 22 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 23 | ||
| select 1 + 2 | ||
| -- !query 23 schema | ||
| struct<(1 + 2):int> | ||
| -- !query 23 output | ||
| 3 | ||
|
|
||
|
|
||
| -- !query 24 | ||
| select 1 - 2 | ||
| -- !query 24 schema | ||
| struct<(1 - 2):int> | ||
| -- !query 24 output | ||
| -1 | ||
|
|
||
|
|
||
| -- !query 25 | ||
| select 2 * 5 | ||
| -- !query 25 schema | ||
| struct<(2 * 5):int> | ||
| -- !query 25 output | ||
| 10 | ||
|
|
||
|
|
||
| -- !query 26 | ||
| select 5 % 3 | ||
| -- !query 26 schema | ||
| struct<(5 % 3):int> | ||
| -- !query 26 output | ||
| 2 | ||
|
|
||
|
|
||
| -- !query 27 | ||
| select pmod(-7, 3) | ||
| -- !query 27 schema | ||
| struct<pmod(-7, 3):int> | ||
| -- !query 27 output | ||
| 2 | ||
|
|
||
|
|
||
| -- !query 28 | ||
| select ceiling(0) | ||
| -- !query 28 schema | ||
| struct<CEIL(CAST(0 AS DOUBLE)):bigint> | ||
| -- !query 28 output | ||
| 0 | ||
|
|
||
|
|
||
| -- !query 29 | ||
| select ceiling(1) | ||
| -- !query 29 schema | ||
| struct<CEIL(CAST(1 AS DOUBLE)):bigint> | ||
| -- !query 29 output | ||
| 1 | ||
|
|
||
|
|
||
| -- !query 30 | ||
| select ceil(1234567890123456) | ||
| -- !query 30 schema | ||
| struct<CEIL(1234567890123456):bigint> | ||
| -- !query 30 output | ||
| 1234567890123456 | ||
|
|
||
|
|
||
| -- !query 31 | ||
| select ceil(12345678901234567) | ||
| -- !query 31 schema | ||
| struct<CEIL(12345678901234567):bigint> | ||
| -- !query 31 output | ||
| 12345678901234567 | ||
|
|
||
|
|
||
| -- !query 32 | ||
| select ceiling(1234567890123456) | ||
| -- !query 32 schema | ||
| struct<CEIL(1234567890123456):bigint> | ||
| -- !query 32 output | ||
| 1234567890123456 | ||
|
|
||
|
|
||
| -- !query 33 | ||
| select ceiling(12345678901234567) | ||
| -- !query 33 schema | ||
| struct<CEIL(12345678901234567):bigint> | ||
| -- !query 33 output | ||
| 12345678901234567 | ||
|
|
||
|
|
||
| -- !query 34 | ||
| select floor(0) | ||
| -- !query 34 schema | ||
| struct<FLOOR(CAST(0 AS DOUBLE)):bigint> | ||
| -- !query 34 output | ||
| 0 | ||
|
|
||
|
|
||
| -- !query 35 | ||
| select floor(1) | ||
| -- !query 35 schema | ||
| struct<FLOOR(CAST(1 AS DOUBLE)):bigint> | ||
| -- !query 35 output | ||
| 1 | ||
|
|
||
|
|
||
| -- !query 36 | ||
| select floor(1234567890123456) | ||
| -- !query 36 schema | ||
| struct<FLOOR(1234567890123456):bigint> | ||
| -- !query 36 output | ||
| 1234567890123456 | ||
|
|
||
|
|
||
| -- !query 37 | ||
| select floor(12345678901234567) | ||
| -- !query 37 schema | ||
| struct<FLOOR(12345678901234567):bigint> | ||
| -- !query 37 output | ||
| 12345678901234567 |
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.
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.
I don't think we should modify the change from what we did at
masterwhen backporting as far as possible .If you want to modify this, let's submit another pr to
masterfirst, and then backport it too.