Skip to content

Commit f53316f

Browse files
Subham SinghalSubham Singhal
authored andcommitted
Fix UT
1 parent e86473a commit f53316f

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

datafusion/sqllogictest/test_files/spark/math/negative.slt

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ SELECT negative(-1.5::double);
9494
query R
9595
SELECT negative(0.0::float);
9696
----
97+
-0.0
98+
99+
# Test negative with negative zero float
100+
query R
101+
SELECT negative(-0.0::float);
102+
----
97103
0.0
98104

99105
# Test negative with decimal
@@ -147,30 +153,55 @@ SELECT negative(1234567890.123456::double);
147153
----
148154
-1234567890.123456
149155

150-
# Test wrap-around: negative of minimum int (should overflow)
156+
# Test wrap-around: negative of minimum int (should wrap to same value)
157+
# Using table to avoid constant folding overflow during optimization
158+
statement ok
159+
CREATE TABLE min_values_int AS VALUES (-2147483648);
160+
151161
query I
152-
SELECT negative(-2147483648::int);
162+
SELECT negative(column1::int) FROM min_values_int;
153163
----
154164
-2147483648
155165

156-
# Test wrap-around: negative of minimum bigint (should overflow)
166+
statement ok
167+
DROP TABLE min_values_int;
168+
169+
# Test wrap-around: negative of minimum bigint (should wrap to same value)
170+
statement ok
171+
CREATE TABLE min_values_bigint AS VALUES (-9223372036854775808);
172+
157173
query I
158-
SELECT negative(-9223372036854775808::bigint);
174+
SELECT negative(column1::bigint) FROM min_values_bigint;
159175
----
160176
-9223372036854775808
161177

162-
# Test wrap-around: negative of minimum smallint (should overflow)
178+
statement ok
179+
DROP TABLE min_values_bigint;
180+
181+
# Test wrap-around: negative of minimum smallint (should wrap to same value)
182+
statement ok
183+
CREATE TABLE min_values_smallint AS VALUES (-32768);
184+
163185
query I
164-
SELECT negative(-32768::smallint);
186+
SELECT negative(column1::smallint) FROM min_values_smallint;
165187
----
166188
-32768
167189

168-
# Test wrap-around: negative of minimum tinyint (should overflow)
190+
statement ok
191+
DROP TABLE min_values_smallint;
192+
193+
# Test wrap-around: negative of minimum tinyint (should wrap to same value)
194+
statement ok
195+
CREATE TABLE min_values_tinyint AS VALUES (-128);
196+
169197
query I
170-
SELECT negative(-128::tinyint);
198+
SELECT negative(column1::tinyint) FROM min_values_tinyint;
171199
----
172200
-128
173201

202+
statement ok
203+
DROP TABLE min_values_tinyint;
204+
174205
# Test overflow: negative of positive infinity (float)
175206
query R
176207
SELECT negative('Infinity'::float);
@@ -211,13 +242,13 @@ NaN
211242
query R
212243
SELECT negative(3.4028235e38::float);
213244
----
214-
-3.4028235e38
245+
-340282350000000000000000000000000000000
215246

216247
# Test overflow: negative of minimum float value
217248
query R
218249
SELECT negative(-3.4028235e38::float);
219250
----
220-
3.4028235e38
251+
340282350000000000000000000000000000000
221252

222253
# Test overflow: negative of maximum double value
223254
query R

0 commit comments

Comments
 (0)