Skip to content

Commit b5a02d3

Browse files
maropucloud-fan
authored andcommitted
[SPARK-29873][SQL][TESTS] Support --import directive to load queries from another test case in SQLQueryTestSuite
### What changes were proposed in this pull request? This pr is to support `--import` directive to load queries from another test case in SQLQueryTestSuite. This fix comes from the cloud-fan suggestion in apache#26479 (comment) ### Why are the changes needed? This functionality might reduce duplicate test code in `SQLQueryTestSuite`. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Run `SQLQueryTestSuite`. Closes apache#26497 from maropu/ImportTests. Authored-by: Takeshi Yamamuro <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent fe1f456 commit b5a02d3

18 files changed

+1518
-869
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- SPARK-23179: SQL ANSI 2011 states that in case of overflow during arithmetic operations,
2+
-- an exception should be thrown instead of returning NULL.
3+
-- This is what most of the SQL DBs do (eg. SQLServer, DB2).
4+
5+
-- tests for decimals handling in operations
6+
create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet;
7+
8+
insert into decimals_test values(1, 100.0, 999.0), (2, 12345.123, 12345.123),
9+
(3, 0.1234567891011, 1234.1), (4, 123456789123456789.0, 1.123456789123456789);
10+
11+
-- test operations between decimals and constants
12+
select id, a*10, b/10 from decimals_test order by id;
13+
14+
-- test operations on constants
15+
select 10.3 * 3.0;
16+
select 10.3000 * 3.0;
17+
select 10.30000 * 30.0;
18+
select 10.300000000000000000 * 3.000000000000000000;
19+
select 10.300000000000000000 * 3.0000000000000000000;
20+
21+
-- arithmetic operations causing an overflow throw exception
22+
select (5e36 + 0.1) + 5e36;
23+
select (-4e36 - 0.1) - 7e36;
24+
select 12345678901234567890.0 * 12345678901234567890.0;
25+
select 1e35 / 0.1;
26+
27+
-- arithmetic operations causing a precision loss throw exception
28+
select 123456789123456789.1234567890 * 1.123456789123456789;
29+
select 123456789123456789.1234567890 * 1.123456789123456789;
30+
select 12345678912345.123456789123 / 0.000000012345678;
31+
32+
drop table decimals_test;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--import higher-order-functions.sql

sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
-- Turns on ANSI mode
2-
SET spark.sql.ansi.enabled=true;
3-
41
select
52
'1' second,
63
2 seconds,
@@ -184,5 +181,7 @@ select date '2012-01-01' + interval (a + 1) day from t;
184181

185182
select date '2012-01-01' + (a + 1) day from t;
186183

187-
-- Turns off ANSI mode
188-
SET spark.sql.ansi.enabled=false;
184+
-- malformed interval literal with ansi mode
185+
select 1 year to month;
186+
select '1' year to second;
187+
select 1 year '2-1' year to month;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--- malformed interval literal with ansi mode
2+
--import literals.sql

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,4 @@ select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.1
8383
select 123456789123456789.1234567890 * 1.123456789123456789;
8484
select 12345678912345.123456789123 / 0.000000012345678;
8585

86-
-- throw an exception instead of returning NULL, according to SQL ANSI 2011
87-
set spark.sql.ansi.enabled=true;
88-
89-
-- test operations between decimals and constants
90-
select id, a*10, b/10 from decimals_test order by id;
91-
92-
-- test operations on constants
93-
select 10.3 * 3.0;
94-
select 10.3000 * 3.0;
95-
select 10.30000 * 30.0;
96-
select 10.300000000000000000 * 3.000000000000000000;
97-
select 10.300000000000000000 * 3.0000000000000000000;
98-
99-
-- arithmetic operations causing an overflow throw exception
100-
select (5e36 + 0.1) + 5e36;
101-
select (-4e36 - 0.1) - 7e36;
102-
select 12345678901234567890.0 * 12345678901234567890.0;
103-
select 1e35 / 0.1;
104-
105-
-- arithmetic operations causing a precision loss throw exception
106-
select 123456789123456789.1234567890 * 1.123456789123456789;
107-
select 123456789123456789.1234567890 * 1.123456789123456789;
108-
select 12345678912345.123456789123 / 0.000000012345678;
109-
11086
drop table decimals_test;

sql/core/src/test/resources/sql-tests/inputs/higher-order-functions.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,3 @@ select transform_values(ys, (k, v) -> k + v) as v from nested;
8787
-- use non reversed keywords: all is non reversed only if !ansi
8888
select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys);
8989
select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys);
90-
91-
set spark.sql.ansi.enabled=true;
92-
select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys);
93-
select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys);
94-
set spark.sql.ansi.enabled=false;

