Skip to content

Commit 430025c

Browse files
wangyumgatorsmile
authored andcommitted
[SPARK-22036][SQL][FOLLOWUP] Fix decimalArithmeticOperations.sql
## What changes were proposed in this pull request? Fix decimalArithmeticOperations.sql test ## How was this patch tested? N/A Author: Yuming Wang <wgyumg@gmail.com> Author: wangyum <wgyumg@gmail.com> Author: Yuming Wang <yumwang@ebay.com> Closes #20498 from wangyum/SPARK-22036. (cherry picked from commit 6fb3fd1) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
1 parent 45f0f4f commit 430025c

File tree

2 files changed

+80
-66
lines changed

2 files changed

+80
-66
lines changed

sql/core/src/test/resources/sql-tests/inputs/typeCoercion/native/decimalArithmeticOperations.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ select 12345678901234567890.0 * 12345678901234567890.0;
4848
select 1e35 / 0.1;
4949

5050
-- arithmetic operations causing a precision loss are truncated
51+
select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345;
5152
select 123456789123456789.1234567890 * 1.123456789123456789;
52-
select 0.001 / 9876543210987654321098765432109876543.2
53+
select 12345678912345.123456789123 / 0.000000012345678;
5354

5455
-- return NULL instead of rounding, according to old Spark versions' behavior
5556
set spark.sql.decimalOperations.allowPrecisionLoss=false;
@@ -74,7 +75,8 @@ select 12345678901234567890.0 * 12345678901234567890.0;
7475
select 1e35 / 0.1;
7576

7677
-- arithmetic operations causing a precision loss return NULL
78+
select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345;
7779
select 123456789123456789.1234567890 * 1.123456789123456789;
78-
select 0.001 / 9876543210987654321098765432109876543.2
80+
select 12345678912345.123456789123 / 0.000000012345678;
7981

8082
drop table decimals_test;

sql/core/src/test/resources/sql-tests/results/typeCoercion/native/decimalArithmeticOperations.sql.out

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Automatically generated by SQLQueryTestSuite
2-
-- Number of queries: 32
2+
-- Number of queries: 36
33

44

55
-- !query 0
@@ -146,146 +146,158 @@ NULL
146146

147147

148148
-- !query 17
149-
select 123456789123456789.1234567890 * 1.123456789123456789
149+
select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345
150150
-- !query 17 schema
151-
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)>
151+
struct<(CAST(12345678912345678912345678912.1234567 AS DECIMAL(38,6)) + CAST(9999999999999999999999999999999.12345 AS DECIMAL(38,6))):decimal(38,6)>
152152
-- !query 17 output
153-
138698367904130467.654320988515622621
153+
10012345678912345678912345678911.246907
154154

155155

156156
-- !query 18
157-
select 0.001 / 9876543210987654321098765432109876543.2
158-
159-
set spark.sql.decimalOperations.allowPrecisionLoss=false
157+
select 123456789123456789.1234567890 * 1.123456789123456789
160158
-- !query 18 schema
161-
struct<>
159+
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)>
162160
-- !query 18 output
163-
org.apache.spark.sql.catalyst.parser.ParseException
164-
165-
mismatched input 'spark' expecting <EOF>(line 3, pos 4)
166-
167-
== SQL ==
168-
select 0.001 / 9876543210987654321098765432109876543.2
169-
170-
set spark.sql.decimalOperations.allowPrecisionLoss=false
171-
----^^^
161+
138698367904130467.654320988515622621
172162

173163

174164
-- !query 19
175-
select id, a+b, a-b, a*b, a/b from decimals_test order by id
165+
select 12345678912345.123456789123 / 0.000000012345678
176166
-- !query 19 schema
177-
struct<id:int,(a + b):decimal(38,17),(a - b):decimal(38,17),(a * b):decimal(38,6),(a / b):decimal(38,6)>
167+
struct<(CAST(12345678912345.123456789123 AS DECIMAL(29,15)) / CAST(1.2345678E-8 AS DECIMAL(29,15))):decimal(38,9)>
178168
-- !query 19 output
179-
1 1099 -899 99900 0.1001
180-
2 24690.246 0 152402061.885129 1
181-
3 1234.2234567891011 -1233.9765432108989 152.358023 0.0001
182-
4 123456789123456790.12345678912345679 123456789123456787.87654321087654321 138698367904130467.515623 109890109097814272.043109
169+
1000000073899961059796.725866332
183170

