@@ -84,69 +84,129 @@ statement ok
8484drop table a
8585
8686# test datafusion.sql_parser.parse_float_as_decimal
87+ #
8788# default option value is false
88- query R
89- select 10000000000000000000.01
89+ query RR
90+ select 10000000000000000000.01, -10000000000000000000.01
9091----
91- 10000000000000000000
92+ 10000000000000000000 -10000000000000000000
9293
93- query T
94- select arrow_typeof(10000000000000000000.01)
94+ query TT
95+ select arrow_typeof(10000000000000000000.01), arrow_typeof(-10000000000000000000.01)
96+ ----
97+ Float64 Float64
98+
99+ # select 0, i64::MIN, i64::MIN-1, i64::MAX, i64::MAX + 1, u64::MAX, u64::MAX + 1
100+ query IIRIIIR
101+ select 0, -9223372036854775808, -9223372036854775809, 9223372036854775807,
102+ 9223372036854775808, 18446744073709551615, 18446744073709551616
95103----
96- Float64
104+ 0 -9223372036854775808 -9223372036854776000 9223372036854775807 9223372036854775808 18446744073709551615 18446744073709552000
105+
106+ query TTTTTTT
107+ select arrow_typeof(0), arrow_typeof(-9223372036854775808), arrow_typeof(-9223372036854775809),
108+ arrow_typeof(9223372036854775807), arrow_typeof(9223372036854775808),
109+ arrow_typeof(18446744073709551615), arrow_typeof(18446744073709551616)
110+ ----
111+ Int64 Int64 Float64 Int64 UInt64 UInt64 Float64
112+
97113
98114statement ok
99115set datafusion.sql_parser.parse_float_as_decimal = true;
100116
101- query R
102- select 10000000000000000000.01
117+ query RR
118+ select 10000000000000000000.01, -10000000000000000000.01
119+ ----
120+ 10000000000000000000.01 -10000000000000000000.01
121+
122+ query TT
123+ select arrow_typeof(10000000000000000000.01), arrow_typeof(-10000000000000000000.01)
103124----
104- 10000000000000000000.01
125+ Decimal128(22, 2) Decimal128(22, 2)
105126
106- query T
107- select arrow_typeof(10000000000000000000.01)
127+ # select 0, i64::MIN, i64::MIN-1, i64::MAX, i64::MAX + 1, u64::MAX, u64::MAX + 1
128+ query IIRIIIR
129+ select 0, -9223372036854775808, -9223372036854775809, 9223372036854775807,
130+ 9223372036854775808, 18446744073709551615, 18446744073709551616
108131----
109- Decimal128(22, 2)
132+ 0 -9223372036854775808 -9223372036854775809 9223372036854775807 9223372036854775808 18446744073709551615 18446744073709551616
110133
111- query R
112- select 999999999999999999999999999999999999
134+ query TTTTTTT
135+ select arrow_typeof(0), arrow_typeof(-9223372036854775808), arrow_typeof(-9223372036854775809),
136+ arrow_typeof(9223372036854775807), arrow_typeof(9223372036854775808),
137+ arrow_typeof(18446744073709551615), arrow_typeof(18446744073709551616)
113138----
114- 999999999999999999999999999999999999
139+ Int64 Int64 Decimal128(19, 0) Int64 UInt64 UInt64 Decimal128(20, 0)
115140
116- query T
117- select arrow_typeof(999999999999999999999999999999999999)
141+ # special cases
142+ query RRRR
143+ select .0 as c1, 0. as c2, 0000. as c3, 00000.00 as c4
118144----
119- Decimal128(36, 0)
145+ 0 0 0 0
120146
121- query R
122- select 99999999999999999999999999999999999999
147+ query TTTT
148+ select arrow_typeof(.0) as c1, arrow_typeof(0.) as c2, arrow_typeof(0000.) as c3, arrow_typeof(00000.00) as c4
123149----
124- 99999999999999999999999999999999999999
150+ Decimal128(1, 1) Decimal128(1, 0) Decimal128(1, 0) Decimal128(2, 2)
125151
126- query T
127- select arrow_typeof(99999999999999999999999999999999999999)
152+ query RR
153+ select 999999999999999999999999999999999999, -999999999999999999999999999999999999
128154----
129- Decimal128(38, 0)
155+ 999999999999999999999999999999999999 -999999999999999999999999999999999999
130156
131- query R
132- select 9999999999999999999999999999999999.9999
157+ query TT
158+ select arrow_typeof(999999999999999999999999999999999999), arrow_typeof(-999999999999999999999999999999999999)
133159----
134- 9999999999999999999999999999999999.9999
160+ Decimal128(36, 0) Decimal128(36, 0)
135161
136- query T
137- select arrow_typeof(9999999999999999999999999999999999.9999)
162+ query RR
163+ select 99999999999999999999999999999999999999, -99999999999999999999999999999999999999
138164----
139- Decimal128(38, 4)
165+ 99999999999999999999999999999999999999 -99999999999999999999999999999999999999
166+
167+ query TT
168+ select arrow_typeof(99999999999999999999999999999999999999), arrow_typeof(-99999999999999999999999999999999999999)
169+ ----
170+ Decimal128(38, 0) Decimal128(38, 0)
171+
172+ query RR
173+ select 9999999999999999999999999999999999.9999, -9999999999999999999999999999999999.9999
174+ ----
175+ 9999999999999999999999999999999999.9999 -9999999999999999999999999999999999.9999
176+
177+ query TT
178+ select arrow_typeof(9999999999999999999999999999999999.9999), arrow_typeof(-9999999999999999999999999999999999.9999)
179+ ----
180+ Decimal128(38, 4) Decimal128(38, 4)
181+
182+ # leading zeroes
183+ query RRR
184+ select 00009999999999999999999999999999999999.9999, -00009999999999999999999999999999999999.9999, 0018446744073709551616
185+ ----
186+ 9999999999999999999999999999999999.9999 -9999999999999999999999999999999999.9999 18446744073709551616
187+
188+ query TTT
189+ select arrow_typeof(00009999999999999999999999999999999999.9999),
190+ arrow_typeof(-00009999999999999999999999999999999999.9999),
191+ arrow_typeof(0018446744073709551616)
192+ ----
193+ Decimal128(38, 4) Decimal128(38, 4) Decimal128(20, 0)
140194
141195# precision overflow
142- statement error SQL error: ParserError\("Cannot parse 123456789012345678901234567890123456789 as i128 when building decimal: precision overflow"\)
196+ statement error DataFusion error: SQL error: ParserError\("Cannot parse 123456789012345678901234567890123456789 as i128 when building decimal: precision overflow"\)
143197select 123456789.012345678901234567890123456789
144198
199+ statement error SQL error: ParserError\("Cannot parse 123456789012345678901234567890123456789 as i128 when building decimal: precision overflow"\)
200+ select -123456789.012345678901234567890123456789
201+
145202# can not fit in i128
146203statement error SQL error: ParserError\("Cannot parse 1234567890123456789012345678901234567890 as i128 when building decimal: number too large to fit in target type"\)
147204select 123456789.0123456789012345678901234567890
148205
149- # Restore those to default value again
206+ statement error SQL error: ParserError\("Cannot parse 1234567890123456789012345678901234567890 as i128 when building decimal: number too large to fit in target type"\)
207+ select -123456789.0123456789012345678901234567890
208+
209+ # Restore option to default value
150210statement ok
151211set datafusion.sql_parser.parse_float_as_decimal = false;
152212
0 commit comments