sql/core/src/test/resources/sql-tests/inputs/interval.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,46 @@ select justify_interval(interval '1 month -59 day 25 hour');
8888
select justify_days(interval '1 month 59 day -25 hour');
8989
select justify_hours(interval '1 month 59 day -25 hour');
9090
select justify_interval(interval '1 month 59 day -25 hour');
91+
92+
-- interval
93+
select interval 13.123456789 seconds, interval -13.123456789 second;
94+
select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond;
95+
select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second;
96+
select interval '0 0:0:0.1' day to second;
97+
select interval '10-9' year to month;
98+
select interval '20 15:40:32.99899999' day to hour;
99+
select interval '20 15:40:32.99899999' day to minute;
100+
select interval '20 15:40:32.99899999' day to second;
101+
select interval '15:40:32.99899999' hour to minute;
102+
select interval '15:40.99899999' hour to second;
103+
select interval '15:40' hour to second;
104+
select interval '15:40:32.99899999' hour to second;
105+
select interval '20 40:32.99899999' minute to second;
106+
select interval '40:32.99899999' minute to second;
107+
select interval '40:32' minute to second;
108+
109+
-- ns is not supported
110+
select interval 10 nanoseconds;
111+
112+
-- map + interval test
113+
select map(1, interval 1 day, 2, interval 3 week);
114+
115+
-- typed interval expression
116+
select interval 'interval 3 year 1 hour';
117+
select interval '3 year 1 hour';
118+
119+
-- malformed interval literal
120+
select interval;
121+
select interval 1 fake_unit;
122+
select interval 1 year to month;
123+
select interval '1' year to second;
124+
select interval '10-9' year to month '2-1' year to month;
125+
select interval '10-9' year to month '12:11:10' hour to second;
126+
select interval '1 15:11' day to minute '12:11:10' hour to second;
127+
select interval 1 year '2-1' year to month;
128+
select interval 1 year '12:11:10' hour to second;
129+
select interval '10-9' year to month '1' year;
130+
select interval '12:11:10' hour to second '1' year;
131+
132+
-- awareness of the positive sign before interval type
133+
select +interval '1 second';

sql/core/src/test/resources/sql-tests/inputs/literals.sql

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,6 @@ select tImEstAmp '2016-03-11 20:54:00.000';
8282
-- invalid timestamp
8383
select timestamp '2016-33-11 20:54:00.000';
8484

85-
-- interval
86-
select interval 13.123456789 seconds, interval -13.123456789 second;
87-
select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond;
88-
select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second;
89-
select interval '0 0:0:0.1' day to second;
90-
select interval '10-9' year to month;
91-
select interval '20 15:40:32.99899999' day to hour;
92-
select interval '20 15:40:32.99899999' day to minute;
93-
select interval '20 15:40:32.99899999' day to second;
94-
select interval '15:40:32.99899999' hour to minute;
95-
select interval '15:40.99899999' hour to second;
96-
select interval '15:40' hour to second;
97-
select interval '15:40:32.99899999' hour to second;
98-
select interval '20 40:32.99899999' minute to second;
99-
select interval '40:32.99899999' minute to second;
100-
select interval '40:32' minute to second;
101-
-- ns is not supported
102-
select interval 10 nanoseconds;
103-
10485
-- unsupported data type
10586
select GEO '(10,-6)';
10687

@@ -119,46 +100,14 @@ select X'XuZ';
119100
-- Hive literal_double test.
120101
SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8;
121102

122-
-- map + interval test
123-
select map(1, interval 1 day, 2, interval 3 week);
124-
125-
-- typed interval expression
126-
select interval 'interval 3 year 1 hour';
127-
select interval '3 year 1 hour';
128-
129103
-- typed integer expression
130104
select integer '7';
131105
select integer'7';
132106
select integer '2147483648';
133107