184171

185172
-- !query 20
186-
select id, a*10, b/10 from decimals_test order by id
173+
set spark.sql.decimalOperations.allowPrecisionLoss=false
187174
-- !query 20 schema
188-
struct<id:int,(CAST(a AS DECIMAL(38,18)) * CAST(CAST(10 AS DECIMAL(2,0)) AS DECIMAL(38,18))):decimal(38,15),(CAST(b AS DECIMAL(38,18)) / CAST(CAST(10 AS DECIMAL(2,0)) AS DECIMAL(38,18))):decimal(38,18)>
175+
struct<key:string,value:string>
189176
-- !query 20 output
190-
1 1000 99.9
191-
2 123451.23 1234.5123
192-
3 1.234567891011 123.41
193-
4 1234567891234567890 0.112345678912345679
177+
spark.sql.decimalOperations.allowPrecisionLoss false
194178

195179

196180
-- !query 21
197-
select 10.3 * 3.0
181+
select id, a+b, a-b, a*b, a/b from decimals_test order by id
198182
-- !query 21 schema
199-
struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)>
183+
struct<id:int,(a + b):decimal(38,18),(a - b):decimal(38,18),(a * b):decimal(38,36),(a / b):decimal(38,18)>
200184
-- !query 21 output
201-
30.9
185+
1 1099 -899 NULL 0.1001001001001001
186+
2 24690.246 0 NULL 1
187+
3 1234.2234567891011 -1233.9765432108989 NULL 0.000100037913541123
188+
4 123456789123456790.123456789123456789 123456789123456787.876543210876543211 NULL 109890109097814272.043109406191131436
202189

203190

204191
-- !query 22
205-
select 10.3000 * 3.0
192+
select id, a*10, b/10 from decimals_test order by id
206193
-- !query 22 schema
207-
struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)>
194+
struct<id:int,(CAST(a AS DECIMAL(38,18)) * CAST(CAST(10 AS DECIMAL(2,0)) AS DECIMAL(38,18))):decimal(38,18),(CAST(b AS DECIMAL(38,18)) / CAST(CAST(10 AS DECIMAL(2,0)) AS DECIMAL(38,18))):decimal(38,19)>
208195
-- !query 22 output
209-
30.9
196+
1 1000 99.9
197+
2 123451.23 1234.5123
198+
3 1.234567891011 123.41
199+
4 1234567891234567890 0.1123456789123456789
210200

211201

212202
-- !query 23
213-
select 10.30000 * 30.0
203+
select 10.3 * 3.0
214204
-- !query 23 schema
215-
struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)>
205+
struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)>
216206
-- !query 23 output
217-
309
207+
30.9
218208

219209

220210
-- !query 24
221-
select 10.300000000000000000 * 3.000000000000000000
211+
select 10.3000 * 3.0
222212
-- !query 24 schema
223-
struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,34)>
213+
struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)>
224214
-- !query 24 output
225215
30.9
226216

227217

228218
-- !query 25
229-
select 10.300000000000000000 * 3.0000000000000000000
219+
select 10.30000 * 30.0
230220
-- !query 25 schema
231-
struct<(CAST(10.300000000000000000 AS DECIMAL(21,19)) * CAST(3.0000000000000000000 AS DECIMAL(21,19))):decimal(38,34)>
221+
struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)>
232222
-- !query 25 output
233-
30.9
223+
309
234224

235225

236226
-- !query 26
237-
select (5e36 + 0.1) + 5e36
227+
select 10.300000000000000000 * 3.000000000000000000
238228
-- !query 26 schema
239-
struct<(CAST((CAST(5E+36 AS DECIMAL(38,1)) + CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) + CAST(5E+36 AS DECIMAL(38,1))):decimal(38,1)>
229+
struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,36)>
240230
-- !query 26 output
241-
NULL
231+
30.9
242232

