|
| 1 | +-- |
| 2 | +-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 3 | +-- |
| 4 | +-- |
| 5 | +-- INT2 |
| 6 | +-- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/int2.sql |
| 7 | + |
| 8 | +CREATE TABLE INT2_TBL(f1 smallint) USING parquet; |
| 9 | + |
| 10 | +-- [SPARK-28023] Trim the string when cast string type to other types |
| 11 | +INSERT INTO INT2_TBL VALUES (trim('0 ')); |
| 12 | + |
| 13 | +INSERT INTO INT2_TBL VALUES (trim(' 1234 ')); |
| 14 | + |
| 15 | +INSERT INTO INT2_TBL VALUES (trim(' -1234')); |
| 16 | + |
| 17 | +-- [SPARK-27923] Invalid input syntax for type short throws exception at PostgreSQL |
| 18 | +-- INSERT INTO INT2_TBL VALUES ('34.5'); |
| 19 | + |
| 20 | +-- largest and smallest values |
| 21 | +INSERT INTO INT2_TBL VALUES ('32767'); |
| 22 | + |
| 23 | +INSERT INTO INT2_TBL VALUES ('-32767'); |
| 24 | + |
| 25 | +-- bad input values -- should give errors |
| 26 | +-- INSERT INTO INT2_TBL VALUES ('100000'); |
| 27 | +-- INSERT INTO INT2_TBL VALUES ('asdf'); |
| 28 | +-- INSERT INTO INT2_TBL VALUES (' '); |
| 29 | +-- INSERT INTO INT2_TBL VALUES ('- 1234'); |
| 30 | +-- INSERT INTO INT2_TBL VALUES ('4 444'); |
| 31 | +-- INSERT INTO INT2_TBL VALUES ('123 dt'); |
| 32 | +-- INSERT INTO INT2_TBL VALUES (''); |
| 33 | + |
| 34 | + |
| 35 | +SELECT '' AS five, * FROM INT2_TBL; |
| 36 | + |
| 37 | +SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> smallint('0'); |
| 38 | + |
| 39 | +SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int('0'); |
| 40 | + |
| 41 | +SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = smallint('0'); |
| 42 | + |
| 43 | +SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int('0'); |
| 44 | + |
| 45 | +SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < smallint('0'); |
| 46 | + |
| 47 | +SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int('0'); |
| 48 | + |
| 49 | +SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= smallint('0'); |
| 50 | + |
| 51 | +SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int('0'); |
| 52 | + |
| 53 | +SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > smallint('0'); |
| 54 | + |
| 55 | +SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int('0'); |
| 56 | + |
| 57 | +SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= smallint('0'); |
| 58 | + |
| 59 | +SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int('0'); |
| 60 | + |
| 61 | +-- positive odds |
| 62 | +SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % smallint('2')) = smallint('1'); |
| 63 | + |
| 64 | +-- any evens |
| 65 | +SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int('2')) = smallint('0'); |
| 66 | + |
| 67 | +-- [SPARK-28024] Incorrect value when out of range |
| 68 | +-- SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT2_TBL i; |
| 69 | + |
| 70 | +SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT2_TBL i |
| 71 | +WHERE abs(f1) < 16384; |
| 72 | + |
| 73 | +SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT2_TBL i; |
| 74 | + |
| 75 | +-- [SPARK-28024] Incorrect value when out of range |
| 76 | +-- SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT2_TBL i; |
| 77 | + |
| 78 | +SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT2_TBL i |
| 79 | +WHERE f1 < 32766; |
| 80 | + |
| 81 | +SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT2_TBL i; |
| 82 | + |
| 83 | +-- [SPARK-28024] Incorrect value when out of range |
| 84 | +-- SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT2_TBL i; |
| 85 | + |
| 86 | +SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT2_TBL i |
| 87 | +WHERE f1 > -32767; |
| 88 | + |
| 89 | +SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT2_TBL i; |
| 90 | + |
| 91 | +-- PostgreSQL `/` is the same with Spark `div` since SPARK-2659. |
| 92 | +SELECT '' AS five, i.f1, i.f1 div smallint('2') AS x FROM INT2_TBL i; |
| 93 | + |
| 94 | +-- PostgreSQL `/` is the same with Spark `div` since SPARK-2659. |
| 95 | +SELECT '' AS five, i.f1, i.f1 div int('2') AS x FROM INT2_TBL i; |
| 96 | + |
| 97 | +-- corner cases |
| 98 | +SELECT string(shiftleft(smallint(-1), 15)); |
| 99 | +SELECT string(smallint(shiftleft(smallint(-1), 15))+1); |
| 100 | + |
| 101 | +-- check sane handling of INT16_MIN overflow cases |
| 102 | +-- [SPARK-28024] Incorrect numeric values when out of range |
| 103 | +-- SELECT smallint((-32768)) * smallint(-1); |
| 104 | +-- SELECT smallint(-32768) / smallint(-1); |
| 105 | +SELECT smallint(-32768) % smallint(-1); |
| 106 | + |
| 107 | +-- [SPARK-28028] Cast numeric to integral type need round |
| 108 | +-- check rounding when casting from float |
| 109 | +SELECT x, smallint(x) AS int2_value |
| 110 | +FROM (VALUES float(-2.5), |
| 111 | + float(-1.5), |
| 112 | + float(-0.5), |
| 113 | + float(0.0), |
| 114 | + float(0.5), |
| 115 | + float(1.5), |
| 116 | + float(2.5)) t(x); |
| 117 | + |
| 118 | +-- [SPARK-28028] Cast numeric to integral type need round |
| 119 | +-- check rounding when casting from numeric |
| 120 | +SELECT x, smallint(x) AS int2_value |
| 121 | +FROM (VALUES cast(-2.5 as decimal(38, 18)), |
| 122 | + cast(-1.5 as decimal(38, 18)), |
| 123 | + cast(-0.5 as decimal(38, 18)), |
| 124 | + cast(-0.0 as decimal(38, 18)), |
| 125 | + cast(0.5 as decimal(38, 18)), |
| 126 | + cast(1.5 as decimal(38, 18)), |
| 127 | + cast(2.5 as decimal(38, 18))) t(x); |
| 128 | + |
| 129 | +DROP TABLE INT2_TBL; |
0 commit comments