Skip to content

Commit 6ba4771

Browse files
mihailoale-dbcloud-fan
authored andcommitted
[SPARK-51371][SQL] Change toString to toPrettySQL when building Aliases in ResolveAggregateFunctions
### What changes were proposed in this pull request? In this PR I propose that we use `toPrettySQL` instead of `toString` when building `Alias`es in `ResolveAggregateFunctions`. ### Why are the changes needed? Right now you can write a DataFrame program in which you can reference a column implicitly aliased with a expression id in its name. If we switch from using `toString` to `toPrettySQL` we won't have expression ids `Alias` name and thus users won't be able to utilize this. For example: ``` import org.apache.spark.sql.functions._ val df = spark.sql("SELECT col1 FROM VALUES (1, 2) GROUP BY col1 ORDER BY MAX(col2)") df.queryExecution.analyzed df.where(col("max(col2#10)") === 0).queryExecution.analyzed ``` program above can work (if `df.queryExecution.analyzed` shows that the name of the `AggregateExpression` alias is `max(col2#10)`). But when run again it might fail because expression ids can be generated differently so we want to disable that (to enforce deterministic behavior in DataFrame programs). ### Does this PR introduce _any_ user-facing change? Some DataFrame programs are going to fail (but they would fail with every cluster reset, as explained.) ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #50136 from mihailoale-db/toprettysqlresolveaggregatefunctions. Authored-by: mihailoale-db <mihailo.aleksic@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 4b4bdcf commit 6ba4771

File tree

21 files changed

+106
-106
lines changed

21 files changed

