Skip to content

Commit 4b86510

Browse files
chitralvermaHyukjinKwon
authored andcommitted
[SPARK-28286][SQL][PYTHON][TESTS] Convert and port 'pivot.sql' into UDF test base
## What changes were proposed in this pull request? This PR adds some tests converted from pivot.sql to test UDFs following the combination guide in [SPARK-27921](https://issues.apache.org/jira/browse/SPARK-27921). <details><summary>Diff comparing to 'pivot.sql'</summary> <p> ```diff diff --git a/sql/core/src/test/resources/sql-tests/results/pivot.sql.out b/sql/core/src/test/resources/sql-tests/results/udf/udf-pivot.sql.out index 9a8f783..cb9e4d7 100644 --- a/sql/core/src/test/resources/sql-tests/results/pivot.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/udf/udf-pivot.sql.out -1,5 +1,5 -- Automatically generated by SQLQueryTestSuite --- Number of queries: 32 +-- Number of queries: 30 -- !query 0 -40,14 +40,14 struct<> -- !query 3 SELECT * FROM ( - SELECT year, course, earnings FROM courseSales + SELECT udf(year), course, earnings FROM courseSales ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR course IN ('dotNET', 'Java') ) -- !query 3 schema -struct<year:int,dotNET:bigint,Java:bigint> +struct<CAST(udf(cast(year as string)) AS INT):int,dotNET:bigint,Java:bigint> -- !query 3 output 2012 15000 20000 2013 48000 30000 -56,7 +56,7 struct<year:int,dotNET:bigint,Java:bigint> -- !query 4 SELECT * FROM courseSales PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR year IN (2012, 2013) ) -- !query 4 schema -71,11 +71,11 SELECT * FROM ( SELECT year, course, earnings FROM courseSales ) PIVOT ( - sum(earnings), avg(earnings) + udf(sum(earnings)), udf(avg(earnings)) FOR course IN ('dotNET', 'Java') ) -- !query 5 schema -struct<year:int,dotNET_sum(CAST(earnings AS BIGINT)):bigint,dotNET_avg(CAST(earnings AS BIGINT)):double,Java_sum(CAST(earnings AS BIGINT)):bigint,Java_avg(CAST(earnings AS BIGINT)):double> +struct<year:int,dotNET_CAST(udf(cast(sum(cast(earnings as bigint)) as string)) AS BIGINT):bigint,dotNET_CAST(udf(cast(avg(cast(earnings as bigint)) as string)) AS DOUBLE):double,Java_CAST(udf(cast(sum(cast(earnings as bigint)) as string)) AS BIGINT):bigint,Java_CAST(udf(cast(avg(cast(earnings as bigint)) as string)) AS DOUBLE):double> -- !query 5 output 2012 15000 7500.0 20000 20000.0 2013 48000 48000.0 30000 30000.0 -83,10 +83,10 struct<year:int,dotNET_sum(CAST(earnings AS BIGINT)):bigint,dotNET_avg(CAST(earn -- !query 6 SELECT * FROM ( - SELECT course, earnings FROM courseSales + SELECT udf(course) as course, earnings FROM courseSales ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR course IN ('dotNET', 'Java') ) -- !query 6 schema -100,23 +100,23 SELECT * FROM ( SELECT year, course, earnings FROM courseSales ) PIVOT ( - sum(earnings), min(year) + udf(sum(udf(earnings))), udf(min(year)) FOR course IN ('dotNET', 'Java') ) -- !query 7 schema -struct<dotNET_sum(CAST(earnings AS BIGINT)):bigint,dotNET_min(year):int,Java_sum(CAST(earnings AS BIGINT)):bigint,Java_min(year):int> +struct<dotNET_CAST(udf(cast(sum(cast(cast(udf(cast(earnings as string)) as int) as bigint)) as string)) AS BIGINT):bigint,dotNET_CAST(udf(cast(min(year) as string)) AS INT):int,Java_CAST(udf(cast(sum(cast(cast(udf(cast(earnings as string)) as int) as bigint)) as string)) AS BIGINT):bigint,Java_CAST(udf(cast(min(year) as string)) AS INT):int> -- !query 7 output 63000 2012 50000 2012 -- !query 8 SELECT * FROM ( - SELECT course, year, earnings, s + SELECT course, year, earnings, udf(s) as s FROM courseSales JOIN years ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR s IN (1, 2) ) -- !query 8 schema -135,11 +135,11 SELECT * FROM ( JOIN years ON year = y ) PIVOT ( - sum(earnings), min(s) + udf(sum(earnings)), udf(min(s)) FOR course IN ('dotNET', 'Java') ) -- !query 9 schema -struct<year:int,dotNET_sum(CAST(earnings AS BIGINT)):bigint,dotNET_min(s):int,Java_sum(CAST(earnings AS BIGINT)):bigint,Java_min(s):int> +struct<year:int,dotNET_CAST(udf(cast(sum(cast(earnings as bigint)) as string)) AS BIGINT):bigint,dotNET_CAST(udf(cast(min(s) as string)) AS INT):int,Java_CAST(udf(cast(sum(cast(earnings as bigint)) as string)) AS BIGINT):bigint,Java_CAST(udf(cast(min(s) as string)) AS INT):int> -- !query 9 output 2012 15000 1 20000 1 2013 48000 2 30000 2 -152,7 +152,7 SELECT * FROM ( JOIN years ON year = y ) PIVOT ( - sum(earnings * s) + udf(sum(earnings * s)) FOR course IN ('dotNET', 'Java') ) -- !query 10 schema -167,7 +167,7 SELECT 2012_s, 2013_s, 2012_a, 2013_a, c FROM ( SELECT year y, course c, earnings e FROM courseSales ) PIVOT ( - sum(e) s, avg(e) a + udf(sum(e)) s, udf(avg(e)) a FOR y IN (2012, 2013) ) -- !query 11 schema -182,7 +182,7 SELECT firstYear_s, secondYear_s, firstYear_a, secondYear_a, c FROM ( SELECT year y, course c, earnings e FROM courseSales ) PIVOT ( - sum(e) s, avg(e) a + udf(sum(e)) s, udf(avg(e)) a FOR y IN (2012 as firstYear, 2013 secondYear) ) -- !query 12 schema -195,7 +195,7 struct<firstYear_s:bigint,secondYear_s:bigint,firstYear_a:double,secondYear_a:do -- !query 13 SELECT * FROM courseSales PIVOT ( - abs(earnings) + udf(abs(earnings)) FOR year IN (2012, 2013) ) -- !query 13 schema -210,7 +210,7 SELECT * FROM ( SELECT year, course, earnings FROM courseSales ) PIVOT ( - sum(earnings), year + udf(sum(earnings)), year FOR course IN ('dotNET', 'Java') ) -- !query 14 schema -225,7 +225,7 SELECT * FROM ( SELECT course, earnings FROM courseSales ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR year IN (2012, 2013) ) -- !query 15 schema -240,11 +240,11 SELECT * FROM ( SELECT year, course, earnings FROM courseSales ) PIVOT ( - ceil(sum(earnings)), avg(earnings) + 1 as a1 + udf(ceil(udf(sum(earnings)))), avg(earnings) + 1 as a1 FOR course IN ('dotNET', 'Java') ) -- !query 16 schema -struct<year:int,dotNET_CEIL(sum(CAST(earnings AS BIGINT))):bigint,dotNET_a1:double,Java_CEIL(sum(CAST(earnings AS BIGINT))):bigint,Java_a1:double> +struct<year:int,dotNET_CAST(udf(cast(CEIL(cast(udf(cast(sum(cast(earnings as bigint)) as string)) as bigint)) as string)) AS BIGINT):bigint,dotNET_a1:double,Java_CAST(udf(cast(CEIL(cast(udf(cast(sum(cast(earnings as bigint)) as string)) as bigint)) as string)) AS BIGINT):bigint,Java_a1:double> -- !query 16 output 2012 15000 7501.0 20000 20001.0 2013 48000 48001.0 30000 30001.0 -255,7 +255,7 SELECT * FROM ( SELECT year, course, earnings FROM courseSales ) PIVOT ( - sum(avg(earnings)) + sum(udf(avg(earnings))) FOR course IN ('dotNET', 'Java') ) -- !query 17 schema -272,7 +272,7 SELECT * FROM ( JOIN years ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, year) IN (('dotNET', 2012), ('Java', 2013)) ) -- !query 18 schema -289,7 +289,7 SELECT * FROM ( JOIN years ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, s) IN (('dotNET', 2) as c1, ('Java', 1) as c2) ) -- !query 19 schema -306,7 +306,7 SELECT * FROM ( JOIN years ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, year) IN ('dotNET', 'Java') ) -- !query 20 schema -319,7 +319,7 Invalid pivot value 'dotNET': value data type string does not match pivot column -- !query 21 SELECT * FROM courseSales PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR year IN (s, 2013) ) -- !query 21 schema -332,7 +332,7 cannot resolve '`s`' given input columns: [coursesales.course, coursesales.earni -- !query 22 SELECT * FROM courseSales PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR year IN (course, 2013) ) -- !query 22 schema -343,151 +343,118 Literal expressions required for pivot values, found 'course#x'; -- !query 23 -SELECT * FROM ( - SELECT course, year, a - FROM courseSales - JOIN yearsWithComplexTypes ON year = y -) -PIVOT ( - min(a) - FOR course IN ('dotNET', 'Java') -) --- !query 23 schema -struct<year:int,dotNET:array<int>,Java:array<int>> --- !query 23 output -2012 [1,1] [1,1] -2013 [2,2] [2,2] - - --- !query 24 -SELECT * FROM ( - SELECT course, year, y, a - FROM courseSales - JOIN yearsWithComplexTypes ON year = y -) -PIVOT ( - max(a) - FOR (y, course) IN ((2012, 'dotNET'), (2013, 'Java')) -) --- !query 24 schema -struct<year:int,[2012, dotNET]:array<int>,[2013, Java]:array<int>> --- !query 24 output -2012 [1,1] NULL -2013 NULL [2,2] - - --- !query 25 SELECT * FROM ( SELECT earnings, year, a FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR a IN (array(1, 1), array(2, 2)) ) --- !query 25 schema +-- !query 23 schema struct<year:int,[1, 1]:bigint,[2, 2]:bigint> --- !query 25 output +-- !query 23 output 2012 35000 NULL 2013 NULL 78000 --- !query 26 +-- !query 24 SELECT * FROM ( - SELECT course, earnings, year, a + SELECT course, earnings, udf(year) as year, a FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, a) IN (('dotNET', array(1, 1)), ('Java', array(2, 2))) ) --- !query 26 schema +-- !query 24 schema struct<year:int,[dotNET, [1, 1]]:bigint,[Java, [2, 2]]:bigint> --- !query 26 output +-- !query 24 output 2012 15000 NULL 2013 NULL 30000 --- !query 27 +-- !query 25 SELECT * FROM ( SELECT earnings, year, s FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR s IN ((1, 'a'), (2, 'b')) ) --- !query 27 schema +-- !query 25 schema struct<year:int,[1, a]:bigint,[2, b]:bigint> --- !query 27 output +-- !query 25 output 2012 35000 NULL 2013 NULL 78000 --- !query 28 +-- !query 26 SELECT * FROM ( SELECT course, earnings, year, s FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, s) IN (('dotNET', (1, 'a')), ('Java', (2, 'b'))) ) --- !query 28 schema +-- !query 26 schema struct<year:int,[dotNET, [1, a]]:bigint,[Java, [2, b]]:bigint> --- !query 28 output +-- !query 26 output 2012 15000 NULL 2013 NULL 30000 --- !query 29 +-- !query 27 SELECT * FROM ( SELECT earnings, year, m FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR m IN (map('1', 1), map('2', 2)) ) --- !query 29 schema +-- !query 27 schema struct<> --- !query 29 output +-- !query 27 output org.apache.spark.sql.AnalysisException Invalid pivot column 'm#x'. Pivot columns must be comparable.; --- !query 30 +-- !query 28 SELECT * FROM ( SELECT course, earnings, year, m FROM courseSales JOIN yearsWithComplexTypes ON year = y ) PIVOT ( - sum(earnings) + udf(sum(earnings)) FOR (course, m) IN (('dotNET', map('1', 1)), ('Java', map('2', 2))) ) --- !query 30 schema +-- !query 28 schema struct<> --- !query 30 output +-- !query 28 output org.apache.spark.sql.AnalysisException Invalid pivot column 'named_struct(course, course#x, m, m#x)'. Pivot columns must be comparable.; --- !query 31 +-- !query 29 SELECT * FROM ( - SELECT course, earnings, "a" as a, "z" as z, "b" as b, "y" as y, "c" as c, "x" as x, "d" as d, "w" as w + SELECT course, earnings, udf("a") as a, udf("z") as z, udf("b") as b, udf("y") as y, + udf("c") as c, udf("x") as x, udf("d") as d, udf("w") as w FROM courseSales ) PIVOT ( - sum(Earnings) + udf(sum(Earnings)) FOR Course IN ('dotNET', 'Java') ) --- !query 31 schema +-- !query 29 schema struct<a:string,z:string,b:string,y:string,c:string,x:string,d:string,w:string,dotNET:bigint,Java:bigint> --- !query 31 output +-- !query 29 output a z b y c x d w 63000 50000 ``` </p> </details> ## How was this patch tested? Tested as guided in [SPARK-27921](https://issues.apache.org/jira/browse/SPARK-27921). Closes apache#25122 from chitralverma/SPARK-28286. Authored-by: chitralverma <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
1 parent eaaf1aa commit 4b86510