134-
-- malformed interval literal
135-
select interval;
136-
select interval 1 fake_unit;
137-
select interval 1 year to month;
138-
select interval '1' year to second;
139-
select interval '10-9' year to month '2-1' year to month;
140-
select interval '10-9' year to month '12:11:10' hour to second;
141-
select interval '1 15:11' day to minute '12:11:10' hour to second;
142-
select interval 1 year '2-1' year to month;
143-
select interval 1 year '12:11:10' hour to second;
144-
select interval '10-9' year to month '1' year;
145-
select interval '12:11:10' hour to second '1' year;
146-
-- malformed interval literal with ansi mode
147-
SET spark.sql.ansi.enabled=true;
148-
select interval;
149-
select interval 1 fake_unit;
150-
select interval 1 year to month;
151-
select 1 year to month;
152-
select interval '1' year to second;
153-
select '1' year to second;
154-
select interval 1 year '2-1' year to month;
155-
select 1 year '2-1' year to month;
156-
SET spark.sql.ansi.enabled=false;
157-
158-
-- awareness of the negative sign before type
108+
-- awareness of the negative/positive sign before type
159109
select -integer '7';
160110
select -date '1999-01-01';
161111
select -timestamp '1999-01-01';
162112
select -x'2379ACFe';
163113
select +integer '7';
164-
select +interval '1 second';
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
-- Automatically generated by SQLQueryTestSuite
2+
-- Number of queries: 16
3+
4+
5+
-- !query 0
6+
create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet
7+
-- !query 0 schema
8+
struct<>
9+
-- !query 0 output
10+
11+
12+
13+
-- !query 1
14+
insert into decimals_test values(1, 100.0, 999.0), (2, 12345.123, 12345.123),
15+
(3, 0.1234567891011, 1234.1), (4, 123456789123456789.0, 1.123456789123456789)
16+
-- !query 1 schema
17+
struct<>
18+
-- !query 1 output
19+
20+
21+
22+
-- !query 2
23+
select id, a*10, b/10 from decimals_test order by id
24+
-- !query 2 schema
25+
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)>
26+
-- !query 2 output
27+
1 1000 99.9
28+
2 123451.23 1234.5123
29+
3 1.234567891011 123.41
30+
4 1234567891234567890 0.112345678912345679
31+
32+
33+
-- !query 3
34+
select 10.3 * 3.0
35+
-- !query 3 schema
36+
struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)>
37+
-- !query 3 output
38+
30.9
39+
40+
41+
-- !query 4
42+
select 10.3000 * 3.0
43+
-- !query 4 schema
44+
struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)>
45+
-- !query 4 output
46+
30.9
47+
48+
49+
-- !query 5
50+
select 10.30000 * 30.0
51+
-- !query 5 schema
52+
struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)>
53+
-- !query 5 output
54+
309
55+
56+
57+
-- !query 6
58+
select 10.300000000000000000 * 3.000000000000000000
59+
-- !query 6 schema
60+
struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,34)>
61+
-- !query 6 output
62+
30.9
63+
64+
65+
-- !query 7
66+
select 10.300000000000000000 * 3.0000000000000000000
67+
-- !query 7 schema
68+
struct<(CAST(10.300000000000000000 AS DECIMAL(21,19)) * CAST(3.0000000000000000000 AS DECIMAL(21,19))):decimal(38,34)>
69+
-- !query 7 output
70+
30.9
71+
72+
73+
-- !query 8
74+
select (5e36 + 0.1) + 5e36
75+
-- !query 8 schema
76+
struct<>
77+
-- !query 8 output
78+
java.lang.ArithmeticException
79+
Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1).
80+
81+
82+
-- !query 9
83+
select (-4e36 - 0.1) - 7e36
84+
-- !query 9 schema
85+
struct<>
86+
-- !query 9 output
87+
java.lang.ArithmeticException
88+
Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1).
89+
90+
91+
-- !query 10
92+
select 12345678901234567890.0 * 12345678901234567890.0
93+
-- !query 10 schema
94+
struct<>
95+
-- !query 10 output
96+
java.lang.ArithmeticException
97+
Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2).
98+
99+
100+
-- !query 11
101+
select 1e35 / 0.1
102+
-- !query 11 schema
103+
struct<>
104+
-- !query 11 output
105+
java.lang.ArithmeticException
106+
Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 6).
107+
108+
109+
-- !query 12
110+
select 123456789123456789.1234567890 * 1.123456789123456789
111+
-- !query 12 schema
112+
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)>
113+
-- !query 12 output
114+
138698367904130467.654320988515622621
115+
116+
117+
-- !query 13
118+
select 123456789123456789.1234567890 * 1.123456789123456789
119+
-- !query 13 schema
120+
struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)>
121+
-- !query 13 output
122+
138698367904130467.654320988515622621
123+
124+
125+
-- !query 14
126+
select 12345678912345.123456789123 / 0.000000012345678
127+
-- !query 14 schema
128+
struct<(CAST(12345678912345.123456789123 AS DECIMAL(29,15)) / CAST(1.2345678E-8 AS DECIMAL(29,15))):decimal(38,9)>
129+
-- !query 14 output
130+
1000000073899961059796.725866332
131+
132+
133+
-- !query 15
134+
drop table decimals_test
135+
-- !query 15 schema
136+
struct<>
137+
-- !query 15 output
138+

0 commit comments

Comments
 (0)