+106
-106
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
27682768
expr match {
27692769
case ae: AggregateExpression =>
27702770
val cleaned = trimTempResolvedColumn(ae)
2771-
val alias = Alias(cleaned, cleaned.toString)()
2771+
val alias = Alias(cleaned, toPrettySQL(cleaned))()
27722772
aggExprList += alias
27732773
alias.toAttribute
27742774
case grouping: Expression if agg.groupingExpressions.exists(grouping.semanticEquals) =>
@@ -2777,7 +2777,7 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
27772777
aggExprList += ne
27782778
ne.toAttribute
27792779
case other =>
2780-
val alias = Alias(other, other.toString)()
2780+
val alias = Alias(other, toPrettySQL(other))()
27812781
aggExprList += alias
27822782
alias.toAttribute
27832783
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ Aggregate [(b1#x & 1)], [bit_xor(b3#x) AS bit_xor(b3)#x]
248248
SELECT b1, bit_xor(b2) FROM bitwise_test GROUP BY b1 HAVING bit_and(b2) < 7
249249
-- !query analysis
250250
Project [b1#x, bit_xor(b2)#x]
251-
+- Filter (bit_and(b2#x)#x < 7)
252-
+- Aggregate [b1#x], [b1#x, bit_xor(b2#x) AS bit_xor(b2)#x, bit_and(b2#x) AS bit_and(b2#x)#x]
251+
+- Filter (bit_and(b2)#x < 7)
252+
+- Aggregate [b1#x], [b1#x, bit_xor(b2#x) AS bit_xor(b2)#x, bit_and(b2#x) AS bit_and(b2)#x]
253253
+- SubqueryAlias bitwise_test
254254
+- View (`bitwise_test`, [b1#x, b2#x, b3#x, b4#xL])
255255
+- Project [cast(b1#x as int) AS b1#x, cast(b2#x as int) AS b2#x, cast(b3#x as int) AS b3#x, cast(b4#xL as bigint) AS b4#xL]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ SELECT s AS s, COUNT(*) c FROM stuff GROUP BY ALL HAVING SUM(f) > 0 ORDER BY s
9191
-- !query analysis
9292
Sort [s#x ASC NULLS FIRST], true
9393
+- Project [s#x, c#xL]
94-
+- Filter (sum(f#x)#x > cast(cast(0 as decimal(1,0)) as decimal(16,4)))
95-
+- Aggregate [s#x], [s#x AS s#x, count(1) AS c#xL, sum(f#x) AS sum(f#x)#x]
94+
+- Filter (sum(f)#x > cast(cast(0 as decimal(1,0)) as decimal(16,4)))
95+
+- Aggregate [s#x], [s#x AS s#x, count(1) AS c#xL, sum(f#x) AS sum(f)#x]
9696
+- SubqueryAlias stuff
9797
+- View (`stuff`, [i#x, f#x, s#x, t#x, d#x, a#x])
9898
+- Project [cast(i#x as int) AS i#x, cast(f#x as decimal(6,4)) AS f#x, cast(s#x as string) AS s#x, cast(t#x as string) AS t#x, cast(d#x as string) AS d#x, cast(a#x as array<int>) AS a#x]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ Filter cast(true as boolean)
315315
SELECT 1 FROM range(10) HAVING MAX(id) > 0
316316
-- !query analysis
317317
Project [1#x]
318-
+- Filter (max(id#xL)#xL > cast(0 as bigint))
319-
+- Aggregate [1 AS 1#x, max(id#xL) AS max(id#xL)#xL]
318+
+- Filter (max(id)#xL > cast(0 as bigint))
319+
+- Aggregate [1 AS 1#x, max(id#xL) AS max(id)#xL]
320320
+- Range (0, 10, step=1)
321321

322322

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Filter (sum(v)#xL > cast(2 as bigint))
3535
SELECT count(k) FROM hav GROUP BY v + 1 HAVING v + 1 = 2
3636
-- !query analysis
3737
Project [count(k)#xL]
38-
+- Filter ((v#x + 1)#x = 2)
39-
+- Aggregate [(v#x + 1)], [count(k#x) AS count(k)#xL, (v#x + 1) AS (v#x + 1)#x]
38+
+- Filter ((v + 1)#x = 2)
39+
+- Aggregate [(v#x + 1)], [count(k#x) AS count(k)#xL, (v#x + 1) AS (v + 1)#x]
4040
+- SubqueryAlias hav
4141
+- View (`hav`, [k#x, v#x])
4242
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]
@@ -199,9 +199,9 @@ Sort [sum(v)#xL ASC NULLS FIRST], true
199199
SELECT k, sum(v) FROM hav GROUP BY k HAVING sum(v) > 2 ORDER BY avg(v)
200200
-- !query analysis
201201
Project [k#x, sum(v)#xL]
202-
+- Sort [avg(v#x)#x ASC NULLS FIRST], true
202+
+- Sort [avg(v)#x ASC NULLS FIRST], true
203203
+- Filter (sum(v)#xL > cast(2 as bigint))
204-
+- Aggregate [k#x], [k#x, sum(v#x) AS sum(v)#xL, avg(v#x) AS avg(v#x)#x]
204+
+- Aggregate [k#x], [k#x, sum(v#x) AS sum(v)#xL, avg(v#x) AS avg(v)#x]
205205
+- SubqueryAlias hav
206206
+- View (`hav`, [k#x, v#x])
207207
+- Project [cast(k#x as string) AS k#x, cast(v#x as int) AS v#x]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ group by ten
3838
having exists (select 1 from onek b where sum(distinct a.four) = b.four)
3939
-- !query analysis
4040
Project [ten#x, sum(DISTINCT four) FILTER (WHERE (four > 10))#xL]
41-
+- Filter exists#x [sum(distinct four#x)#xL]
41+
+- Filter exists#x [sum(DISTINCT four)#xL]
4242
: +- Project [1 AS 1#x]
43-
: +- Filter (outer(sum(distinct four#x)#xL) = cast(four#x as bigint))
43+
: +- Filter (outer(sum(DISTINCT four)#xL) = cast(four#x as bigint))
4444
: +- SubqueryAlias b
4545
: +- SubqueryAlias spark_catalog.default.onek
4646
: +- Relation spark_catalog.default.onek[unique1#x,unique2#x,two#x,four#x,ten#x,twenty#x,hundred#x,thousand#x,twothousand#x,fivethous#x,tenthous#x,odd#x,even#x,stringu1#x,stringu2#x,string4#x] parquet
47-
+- Aggregate [ten#x], [ten#x, sum(distinct four#x) FILTER (WHERE (four#x > 10)) AS sum(DISTINCT four) FILTER (WHERE (four > 10))#xL, sum(distinct four#x) AS sum(distinct four#x)#xL]
47+
+- Aggregate [ten#x], [ten#x, sum(distinct four#x) FILTER (WHERE (four#x > 10)) AS sum(DISTINCT four) FILTER (WHERE (four > 10))#xL, sum(distinct four#x) AS sum(DISTINCT four)#xL]
4848
+- SubqueryAlias a
4949
+- SubqueryAlias spark_catalog.default.onek
5050
+- Relation spark_catalog.default.onek[unique1#x,unique2#x,two#x,four#x,ten#x,twenty#x,hundred#x,thousand#x,twothousand#x,fivethous#x,tenthous#x,odd#x,even#x,stringu1#x,stringu2#x,string4#x] parquet

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ SELECT c, max(a) FROM test_having
115115
-- !query analysis
116116
Sort [c#x ASC NULLS FIRST], true
117117
+- Project [c#x, max(a)#x]
118-
+- Filter ((count(1)#xL > cast(2 as bigint)) OR (min(a#x)#x = max(a)#x))
119-
+- Aggregate [c#x], [c#x, max(a#x) AS max(a)#x, count(1) AS count(1)#xL, min(a#x) AS min(a#x)#x]
118+
+- Filter ((count(1)#xL > cast(2 as bigint)) OR (min(a)#x = max(a)#x))
119+
+- Aggregate [c#x], [c#x, max(a#x) AS max(a)#x, count(1) AS count(1)#xL, min(a#x) AS min(a)#x]
120120
+- SubqueryAlias spark_catalog.default.test_having
121121
+- Relation spark_catalog.default.test_having[a#x,b#x,c#x,d#x] parquet
122122

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ GROUP BY lower(test_missing_target.c)
310310
ORDER BY lower(test_missing_target.c)
311311
-- !query analysis
312312
Project [count(c)#xL]
313-
+- Sort [lower(c#x)#x ASC NULLS FIRST], true
314-
+- Aggregate [lower(c#x)], [count(c#x) AS count(c)#xL, lower(c#x) AS lower(c#x)#x]
313+
+- Sort [lower(c)#x ASC NULLS FIRST], true
314+
+- Aggregate [lower(c#x)], [count(c#x) AS count(c)#xL, lower(c#x) AS lower(c)#x]
315315
+- SubqueryAlias spark_catalog.default.test_missing_target
316316
+- Relation spark_catalog.default.test_missing_target[a#x,b#x,c#x,d#x] parquet
317317

@@ -341,8 +341,8 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
341341
SELECT count(b) FROM test_missing_target GROUP BY b/2 ORDER BY b/2
342342
-- !query analysis
343343
Project [count(b)#xL]
344-
+- Sort [(cast(b#x as double) / cast(2 as double))#x ASC NULLS FIRST], true
345-
+- Aggregate [(cast(b#x as double) / cast(2 as double))], [count(b#x) AS count(b)#xL, (cast(b#x as double) / cast(2 as double)) AS (cast(b#x as double) / cast(2 as double))#x]
344+
+- Sort [(b / 2)#x ASC NULLS FIRST], true
345+
+- Aggregate [(cast(b#x as double) / cast(2 as double))], [count(b#x) AS count(b)#xL, (cast(b#x as double) / cast(2 as double)) AS (b / 2)#x]
346346
+- SubqueryAlias spark_catalog.default.test_missing_target
347347
+- Relation spark_catalog.default.test_missing_target[a#x,b#x,c#x,d#x] parquet
348348

@@ -372,8 +372,8 @@ SELECT count(b) FROM test_missing_target
372372
GROUP BY (b + 1) / 2 ORDER BY (b + 1) / 2 desc
373373
-- !query analysis
374374
Project [count(b)#xL]
375-
+- Sort [(cast((b#x + 1) as double) / cast(2 as double))#x DESC NULLS LAST], true
376-
+- Aggregate [(cast((b#x + 1) as double) / cast(2 as double))], [count(b#x) AS count(b)#xL, (cast((b#x + 1) as double) / cast(2 as double)) AS (cast((b#x + 1) as double) / cast(2 as double))#x]
375+
+- Sort [((b + 1) / 2)#x DESC NULLS LAST], true
376+
+- Aggregate [(cast((b#x + 1) as double) / cast(2 as double))], [count(b#x) AS count(b)#xL, (cast((b#x + 1) as double) / cast(2 as double)) AS ((b + 1) / 2)#x]
377377
+- SubqueryAlias spark_catalog.default.test_missing_target
378378
+- Relation spark_catalog.default.test_missing_target[a#x,b#x,c#x,d#x] parquet
379379

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,8 @@ Aggregate [(c1#x + variablereference(system.session.var1=1))], [1 AS 1#x]
19951995
SELECT c1, sum(c2) FROM VALUES(1, 2) AS T(c1, c2) GROUP BY c1 HAVING sum(c1) != var1
19961996
-- !query analysis
19971997
Project [c1#x, sum(c2)#xL]
1998-
+- Filter NOT (sum(c1#x)#xL = cast(variablereference(system.session.var1=1) as bigint))
1999-
+- Aggregate [c1#x], [c1#x, sum(c2#x) AS sum(c2)#xL, sum(c1#x) AS sum(c1#x)#xL]
1998+
+- Filter NOT (sum(c1)#xL = cast(variablereference(system.session.var1=1) as bigint))
1999+
+- Aggregate [c1#x], [c1#x, sum(c2#x) AS sum(c2)#xL, sum(c1#x) AS sum(c1)#xL]
20002000
+- SubqueryAlias T
20012001
+- LocalRelation [c1#x, c2#x]
20022002

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ HAVING EXISTS (SELECT 1
7575
WHERE bonus_amt < min(emp.salary))
7676
-- !query analysis
7777
Project [dept_id#x, count(1)#xL]
78-
+- Filter exists#x [min(salary#x)#x]
78+
+- Filter exists#x [min(salary)#x]
7979
: +- Project [1 AS 1#x]
80-
: +- Filter (bonus_amt#x < outer(min(salary#x)#x))
80+
: +- Filter (bonus_amt#x < outer(min(salary)#x))
8181
: +- SubqueryAlias bonus
8282
: +- View (`BONUS`, [emp_name#x, bonus_amt#x])
8383
: +- Project [cast(col1#x as string) AS emp_name#x, cast(col2#x as double) AS bonus_amt#x]
8484
: +- LocalRelation [col1#x, col2#x]
85-
+- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary#x)#x]
85+
+- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary)#x]
8686
+- SubqueryAlias emp
8787
+- View (`EMP`, [id#x, emp_name#x, hiredate#x, salary#x, dept_id#x])
8888
+- Project [cast(col1#x as int) AS id#x, cast(col2#x as string) AS emp_name#x, cast(col3#x as date) AS hiredate#x, cast(col4#x as double) AS salary#x, cast(col5#x as int) AS dept_id#x]
@@ -103,14 +103,14 @@ WHERE EXISTS (SELECT dept_id,
103103
Project [dept_id#x, dept_name#x, state#x]
104104
+- Filter exists#x []
105105
: +- Project [dept_id#x, count(1)#xL]
106-
: +- Filter exists#x [min(salary#x)#x]
106+
: +- Filter exists#x [min(salary)#x]
107107
: : +- Project [1 AS 1#x]
108-
: : +- Filter (bonus_amt#x < outer(min(salary#x)#x))
108+
: : +- Filter (bonus_amt#x < outer(min(salary)#x))
109109
: : +- SubqueryAlias bonus
110110
: : +- View (`BONUS`, [emp_name#x, bonus_amt#x])
111111
: : +- Project [cast(col1#x as string) AS emp_name#x, cast(col2#x as double) AS bonus_amt#x]
112112
: : +- LocalRelation [col1#x, col2#x]
113-
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary#x)#x]
113+
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary)#x]
114114
: +- SubqueryAlias emp
115115
: +- View (`EMP`, [id#x, emp_name#x, hiredate#x, salary#x, dept_id#x])
116116
: +- Project [cast(col1#x as int) AS id#x, cast(col2#x as string) AS emp_name#x, cast(col3#x as date) AS hiredate#x, cast(col4#x as double) AS salary#x, cast(col5#x as int) AS dept_id#x]
@@ -137,14 +137,14 @@ GROUP BY gp.dept_id
137137
Aggregate [dept_id#x], [dept_id#x, max(salary#x) AS max(salary)#x]
138138
+- Filter exists#x []
139139
: +- Project [dept_id#x, count(1)#xL]
140-
: +- Filter exists#x [min(salary#x)#x]
140+
: +- Filter exists#x [min(salary)#x]
141141
: : +- Project [1 AS 1#x]
142-
: : +- Filter (bonus_amt#x < outer(min(salary#x)#x))
142+
: : +- Filter (bonus_amt#x < outer(min(salary)#x))
143143
: : +- SubqueryAlias bonus
144144
: : +- View (`BONUS`, [emp_name#x, bonus_amt#x])
145145
: : +- Project [cast(col1#x as string) AS emp_name#x, cast(col2#x as double) AS bonus_amt#x]
146146
: : +- LocalRelation [col1#x, col2#x]
147-
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary#x)#x]
147+
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary)#x]
148148
: +- SubqueryAlias p
149149
: +- SubqueryAlias emp
150150
: +- View (`EMP`, [id#x, emp_name#x, hiredate#x, salary#x, dept_id#x])
@@ -171,14 +171,14 @@ WHERE EXISTS (SELECT dept_id,
171171
Project [dept_id#x, dept_name#x, state#x]
172172
+- Filter exists#x []
173173
: +- Project [dept_id#x, count(1)#xL]
174-
: +- Filter exists#x [min(salary#x)#x]
174+
: +- Filter exists#x [min(salary)#x]
175175
: : +- Project [1 AS 1#x]
176-
: : +- Filter (bonus_amt#x > outer(min(salary#x)#x))
176+
: : +- Filter (bonus_amt#x > outer(min(salary)#x))
177177
: : +- SubqueryAlias bonus
178178
: : +- View (`BONUS`, [emp_name#x, bonus_amt#x])
179179
: : +- Project [cast(col1#x as string) AS emp_name#x, cast(col2#x as double) AS bonus_amt#x]
180180
: : +- LocalRelation [col1#x, col2#x]
181-
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary#x)#x]
181+
: +- Aggregate [dept_id#x], [dept_id#x, count(1) AS count(1)#xL, min(salary#x) AS min(salary)#x]
182182
: +- SubqueryAlias emp
183183
: +- View (`EMP`, [id#x, emp_name#x, hiredate#x, salary#x, dept_id#x])
184184
: +- Project [cast(col1#x as int) AS id#x, cast(col2#x as string) AS emp_name#x, cast(col3#x as date) AS hiredate#x, cast(col4#x as double) AS salary#x, cast(col5#x as int) AS dept_id#x]
@@ -205,14 +205,14 @@ WHERE EXISTS (SELECT dept_id,
205205
Project [dept_id#x, dept_name#x, state#x]
206206
+- Filter exists#x [dept_id#x]
207207
: +- Project [dept_id#x, count(dept_id)#xL]
208-
: +- Filter exists#x [min(salary#x)#x && count(dept_id)#xL]
208+
: +- Filter exists#x [min(salary)#x && count(dept_id)#xL]
209209
: : +- Project [1 AS 1#x]
210-
: : +- Filter ((bonus_amt#x > outer(min(salary#x)#x)) AND (outer(count(dept_id)#xL) > cast(1 as bigint)))
210+
: : +- Filter ((bonus_amt#x > outer(min(salary)#x)) AND (outer(count(dept_id)#xL) > cast(1 as bigint)))
211211
: : +- SubqueryAlias bonus
212212
: : +- View (`BONUS`, [emp_name#x, bonus_amt#x])
213213
: : +- Project [cast(col1#x as string) AS emp_name#x, cast(col2#x as double) AS bonus_amt#x]
214214
: : +- LocalRelation [col1#x, col2#x]
215-
: +- Aggregate [dept_id#x], [dept_id#x, count(dept_id#x) AS count(dept_id)#xL, min(salary#x) AS min(salary#x)#x]
215+
: +- Aggregate [dept_id#x], [dept_id#x, count(dept_id#x) AS count(dept_id)#xL, min(salary#x) AS min(salary)#x]
216216
: +- Filter (outer(dept_id#x) = dept_id#x)
217217
: +- SubqueryAlias emp
218218
: +- View (`EMP`, [id#x, emp_name#x, hiredate#x, salary#x, dept_id#x])

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ GROUP BY t1a, t1b, t1c
203203
HAVING COUNT (DISTINCT t1b) < 10
204204
-- !query analysis
205205
Project [t1a#x, t1b#x, t1c#x]
206-
+- Filter (count(distinct t1b#x)#xL < cast(10 as bigint))
207-
+- Aggregate [t1a#x, t1b#x, t1c#x], [t1a#x, t1b#x, t1c#x, count(distinct t1b#x) AS count(distinct t1b#x)#xL]
206+
+- Filter (count(DISTINCT t1b)#xL < cast(10 as bigint))
207+
+- Aggregate [t1a#x, t1b#x, t1c#x], [t1a#x, t1b#x, t1c#x, count(distinct t1b#x) AS count(DISTINCT t1b)#xL]
208208
+- Filter t1b#x IN (list#x [t1c#x])
209209
: +- Project [t2b#x]
210210
: +- Filter (outer(t1c#x) = t2c#x)

sql/core/src/test/resources/sql-tests/analyzer-results/subquery/in-subquery/not-in-joins.sql.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ GROUP BY t1b,
341341
HAVING t1b < sum(t1c)
342342
-- !query analysis
343343
Project [count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL]
344-
+- Filter (cast(t1b#x as bigint) < sum(t1c#x)#xL)
345-
+- Aggregate [t1b#x, t1c#x, t1d#xL], [count(distinct t1a#x) AS count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL, sum(t1c#x) AS sum(t1c#x)#xL]
344+
+- Filter (cast(t1b#x as bigint) < sum(t1c)#xL)
345+
+- Aggregate [t1b#x, t1c#x, t1d#xL], [count(distinct t1a#x) AS count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL, sum(t1c#x) AS sum(t1c)#xL]
346346
+- Filter NOT t1a#x IN (list#x [])
347347
: +- Project [t2a#x]
348348
: +- Join Inner, (t1a#x = t2a#x)
@@ -390,8 +390,8 @@ GROUP BY t1b,
390390
HAVING t1b < sum(t1c)
391391
-- !query analysis
392392
Project [count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL]
393-
+- Filter (cast(t1b#x as bigint) < sum(t1c#x)#xL)
394-
+- Aggregate [t1b#x, t1c#x, t1d#xL], [count(distinct t1a#x) AS count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL, sum(t1c#x) AS sum(t1c#x)#xL]
393+
+- Filter (cast(t1b#x as bigint) < sum(t1c)#xL)
394+
+- Aggregate [t1b#x, t1c#x, t1d#xL], [count(distinct t1a#x) AS count(DISTINCT t1a)#xL, t1b#x, t1c#x, t1d#xL, sum(t1c#x) AS sum(t1c)#xL]
395395
+- Filter (NOT t1a#x IN (list#x []) AND NOT t1d#xL IN (list#x []))
396396
: :- Project [t2a#x]
397397
: : +- Join Inner, (t1a#x = t2a#x)

sql/core/src/test/resources/sql-tests/analyzer-results/subquery/scalar-subquery/scalar-subquery-predicate.sql.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ HAVING max(t1b) <= (SELECT max(t2b)
862862
GROUP BY t2c)
863863
-- !query analysis
864864
Project [t1a#x]
865-
+- Filter (max(t1b#x)#x <= scalar-subquery#x [t1c#x])
865+
+- Filter (max(t1b)#x <= scalar-subquery#x [t1c#x])
866866
: +- Aggregate [t2c#x], [max(t2b#x) AS max(t2b)#x]
867867
: +- Filter (t2c#x = outer(t1c#x))
868868
: +- SubqueryAlias t2
@@ -871,7 +871,7 @@ Project [t1a#x]
871871
: +- Project [t2a#x, t2b#x, t2c#x, t2d#xL, t2e#x, t2f#x, t2g#x, t2h#x, t2i#x]
872872
: +- SubqueryAlias t2
873873
: +- LocalRelation [t2a#x, t2b#x, t2c#x, t2d#xL, t2e#x, t2f#x, t2g#x, t2h#x, t2i#x]
874-
+- Aggregate [t1a#x, t1c#x], [t1a#x, max(t1b#x) AS max(t1b#x)#x, t1c#x]
874+
+- Aggregate [t1a#x, t1c#x], [t1a#x, max(t1b#x) AS max(t1b)#x, t1c#x]
875875
+- SubqueryAlias t1
876876
+- View (`t1`, [t1a#x, t1b#x, t1c#x, t1d#xL, t1e#x, t1f#x, t1g#x, t1h#x, t1i#x])
877877
+- Project [cast(t1a#x as string) AS t1a#x, cast(t1b#x as smallint) AS t1b#x, cast(t1c#x as int) AS t1c#x, cast(t1d#xL as bigint) AS t1d#xL, cast(t1e#x as float) AS t1e#x, cast(t1f#x as double) AS t1f#x, cast(t1g#x as decimal(4,0)) AS t1g#x, cast(t1h#x as timestamp) AS t1h#x, cast(t1i#x as date) AS t1i#x]
@@ -1204,8 +1204,8 @@ Project [t1a#x, t1b#x]
12041204
: +- GlobalLimit 1
12051205
: +- LocalLimit 1
12061206
: +- Project [max(t2c)#x]
1207-
: +- Sort [min(t2c#x)#x ASC NULLS FIRST], true
1208-
: +- Aggregate [max(t2c#x) AS max(t2c)#x, min(t2c#x) AS min(t2c#x)#x]
1207+
: +- Sort [min(t2c)#x ASC NULLS FIRST], true
1208+
: +- Aggregate [max(t2c#x) AS max(t2c)#x, min(t2c#x) AS min(t2c)#x]
12091209
: +- Filter (cast(outer(t1b#x) as bigint) < outer(t1d#xL))
12101210
: +- SubqueryAlias t2
12111211
: +- View (`t2`, [t2a#x, t2b#x, t2c#x, t2d#xL, t2e#x, t2f#x, t2g#x, t2h#x, t2i#x])

sql/core/src/test/resources/sql-tests/analyzer-results/udf/postgreSQL/udf-aggregates_part1.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ group by ten
454454
having exists (select 1 from onek b where udf(sum(distinct a.four)) = b.four)
455455
-- !query analysis
456456
Project [ten#x, udf(sum(DISTINCT four))#xL]
457-
+- Filter exists#x [sum(distinct four#x)#xL]
457+
+- Filter exists#x [sum(DISTINCT four)#xL]
458458
: +- Project [1 AS 1#x]
459459
: +- Filter (outer(udf(sum(DISTINCT four))#xL) = cast(four#x as bigint))
460460
: +- SubqueryAlias b
461461
: +- SubqueryAlias spark_catalog.default.onek
462462
: +- Relation spark_catalog.default.onek[unique1#x,unique2#x,two#x,four#x,ten#x,twenty#x,hundred#x,thousand#x,twothousand#x,fivethous#x,tenthous#x,odd#x,even#x,stringu1#x,stringu2#x,string4#x] parquet
463-
+- Aggregate [ten#x], [ten#x, cast(udf(cast(sum(distinct four#x) as string)) as bigint) AS udf(sum(DISTINCT four))#xL, sum(distinct four#x) AS sum(distinct four#x)#xL]
463+
+- Aggregate [ten#x], [ten#x, cast(udf(cast(sum(distinct four#x) as string)) as bigint) AS udf(sum(DISTINCT four))#xL, sum(distinct four#x) AS sum(DISTINCT four)#xL]
464464
+- SubqueryAlias a
465465
+- SubqueryAlias spark_catalog.default.onek
466466
+- Relation spark_catalog.default.onek[unique1#x,unique2#x,two#x,four#x,ten#x,twenty#x,hundred#x,thousand#x,twothousand#x,fivethous#x,tenthous#x,odd#x,even#x,stringu1#x,stringu2#x,string4#x] parquet

0 commit comments

Comments
 (0)