-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28029][SQL][TEST] Port int2.sql #24853
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
129 changes: 129 additions & 0 deletions
129
sql/core/src/test/resources/sql-tests/inputs/pgSQL/int2.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,129 @@ | ||
| -- | ||
| -- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group | ||
| -- | ||
| -- | ||
| -- INT2 | ||
| -- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/int2.sql | ||
|
|
||
| CREATE TABLE INT2_TBL(f1 smallint) USING parquet; | ||
|
|
||
| -- [SPARK-28023] Trim the string when cast string type to other types | ||
| INSERT INTO INT2_TBL VALUES (trim('0 ')); | ||
|
|
||
| INSERT INTO INT2_TBL VALUES (trim(' 1234 ')); | ||
|
|
||
| INSERT INTO INT2_TBL VALUES (trim(' -1234')); | ||
|
|
||
| -- [SPARK-27923] Invalid input syntax for type short throws exception at PostgreSQL | ||
| -- INSERT INTO INT2_TBL VALUES ('34.5'); | ||
|
|
||
| -- largest and smallest values | ||
| INSERT INTO INT2_TBL VALUES ('32767'); | ||
|
|
||
| INSERT INTO INT2_TBL VALUES ('-32767'); | ||
|
|
||
| -- bad input values -- should give errors | ||
| -- INSERT INTO INT2_TBL VALUES ('100000'); | ||
| -- INSERT INTO INT2_TBL VALUES ('asdf'); | ||
| -- INSERT INTO INT2_TBL VALUES (' '); | ||
| -- INSERT INTO INT2_TBL VALUES ('- 1234'); | ||
| -- INSERT INTO INT2_TBL VALUES ('4 444'); | ||
| -- INSERT INTO INT2_TBL VALUES ('123 dt'); | ||
| -- INSERT INTO INT2_TBL VALUES (''); | ||
|
|
||
|
|
||
| SELECT '' AS five, * FROM INT2_TBL; | ||
|
|
||
| SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> smallint('0'); | ||
|
|
||
| SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int('0'); | ||
|
|
||
| SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = smallint('0'); | ||
|
|
||
| SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int('0'); | ||
|
|
||
| SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < smallint('0'); | ||
|
|
||
| SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int('0'); | ||
|
|
||
| SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= smallint('0'); | ||
|
|
||
| SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int('0'); | ||
|
|
||
| SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > smallint('0'); | ||
|
|
||
| SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int('0'); | ||
|
|
||
| SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= smallint('0'); | ||
|
|
||
| SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int('0'); | ||
|
|
||
| -- positive odds | ||
| SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % smallint('2')) = smallint('1'); | ||
|
|
||
| -- any evens | ||
| SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int('2')) = smallint('0'); | ||
|
|
||
| -- [SPARK-28024] Incorrect value when out of range | ||
| -- SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT2_TBL i; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT2_TBL i | ||
| WHERE abs(f1) < 16384; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT2_TBL i; | ||
|
|
||
| -- [SPARK-28024] Incorrect value when out of range | ||
| -- SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT2_TBL i; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT2_TBL i | ||
| WHERE f1 < 32766; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT2_TBL i; | ||
|
|
||
| -- [SPARK-28024] Incorrect value when out of range | ||
| -- SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT2_TBL i; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT2_TBL i | ||
| WHERE f1 > -32767; | ||
|
|
||
| SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT2_TBL i; | ||
|
|
||
| -- PostgreSQL `/` is the same with Spark `div` since SPARK-2659. | ||
| SELECT '' AS five, i.f1, i.f1 div smallint('2') AS x FROM INT2_TBL i; | ||
|
|
||
| -- PostgreSQL `/` is the same with Spark `div` since SPARK-2659. | ||
| SELECT '' AS five, i.f1, i.f1 div int('2') AS x FROM INT2_TBL i; | ||
|
|
||
| -- corner cases | ||
| SELECT string(shiftleft(smallint(-1), 15)); | ||
| SELECT string(smallint(shiftleft(smallint(-1), 15))+1); | ||
|
|
||
| -- check sane handling of INT16_MIN overflow cases | ||
| -- [SPARK-28024] Incorrect numeric values when out of range | ||
| -- SELECT smallint((-32768)) * smallint(-1); | ||
| -- SELECT smallint(-32768) / smallint(-1); | ||
| SELECT smallint(-32768) % smallint(-1); | ||
|
|
||
| -- [SPARK-28028] Cast numeric to integral type need round | ||
| -- check rounding when casting from float | ||
| SELECT x, smallint(x) AS int2_value | ||
| FROM (VALUES float(-2.5), | ||
| float(-1.5), | ||
| float(-0.5), | ||
| float(0.0), | ||
| float(0.5), | ||
| float(1.5), | ||
| float(2.5)) t(x); | ||
|
|
||
| -- [SPARK-28028] Cast numeric to integral type need round | ||
| -- check rounding when casting from numeric | ||
| SELECT x, smallint(x) AS int2_value | ||
| FROM (VALUES cast(-2.5 as decimal(38, 18)), | ||
| cast(-1.5 as decimal(38, 18)), | ||
| cast(-0.5 as decimal(38, 18)), | ||
| cast(-0.0 as decimal(38, 18)), | ||
| cast(0.5 as decimal(38, 18)), | ||
| cast(1.5 as decimal(38, 18)), | ||
| cast(2.5 as decimal(38, 18))) t(x); | ||
|
|
||
| DROP TABLE INT2_TBL; | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.