File tree

2 files changed

+767
-0
lines changed

2 files changed

+767
-0
lines changed
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
-- This test file was converted from pivot.sql.
2+
3+
-- Note some test cases have been commented as the current integrated UDFs cannot handle complex types
4+
5+
create temporary view courseSales as select * from values
6+
("dotNET", 2012, 10000),
7+
("Java", 2012, 20000),
8+
("dotNET", 2012, 5000),
9+
("dotNET", 2013, 48000),
10+
("Java", 2013, 30000)
11+
as courseSales(course, year, earnings);
12+
13+
create temporary view years as select * from values
14+
(2012, 1),
15+
(2013, 2)
16+
as years(y, s);
17+
18+
create temporary view yearsWithComplexTypes as select * from values
19+
(2012, array(1, 1), map('1', 1), struct(1, 'a')),
20+
(2013, array(2, 2), map('2', 2), struct(2, 'b'))
21+
as yearsWithComplexTypes(y, a, m, s);
22+
23+
-- pivot courses
24+
SELECT * FROM (
25+
SELECT udf(year), course, earnings FROM courseSales
26+
)
27+
PIVOT (
28+
udf(sum(earnings))
29+
FOR course IN ('dotNET', 'Java')
30+
);
31+
32+
-- pivot years with no subquery
33+
SELECT * FROM courseSales
34+
PIVOT (
35+
udf(sum(earnings))
36+
FOR year IN (2012, 2013)
37+
);
38+
39+
-- pivot courses with multiple aggregations
40+
SELECT * FROM (
41+
SELECT year, course, earnings FROM courseSales
42+
)
43+
PIVOT (
44+
udf(sum(earnings)), udf(avg(earnings))
45+
FOR course IN ('dotNET', 'Java')
46+
);
47+
48+
-- pivot with no group by column
49+
SELECT * FROM (
50+
SELECT udf(course) as course, earnings FROM courseSales
51+
)
52+
PIVOT (
53+
udf(sum(earnings))
54+
FOR course IN ('dotNET', 'Java')
55+
);
56+
57+
-- pivot with no group by column and with multiple aggregations on different columns
58+
SELECT * FROM (
59+
SELECT year, course, earnings FROM courseSales
60+
)
61+
PIVOT (
62+
udf(sum(udf(earnings))), udf(min(year))
63+
FOR course IN ('dotNET', 'Java')
64+
);
65+
66+
-- pivot on join query with multiple group by columns
67+
SELECT * FROM (
68+
SELECT course, year, earnings, udf(s) as s
69+
FROM courseSales
70+
JOIN years ON year = y
71+
)
72+
PIVOT (
73+
udf(sum(earnings))
74+
FOR s IN (1, 2)
75+
);
76+
77+
-- pivot on join query with multiple aggregations on different columns
78+
SELECT * FROM (
79+
SELECT course, year, earnings, s
80+
FROM courseSales
81+
JOIN years ON year = y
82+
)
83+
PIVOT (
84+
udf(sum(earnings)), udf(min(s))
85+
FOR course IN ('dotNET', 'Java')
86+
);
87+
88+
-- pivot on join query with multiple columns in one aggregation
89+
SELECT * FROM (
90+
SELECT course, year, earnings, s
91+
FROM courseSales
92+
JOIN years ON year = y
93+
)
94+
PIVOT (
95+
udf(sum(earnings * s))
96+
FOR course IN ('dotNET', 'Java')
97+
);
98+
99+
-- pivot with aliases and projection
100+
SELECT 2012_s, 2013_s, 2012_a, 2013_a, c FROM (
101+
SELECT year y, course c, earnings e FROM courseSales
102+
)
103+
PIVOT (
104+
udf(sum(e)) s, udf(avg(e)) a
105+
FOR y IN (2012, 2013)
106+
);
107+
108+
-- pivot with projection and value aliases
109+
SELECT firstYear_s, secondYear_s, firstYear_a, secondYear_a, c FROM (
110+
SELECT year y, course c, earnings e FROM courseSales
111+
)
112+
PIVOT (
113+
udf(sum(e)) s, udf(avg(e)) a
114+
FOR y IN (2012 as firstYear, 2013 secondYear)
115+
);
116+
117+
-- pivot years with non-aggregate function
118+
SELECT * FROM courseSales
119+
PIVOT (
120+
udf(abs(earnings))
121+
FOR year IN (2012, 2013)
122+
);
123+
124+
-- pivot with one of the expressions as non-aggregate function
125+
SELECT * FROM (
126+
SELECT year, course, earnings FROM courseSales
127+
)
128+
PIVOT (
129+
udf(sum(earnings)), year
130+
FOR course IN ('dotNET', 'Java')
131+
);
132+
133+
-- pivot with unresolvable columns
134+
SELECT * FROM (
135+
SELECT course, earnings FROM courseSales
136+
)
137+
PIVOT (
138+
udf(sum(earnings))
139+
FOR year IN (2012, 2013)
140+
);
141+
142+
-- pivot with complex aggregate expressions
143+
SELECT * FROM (
144+
SELECT year, course, earnings FROM courseSales
145+
)
146+
PIVOT (
147+
udf(ceil(udf(sum(earnings)))), avg(earnings) + 1 as a1
148+
FOR course IN ('dotNET', 'Java')
149+
);
150+
151+
-- pivot with invalid arguments in aggregate expressions
152+
SELECT * FROM (
153+
SELECT year, course, earnings FROM courseSales
154+
)
155+
PIVOT (
156+
sum(udf(avg(earnings)))
157+
FOR course IN ('dotNET', 'Java')
158+
);
159+
160+
-- pivot on multiple pivot columns
161+
SELECT * FROM (
162+
SELECT course, year, earnings, s
163+
FROM courseSales
164+
JOIN years ON year = y
165+
)
166+
PIVOT (
167+
udf(sum(earnings))
168+
FOR (course, year) IN (('dotNET', 2012), ('Java', 2013))
169+
);
170+
171+
-- pivot on multiple pivot columns with aliased values
172+
SELECT * FROM (
173+
SELECT course, year, earnings, s
174+
FROM courseSales
175+
JOIN years ON year = y
176+
)
177+
PIVOT (
178+
udf(sum(earnings))
179+
FOR (course, s) IN (('dotNET', 2) as c1, ('Java', 1) as c2)
180+
);
181+
182+
-- pivot on multiple pivot columns with values of wrong data types
183+
SELECT * FROM (
184+
SELECT course, year, earnings, s
185+
FROM courseSales
186+
JOIN years ON year = y
187+
)
188+
PIVOT (
189+
udf(sum(earnings))
190+
FOR (course, year) IN ('dotNET', 'Java')
191+
);
192+
193+
-- pivot with unresolvable values
194+
SELECT * FROM courseSales
195+
PIVOT (
196+
udf(sum(earnings))
197+
FOR year IN (s, 2013)
198+
);
199+
200+
-- pivot with non-literal values
201+
SELECT * FROM courseSales
202+
PIVOT (
203+
udf(sum(earnings))
204+
FOR year IN (course, 2013)
205+
);
206+
207+
-- Complex type is not supported in the current UDF. Skipped for now.
208+
-- pivot on join query with columns of complex data types
209+
-- SELECT * FROM (
210+
-- SELECT course, year, a
211+
-- FROM courseSales
212+
-- JOIN yearsWithComplexTypes ON year = y
213+
--)
214+
--PIVOT (
215+
-- udf(min(a))
216+
-- FOR course IN ('dotNET', 'Java')
217+
--);
218+
219+
-- Complex type is not supported in the current UDF. Skipped for now.
220+
-- pivot on multiple pivot columns with agg columns of complex data types
221+
-- SELECT * FROM (
222+
-- SELECT course, year, y, a
223+
-- FROM courseSales
224+
-- JOIN yearsWithComplexTypes ON year = y
225+
--)
226+
--PIVOT (
227+
-- udf(max(a))
228+
-- FOR (y, course) IN ((2012, 'dotNET'), (2013, 'Java'))
229+
--);
230+
231+
-- pivot on pivot column of array type
232+
SELECT * FROM (
233+
SELECT earnings, year, a
234+
FROM courseSales
235+
JOIN yearsWithComplexTypes ON year = y
236+
)
237+
PIVOT (
238+
udf(sum(earnings))
239+
FOR a IN (array(1, 1), array(2, 2))
240+
);
241+
242+
-- pivot on multiple pivot columns containing array type
243+
SELECT * FROM (
244+
SELECT course, earnings, udf(year) as year, a
245+
FROM courseSales
246+
JOIN yearsWithComplexTypes ON year = y
247+
)
248+
PIVOT (
249+
udf(sum(earnings))
250+
FOR (course, a) IN (('dotNET', array(1, 1)), ('Java', array(2, 2)))
251+
);
252+
253+
-- pivot on pivot column of struct type
254+
SELECT * FROM (
255+
SELECT earnings, year, s
256+
FROM courseSales
257+
JOIN yearsWithComplexTypes ON year = y
258+
)
259+
PIVOT (
260+
udf(sum(earnings))
261+
FOR s IN ((1, 'a'), (2, 'b'))
262+
);
263+
264+
-- pivot on multiple pivot columns containing struct type
265+
SELECT * FROM (
266+
SELECT course, earnings, year, s
267+
FROM courseSales
268+
JOIN yearsWithComplexTypes ON year = y
269+
)
270+
PIVOT (
271+
udf(sum(earnings))
272+
FOR (course, s) IN (('dotNET', (1, 'a')), ('Java', (2, 'b')))
273+
);
274+
275+
-- pivot on pivot column of map type
276+
SELECT * FROM (
277+
SELECT earnings, year, m
278+
FROM courseSales
279+
JOIN yearsWithComplexTypes ON year = y
280+
)
281+
PIVOT (
282+
udf(sum(earnings))
283+
FOR m IN (map('1', 1), map('2', 2))
284+
);
285+
286+
-- pivot on multiple pivot columns containing map type
287+
SELECT * FROM (
288+
SELECT course, earnings, year, m
289+
FROM courseSales
290+
JOIN yearsWithComplexTypes ON year = y
291+
)
292+
PIVOT (
293+
udf(sum(earnings))
294+
FOR (course, m) IN (('dotNET', map('1', 1)), ('Java', map('2', 2)))
295+
);
296+
297+
-- grouping columns output in the same order as input
298+
-- correctly handle pivot columns with different cases
299+
SELECT * FROM (
300+
SELECT course, earnings, udf("a") as a, udf("z") as z, udf("b") as b, udf("y") as y,
301+
udf("c") as c, udf("x") as x, udf("d") as d, udf("w") as w
302+
FROM courseSales
303+
)
304+
PIVOT (
305+
udf(sum(Earnings))
306+
FOR Course IN ('dotNET', 'Java')
307+
);

0 commit comments

Comments
 (0)