|
| 1 | +-- |
| 2 | +-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 3 | +-- |
| 4 | +-- |
| 5 | +-- INT4 |
| 6 | +-- https://github.com/postgres/postgres/blob/REL_12_BETA1/src/test/regress/sql/int4.sql |
| 7 | +-- |
| 8 | + |
| 9 | +CREATE TABLE INT4_TBL(f1 int) USING parquet; |
| 10 | + |
| 11 | +-- [SPARK-28023] Trim the string when cast string type to other types |
| 12 | +INSERT INTO INT4_TBL VALUES (trim(' 0 ')); |
| 13 | + |
| 14 | +INSERT INTO INT4_TBL VALUES (trim('123456 ')); |
| 15 | + |
| 16 | +INSERT INTO INT4_TBL VALUES (trim(' -123456')); |
| 17 | + |
| 18 | +-- [SPARK-27923] Invalid input syntax for integer: "34.5" at PostgreSQL |
| 19 | +-- INSERT INTO INT4_TBL(f1) VALUES ('34.5'); |
| 20 | + |
| 21 | +-- largest and smallest values |
| 22 | +INSERT INTO INT4_TBL VALUES ('2147483647'); |
| 23 | + |
| 24 | +INSERT INTO INT4_TBL VALUES ('-2147483647'); |
| 25 | + |
| 26 | +-- [SPARK-27923] Spark SQL insert these bad inputs to NULL |
| 27 | +-- bad input values |
| 28 | +-- INSERT INTO INT4_TBL(f1) VALUES ('1000000000000'); |
| 29 | +-- INSERT INTO INT4_TBL(f1) VALUES ('asdf'); |
| 30 | +-- INSERT INTO INT4_TBL(f1) VALUES (' '); |
| 31 | +-- INSERT INTO INT4_TBL(f1) VALUES (' asdf '); |
| 32 | +-- INSERT INTO INT4_TBL(f1) VALUES ('- 1234'); |
| 33 | +-- INSERT INTO INT4_TBL(f1) VALUES ('123 5'); |
| 34 | +-- INSERT INTO INT4_TBL(f1) VALUES (''); |
| 35 | + |
| 36 | + |
| 37 | +SELECT '' AS five, * FROM INT4_TBL; |
| 38 | + |
| 39 | +SELECT '' AS four, i.* FROM INT4_TBL i WHERE i.f1 <> smallint('0'); |
| 40 | + |
| 41 | +SELECT '' AS four, i.* FROM INT4_TBL i WHERE i.f1 <> int('0'); |
| 42 | + |
| 43 | +SELECT '' AS one, i.* FROM INT4_TBL i WHERE i.f1 = smallint('0'); |
| 44 | + |
| 45 | +SELECT '' AS one, i.* FROM INT4_TBL i WHERE i.f1 = int('0'); |
| 46 | + |
| 47 | +SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 < smallint('0'); |
| 48 | + |
| 49 | +SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 < int('0'); |
| 50 | + |
| 51 | +SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 <= smallint('0'); |
| 52 | + |
| 53 | +SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 <= int('0'); |
| 54 | + |
| 55 | +SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 > smallint('0'); |
| 56 | + |
| 57 | +SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 > int('0'); |
| 58 | + |
| 59 | +SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= smallint('0'); |
| 60 | + |
| 61 | +SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int('0'); |
| 62 | + |
| 63 | +-- positive odds |
| 64 | +SELECT '' AS one, i.* FROM INT4_TBL i WHERE (i.f1 % smallint('2')) = smallint('1'); |
| 65 | + |
| 66 | +-- any evens |
| 67 | +SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int('2')) = smallint('0'); |
| 68 | + |
| 69 | +-- [SPARK-28024] Incorrect value when out of range |
| 70 | +SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT4_TBL i; |
| 71 | + |
| 72 | +SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT4_TBL i |
| 73 | +WHERE abs(f1) < 1073741824; |
| 74 | + |
| 75 | +-- [SPARK-28024] Incorrect value when out of range |
| 76 | +SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT4_TBL i; |
| 77 | + |
| 78 | +SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT4_TBL i |
| 79 | +WHERE abs(f1) < 1073741824; |
| 80 | + |
| 81 | +-- [SPARK-28024] Incorrect value when out of range |
| 82 | +SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT4_TBL i; |
| 83 | + |
| 84 | +SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT4_TBL i |
| 85 | +WHERE f1 < 2147483646; |
| 86 | + |
| 87 | +-- [SPARK-28024] Incorrect value when out of range |
| 88 | +SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT4_TBL i; |
| 89 | + |
| 90 | +SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT4_TBL i |
| 91 | +WHERE f1 < 2147483646; |
| 92 | + |
| 93 | +-- [SPARK-28024] Incorrect value when out of range |
| 94 | +SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT4_TBL i; |
| 95 | + |
| 96 | +SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT4_TBL i |
| 97 | +WHERE f1 > -2147483647; |
| 98 | + |
| 99 | +-- [SPARK-28024] Incorrect value when out of range |
| 100 | +SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT4_TBL i; |
| 101 | + |
| 102 | +SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT4_TBL i |
| 103 | +WHERE f1 > -2147483647; |
| 104 | + |
| 105 | +SELECT '' AS five, i.f1, i.f1 / smallint('2') AS x FROM INT4_TBL i; |
| 106 | + |
| 107 | +SELECT '' AS five, i.f1, i.f1 / int('2') AS x FROM INT4_TBL i; |
| 108 | + |
| 109 | +-- |
| 110 | +-- more complex expressions |
| 111 | +-- |
| 112 | + |
| 113 | +-- variations on unary minus parsing |
| 114 | +SELECT -2+3 AS one; |
| 115 | + |
| 116 | +SELECT 4-2 AS two; |
| 117 | + |
| 118 | +SELECT 2- -1 AS three; |
| 119 | + |
| 120 | +SELECT 2 - -2 AS four; |
| 121 | + |
| 122 | +SELECT smallint('2') * smallint('2') = smallint('16') / smallint('4') AS true; |
| 123 | + |
| 124 | +SELECT int('2') * smallint('2') = smallint('16') / int('4') AS true; |
| 125 | + |
| 126 | +SELECT smallint('2') * int('2') = int('16') / smallint('4') AS true; |
| 127 | + |
| 128 | +SELECT int('1000') < int('999') AS false; |
| 129 | + |
| 130 | +-- [SPARK-28027] Our ! and !! has different meanings |
| 131 | +-- SELECT 4! AS twenty_four; |
| 132 | + |
| 133 | +-- SELECT !!3 AS six; |
| 134 | + |
| 135 | +SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten; |
| 136 | + |
| 137 | +-- [SPARK-2659] HiveQL: Division operator should always perform fractional division |
| 138 | +SELECT 2 + 2 / 2 AS three; |
| 139 | + |
| 140 | +SELECT (2 + 2) / 2 AS two; |
| 141 | + |
| 142 | +-- [SPARK-28027] Add bitwise shift left/right operators |
| 143 | +-- corner case |
| 144 | +SELECT string(shiftleft(int(-1), 31)); |
| 145 | +SELECT string(int(shiftleft(int(-1), 31))+1); |
| 146 | + |
| 147 | +-- [SPARK-28024] Incorrect numeric values when out of range |
| 148 | +-- check sane handling of INT_MIN overflow cases |
| 149 | +-- SELECT (-2147483648)::int4 * (-1)::int4; |
| 150 | +-- SELECT (-2147483648)::int4 / (-1)::int4; |
| 151 | +SELECT int(-2147483648) % int(-1); |
| 152 | +-- SELECT (-2147483648)::int4 * (-1)::int2; |
| 153 | +-- SELECT (-2147483648)::int4 / (-1)::int2; |
| 154 | +SELECT int(-2147483648) % smallint(-1); |
| 155 | + |
| 156 | +-- [SPARK-28028] Cast numeric to integral type need round |
| 157 | +-- check rounding when casting from float |
| 158 | +SELECT x, int(x) AS int4_value |
| 159 | +FROM (VALUES double(-2.5), |
| 160 | + double(-1.5), |
| 161 | + double(-0.5), |
| 162 | + double(0.0), |
| 163 | + double(0.5), |
| 164 | + double(1.5), |
| 165 | + double(2.5)) t(x); |
| 166 | + |
| 167 | +-- [SPARK-28028] Cast numeric to integral type need round |
| 168 | +-- check rounding when casting from numeric |
| 169 | +SELECT x, int(x) AS int4_value |
| 170 | +FROM (VALUES cast(-2.5 as decimal(38, 18)), |
| 171 | + cast(-1.5 as decimal(38, 18)), |
| 172 | + cast(-0.5 as decimal(38, 18)), |
| 173 | + cast(-0.0 as decimal(38, 18)), |
| 174 | + cast(0.5 as decimal(38, 18)), |
| 175 | + cast(1.5 as decimal(38, 18)), |
| 176 | + cast(2.5 as decimal(38, 18))) t(x); |
| 177 | + |
| 178 | +DROP TABLE INT4_TBL; |
0 commit comments