Skip to content

Commit 92bfd02

Browse files
mihailoale-dbcloud-fan
authored andcommitted
[SPARK-52400][SQL][TESTS] Cover SQL test gaps in golden files
### What changes were proposed in this pull request? In this PR I propose that we cover test gaps discovered during single-pass Analyzer implementation. ### Why are the changes needed? To make Spark test coverage better. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? New tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51088 from mihailoale-db/goldenfiles1. Authored-by: mihailoale-db <mihailo.aleksic@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 79893b4 commit 92bfd02

23 files changed

+3065
-0
lines changed

sql/core/src/test/resources/sql-tests/analyzer-results/generators.sql.out

Lines changed: 947 additions & 0 deletions
Large diffs are not rendered by default.

sql/core/src/test/resources/sql-tests/analyzer-results/group-by-alias.sql.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,60 @@ Aggregate [scalar-subquery#x []], [scalar-subquery#x [] AS subq1#x]
411411
+- LocalRelation [col1#x]
412412

413413

414+
-- !query
415+
SELECT 111 AS abc GROUP BY 'a', abc
416+
-- !query analysis
417+
Aggregate [a, 111], [111 AS abc#x]
418+
+- OneRowRelation
419+
420+
421+
-- !query
422+
SELECT *, 111 AS abc FROM VALUES ('a', 'b', 'c') GROUP BY col1, col2, col3, abc
423+
-- !query analysis
424+
Aggregate [col1#x, col2#x, col3#x, 111], [col1#x, col2#x, col3#x, 111 AS abc#x]
425+
+- LocalRelation [col1#x, col2#x, col3#x]
426+
427+
428+
-- !query
429+
SELECT col1 as a, col2 AS a FROM values('a','b') GROUP BY col2, a
430+
-- !query analysis
431+
Aggregate [col2#x, col1#x], [col1#x AS a#x, col2#x AS a#x]
432+
+- LocalRelation [col1#x, col2#x]
433+
434+
435+
-- !query
436+
SELECT 1 AS a, 2 AS a FROM VALUES (1) t (a) GROUP BY a HAVING a > 1 ORDER BY a
437+
-- !query analysis
438+
Project [a#x, a#x]
439+
+- Sort [a#x ASC NULLS FIRST], true
440+
+- Project [a#x, a#x, a#x]
441+
+- Filter (a#x > a#x)
442+
+- Aggregate [a#x], [1 AS a#x, 2 AS a#x, a#x]
443+
+- SubqueryAlias t
444+
+- LocalRelation [a#x]
445+
446+
447+
-- !query
448+
SELECT 1 AS a, 2 AS a FROM VALUES (1) t (col1) GROUP BY a HAVING a > 1 ORDER BY a
449+
-- !query analysis
450+
org.apache.spark.sql.AnalysisException
451+
{
452+
"errorClass" : "AMBIGUOUS_REFERENCE",
453+
"sqlState" : "42704",
454+
"messageParameters" : {
455+
"name" : "`a`",
456+
"referenceNames" : "[`a`, `a`]"
457+
},
458+
"queryContext" : [ {
459+
"objectType" : "",
460+
"objectName" : "",
461+
"startIndex" : 66,
462+
"stopIndex" : 66,
463+
"fragment" : "a"
464+
} ]
465+
}
466+
467+
414468
-- !query
415469
set spark.sql.groupByAliases=false
416470
-- !query analysis

sql/core/src/test/resources/sql-tests/analyzer-results/having.sql.out

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,109 @@ Project [sum(v)#xL]
320320
+- Project [k#x, v#x]
321321
+- SubqueryAlias hav
322322
+- LocalRelation [k#x, v#x]
323+
324+
325+
-- !query
326+
SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2
327+
-- !query analysis
328+
Project [2#x, 2#x]
329+
+- Filter (2#x > 2#x)
330+
+- Aggregate [2#x], [1 AS 2#x, 2 AS 2#x, 2#x]
331+
+- SubqueryAlias t
332+
+- LocalRelation [2#x]
333+
334+
335+
-- !query
336+
SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2
337+
-- !query analysis
338+
Project [2#x, 2#x]
339+
+- Filter (2#x > 2#x)
340+
+- Aggregate [2#x], [2 AS 2#x, 1 AS 2#x, 2#x]
341+
+- SubqueryAlias t
342+
+- LocalRelation [2#x]
343+
344+
345+
-- !query
346+
SELECT 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2
347+
-- !query analysis
348+
Project [2#x]
349+
+- Filter (2#x > 2)
350+
+- Aggregate [2#x], [1 AS 2#x, 2#x]
351+
+- SubqueryAlias t
352+
+- LocalRelation [2#x]
353+
354+
355+
-- !query
356+
SELECT 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2
357+
-- !query analysis
358+
Project [2#x]
359+
+- Filter (2#x > 2#x)
360+
+- Aggregate [2#x], [2 AS 2#x, 2#x]
361+
+- SubqueryAlias t
362+
+- LocalRelation [2#x]
363+
364+
365+
-- !query
366+
SELECT SUM(v) + 1 FROM hav HAVING SUM(v) + 1
367+
-- !query analysis
368+
Filter cast((sum(v) + 1)#xL as boolean)
369+
+- Aggregate [(sum(v#x) + cast(1 as bigint)) AS (sum(v) + 1)#xL]
370+
+- SubqueryAlias hav
371+
+- View (`hav`, [k#x, v#x])
372+
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
373+
+- Project [k#x, v#x]
374+
+- SubqueryAlias hav
375+
+- LocalRelation [k#x, v#x]
376+
377+
378+
-- !query
379+
SELECT 1 + SUM(v) FROM hav HAVING SUM(v) + 1
380+
-- !query analysis
381+
Filter cast((1 + sum(v))#xL as boolean)
382+
+- Aggregate [(cast(1 as bigint) + sum(v#x)) AS (1 + sum(v))#xL]
383+
+- SubqueryAlias hav
384+
+- View (`hav`, [k#x, v#x])
385+
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
386+
+- Project [k#x, v#x]
387+
+- SubqueryAlias hav
388+
+- LocalRelation [k#x, v#x]
389+
390+
391+
-- !query
392+
SELECT SUM(v) + 1 FROM hav HAVING 1 + SUM(v)
393+
-- !query analysis
394+
Filter cast((sum(v) + 1)#xL as boolean)
395+
+- Aggregate [(sum(v#x) + cast(1 as bigint)) AS (sum(v) + 1)#xL]
396+
+- SubqueryAlias hav
397+
+- View (`hav`, [k#x, v#x])
398+
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
399+
+- Project [k#x, v#x]
400+
+- SubqueryAlias hav
401+
+- LocalRelation [k#x, v#x]
402+
403+
404+
-- !query
405+
SELECT MAX(v) + SUM(v) FROM hav HAVING SUM(v) + MAX(v)
406+
-- !query analysis
407+
Filter cast((max(v) + sum(v))#xL as boolean)
408+
+- Aggregate [(cast(max(v#x) as bigint) + sum(v#x)) AS (max(v) + sum(v))#xL]
409+
+- SubqueryAlias hav
410+
+- View (`hav`, [k#x, v#x])
411+
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
412+
+- Project [k#x, v#x]
413+
+- SubqueryAlias hav
414+
+- LocalRelation [k#x, v#x]
415+
416+
417+
-- !query
418+
SELECT SUM(v) + 1 + MIN(v) FROM hav HAVING 1 + 1 + 1 + MIN(v) + 1 + SUM(v)
419+
-- !query analysis
420+
Project [((sum(v) + 1) + min(v))#xL]
421+
+- Filter cast((cast(((((1 + 1) + 1) + min(v)#x) + 1) as bigint) + sum(v)#xL) as boolean)
422+
+- Aggregate [((sum(v#x) + cast(1 as bigint)) + cast(min(v#x) as bigint)) AS ((sum(v) + 1) + min(v))#xL, min(v#x) AS min(v)#x, sum(v#x) AS sum(v)#xL]
423+
+- SubqueryAlias hav
424+
+- View (`hav`, [k#x, v#x])
425+
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
426+
+- Project [k#x, v#x]
427+
+- SubqueryAlias hav
428+
+- LocalRelation [k#x, v#x]

sql/core/src/test/resources/sql-tests/analyzer-results/nonansi/try_arithmetic.sql.out

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ Project [try_add(1, (1.0 / 0.0)) AS try_add(1, (1.0 / 0.0))#x]
6969
+- OneRowRelation
7070

7171

72+
-- !query
73+
SELECT try_add(sum(1), 1) GROUP BY ALL
74+
-- !query analysis
75+
Aggregate [try_add(sum(1), 1) AS try_add(sum(1), 1)#xL]
76+
+- OneRowRelation
77+
78+
7279
-- !query
7380
SELECT try_add(date'2021-01-01', 1)
7481
-- !query analysis
@@ -239,6 +246,13 @@ Project [try_divide(1, 0) AS try_divide(1, 0)#x]
239246
+- OneRowRelation
240247

241248

249+
-- !query
250+
SELECT try_divide(sum(1), 1) GROUP BY ALL
251+
-- !query analysis
252+
Aggregate [try_divide(sum(1), 1) AS try_divide(sum(1), 1)#x]
253+
+- OneRowRelation
254+
255+
242256
-- !query
243257
SELECT try_divide(interval 2 year, 2)
244258
-- !query analysis
@@ -351,6 +365,13 @@ Project [try_subtract(1, (1.0 / 0.0)) AS try_subtract(1, (1.0 / 0.0))#x]
351365
+- OneRowRelation
352366

353367

368+
-- !query
369+
SELECT try_subtract(sum(1), 1) GROUP BY ALL
370+
-- !query analysis
371+
Aggregate [try_subtract(sum(1), 1) AS try_subtract(sum(1), 1)#xL]
372+
+- OneRowRelation
373+
374+
354375
-- !query
355376
SELECT try_subtract(interval 2 year, interval 3 year)
356377
-- !query analysis
@@ -449,6 +470,13 @@ Project [try_multiply(1, (1.0 / 0.0)) AS try_multiply(1, (1.0 / 0.0))#x]
449470
+- OneRowRelation
450471

451472

473+
-- !query
474+
SELECT try_multiply(sum(1), 1) GROUP BY ALL
475+
-- !query analysis
476+
Aggregate [try_multiply(sum(1), 1) AS try_multiply(sum(1), 1)#xL]
477+
+- OneRowRelation
478+
479+
452480
-- !query
453481
SELECT try_multiply(interval 2 year, 2)
454482
-- !query analysis

sql/core/src/test/resources/sql-tests/analyzer-results/order-by-alias.sql.out

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,41 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
212212
"fragment" : "c"
213213
} ]
214214
}
215+
216+
217+
-- !query
218+
SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) ORDER BY `2`
219+
-- !query analysis
220+
Project [2#x, 2#x]
221+
+- Sort [2#x ASC NULLS FIRST], true
222+
+- Project [1 AS 2#x, 2 AS 2#x, 2#x]
223+
+- SubqueryAlias t
224+
+- LocalRelation [2#x]
225+
226+
227+
-- !query
228+
SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2`
229+
-- !query analysis
230+
Project [2#x, 2#x]
231+
+- Sort [2#x ASC NULLS FIRST], true
232+
+- Project [2 AS 2#x, 1 AS 2#x, 2#x]
233+
+- SubqueryAlias t
234+
+- LocalRelation [2#x]
235+
236+
237+
-- !query
238+
SELECT 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2`
239+
-- !query analysis
240+
Sort [2#x ASC NULLS FIRST], true
241+
+- Project [1 AS 2#x]
242+
+- SubqueryAlias t
243+
+- LocalRelation [2#x]
244+
245+
246+
-- !query
247+
SELECT 2 FROM VALUES (2) t (`2`) ORDER BY `2`
248+
-- !query analysis
249+
Sort [2#x ASC NULLS FIRST], true
250+
+- Project [2 AS 2#x]
251+
+- SubqueryAlias t
252+
+- LocalRelation [2#x]

sql/core/src/test/resources/sql-tests/analyzer-results/order-by.sql.out

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,86 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
374374
}
375375

376376

377+
-- !query
378+
SELECT SUM(a) + 1 FROM testData ORDER BY SUM(a) + 1
379+
-- !query analysis
380+
Sort [(sum(a) + 1)#xL ASC NULLS FIRST], true
381+
+- Aggregate [(sum(a#x) + cast(1 as bigint)) AS (sum(a) + 1)#xL]
382+
+- SubqueryAlias testdata
383+
+- View (`testData`, [a#x, b#x])
384+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
385+
+- Project [a#x, b#x]
386+
+- SubqueryAlias testData
387+
+- LocalRelation [a#x, b#x]
388+
389+
390+
-- !query
391+
SELECT 1 + SUM(b) FROM testData ORDER BY SUM(b) + 1
392+
-- !query analysis
393+
Sort [(1 + sum(b))#xL ASC NULLS FIRST], true
394+
+- Aggregate [(cast(1 as bigint) + sum(b#x)) AS (1 + sum(b))#xL]
395+
+- SubqueryAlias testdata
396+
+- View (`testData`, [a#x, b#x])
397+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
398+
+- Project [a#x, b#x]
399+
+- SubqueryAlias testData
400+
+- LocalRelation [a#x, b#x]
401+
402+
403+
-- !query
404+
SELECT SUM(a) + 1 FROM testData ORDER BY 1 + SUM(a)
405+
-- !query analysis
406+
Sort [(sum(a) + 1)#xL ASC NULLS FIRST], true
407+
+- Aggregate [(sum(a#x) + cast(1 as bigint)) AS (sum(a) + 1)#xL]
408+
+- SubqueryAlias testdata
409+
+- View (`testData`, [a#x, b#x])
410+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
411+
+- Project [a#x, b#x]
412+
+- SubqueryAlias testData
413+
+- LocalRelation [a#x, b#x]
414+
415+
416+
-- !query
417+
SELECT MAX(a) + SUM(b) FROM testData ORDER BY SUM(b) + MAX(a)
418+
-- !query analysis
419+
Sort [(max(a) + sum(b))#xL ASC NULLS FIRST], true
420+
+- Aggregate [(cast(max(a#x) as bigint) + sum(b#x)) AS (max(a) + sum(b))#xL]
421+
+- SubqueryAlias testdata
422+
+- View (`testData`, [a#x, b#x])
423+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
424+
+- Project [a#x, b#x]
425+
+- SubqueryAlias testData
426+
+- LocalRelation [a#x, b#x]
427+
428+
429+
-- !query
430+
SELECT SUM(a) + 1 + MIN(a) FROM testData ORDER BY 1 + 1 + 1 + MIN(a) + 1 + SUM(a)
431+
-- !query analysis
432+
Project [((sum(a) + 1) + min(a))#xL]
433+
+- Sort [(cast(((((1 + 1) + 1) + min(a)#x) + 1) as bigint) + sum(a)#xL) ASC NULLS FIRST], true
434+
+- Aggregate [((sum(a#x) + cast(1 as bigint)) + cast(min(a#x) as bigint)) AS ((sum(a) + 1) + min(a))#xL, min(a#x) AS min(a)#x, sum(a#x) AS sum(a)#xL]
435+
+- SubqueryAlias testdata
436+
+- View (`testData`, [a#x, b#x])
437+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
438+
+- Project [a#x, b#x]
439+
+- SubqueryAlias testData
440+
+- LocalRelation [a#x, b#x]
441+
442+
443+
-- !query
444+
SELECT SUM(b) + 1 FROM testData HAVING SUM(b) + 1 > 0 ORDER BY SUM(b) + 1
445+
-- !query analysis
446+
Sort [(sum(b) + 1)#xL ASC NULLS FIRST], true
447+
+- Filter ((sum(b) + 1)#xL > cast(0 as bigint))
448+
+- Aggregate [(sum(b#x) + cast(1 as bigint)) AS (sum(b) + 1)#xL]
449+
+- SubqueryAlias testdata
450+
+- View (`testData`, [a#x, b#x])
451+
+- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]
452+
+- Project [a#x, b#x]
453+
+- SubqueryAlias testData
454+
+- LocalRelation [a#x, b#x]
455+
456+
377457
-- !query
378458
DROP VIEW IF EXISTS testData
379459
-- !query analysis

0 commit comments

Comments
 (0)