243233

244234
-- !query 27
245-
select (-4e36 - 0.1) - 7e36
235+
select 10.300000000000000000 * 3.0000000000000000000
246236
-- !query 27 schema
247-
struct<(CAST((CAST(-4E+36 AS DECIMAL(38,1)) - CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) - CAST(7E+36 AS DECIMAL(38,1))):decimal(38,1)>
237+
struct<(CAST(10.300000000000000000 AS DECIMAL(21,19)) * CAST(3.0000000000000000000 AS DECIMAL(21,19))):decimal(38,37)>
248238
-- !query 27 output
249239
NULL
250240

251241

252242
-- !query 28
253-
select 12345678901234567890.0 * 12345678901234567890.0
243+
select (5e36 + 0.1) + 5e36
254244
-- !query 28 schema
255-
struct<(12345678901234567890.0 * 12345678901234567890.0):decimal(38,2)>
245+
struct<(CAST((CAST(5E+36 AS DECIMAL(38,1)) + CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) + CAST(5E+36 AS DECIMAL(38,1))):decimal(38,1)>
256246
-- !query 28 output
257247
NULL
258248

259249

260250
-- !query 29
261-
select 1e35 / 0.1
251+
select (-4e36 - 0.1) - 7e36
262252
-- !query 29 schema
263-
struct<(CAST(1E+35 AS DECIMAL(37,1)) / CAST(0.1 AS DECIMAL(37,1))):decimal(38,6)>
253+
struct<(CAST((CAST(-4E+36 AS DECIMAL(38,1)) - CAST(0.1 AS DECIMAL(38,1))) AS DECIMAL(38,1)) - CAST(7E+36 AS DECIMAL(38,1))):decimal(38,1)>
264254
-- !query 29 output
265255
NULL
266256

267257

268258
-- !query 30
269-
select 123456789123456789.1234567890 * 1.123456789123456789
259+
select 12345678901234567890.0 * 12345678901234567890.0
270260
-- !query 30 schema
271-
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)>
261+
struct<(12345678901234567890.0 * 12345678901234567890.0):decimal(38,2)>
272262
-- !query 30 output
273-
138698367904130467.654320988515622621
263+
NULL
274264

275265

276266
-- !query 31
277-
select 0.001 / 9876543210987654321098765432109876543.2
278-
279-
drop table decimals_test
267+
select 1e35 / 0.1
280268
-- !query 31 schema
281-
struct<>
269+
struct<(CAST(1E+35 AS DECIMAL(37,1)) / CAST(0.1 AS DECIMAL(37,1))):decimal(38,3)>
282270
-- !query 31 output
283-
org.apache.spark.sql.catalyst.parser.ParseException
271+
NULL
284272

285-
mismatched input 'table' expecting <EOF>(line 3, pos 5)
286273

287-
== SQL ==
288-
select 0.001 / 9876543210987654321098765432109876543.2
274+
-- !query 32
275+
select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345
276+
-- !query 32 schema
277+
struct<(CAST(12345678912345678912345678912.1234567 AS DECIMAL(38,7)) + CAST(9999999999999999999999999999999.12345 AS DECIMAL(38,7))):decimal(38,7)>
278+
-- !query 32 output
279+
NULL
280+
281+
282+
-- !query 33
283+
select 123456789123456789.1234567890 * 1.123456789123456789
284+
-- !query 33 schema
285+
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,28)>
286+
-- !query 33 output
287+
NULL
288+
289289

290+
-- !query 34
291+
select 12345678912345.123456789123 / 0.000000012345678
292+
-- !query 34 schema
293+
struct<(CAST(12345678912345.123456789123 AS DECIMAL(29,15)) / CAST(1.2345678E-8 AS DECIMAL(29,15))):decimal(38,18)>
294+
-- !query 34 output
295+
NULL
296+
297+
298+
-- !query 35
290299
drop table decimals_test
291-
-----^^^
300+
-- !query 35 schema
301+
struct<>
302+
-- !query 35 output
303+

0 commit comments

Comments
 (0)