This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new f5a45826bbff [SPARK-52532][SQL][TESTS] Add tests for hidden or main
output prioritization during attribute name conflict
f5a45826bbff is described below
commit f5a45826bbff25d3e53c937406d782c22b5f6bfa
Author: Vladimir Golubev <[email protected]>
AuthorDate: Mon Jun 23 10:54:22 2025 +0800
[SPARK-52532][SQL][TESTS] Add tests for hidden or main output
prioritization during attribute name conflict
### What changes were proposed in this pull request?
Spark is being smart about which output can be referenced based on the name
conflict. Example:
```
-- Sort prefers col1 from local relation, because SELECT list has a conflict
SELECT 1 AS col1, 2 AS col1 FROM VALUES (1) t (col1) ORDER BY col1;
```
We need more test coverage for these cases.
### Why are the changes needed?
To improve Spark SQL test coverage.
### Does this PR introduce _any_ user-facing change?
Test-only change.
### How was this patch tested?
New golden file tests.
### Was this patch authored or co-authored using generative AI tooling?
Yes, test data was generated using AI agent.
Closes #51224 from
vladimirg-db/vladimir-golubev_data/add-tests-for-conflicting-attribute-resolution-using-different-types-of-output.
Authored-by: Vladimir Golubev <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
---
...-and-having-with-conflicting-attributes.sql.out | 625 +++++++++++++++++
...r-by-and-having-with-conflicting-attributes.sql | 114 ++++
...-and-having-with-conflicting-attributes.sql.out | 744 +++++++++++++++++++++
3 files changed, 1483 insertions(+)
diff --git
a/sql/core/src/test/resources/sql-tests/analyzer-results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
b/sql/core/src/test/resources/sql-tests/analyzer-results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
new file mode 100644
index 000000000000..2eef922b1a8e
--- /dev/null
+++
b/sql/core/src/test/resources/sql-tests/analyzer-results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
@@ -0,0 +1,625 @@
+-- Automatically generated by SQLQueryTestSuite
+-- !query
+CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT col1 FROM VALUES
+ (42), (17), (99), (5), (42),
+ (23), (8), (17), (76), (33),
+ (99), (55), (3), (42), (8)
+-- !query analysis
+CreateViewCommand `v1`, SELECT col1 FROM VALUES
+ (42), (17), (99), (5), (42),
+ (23), (8), (17), (76), (33),
+ (99), (55), (3), (42), (8), false, true, LocalTempView, UNSUPPORTED, true
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT col1 FROM VALUES
+ ('apple'), ('banana'), ('cherry'), ('date'), ('apple'),
+ ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'),
+ ('cherry'), ('mango'), ('orange'), ('apple'), ('grape')
+-- !query analysis
+CreateViewCommand `v2`, SELECT col1 FROM VALUES
+ ('apple'), ('banana'), ('cherry'), ('date'), ('apple'),
+ ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'),
+ ('cherry'), ('mango'), ('orange'), ('apple'), ('grape'), false, true,
LocalTempView, UNSUPPORTED, true
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [2], [2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query analysis
+Filter (col1#x > 50)
++- Aggregate [2], [2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1#x AS c#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1#x, 2], [col1#x AS c#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query analysis
+Filter (c#x > 50)
++- Aggregate [col1#x, 2], [col1#x AS c#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1
+-- !query analysis
+Project [col1#x, col1#x]
++- Sort [col1#x ASC NULLS FIRST], true
+ +- Project [2 AS col1#x, 3 AS col1#x, col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.catalyst.ExtendedAnalysisException
+{
+ "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION",
+ "sqlState" : "42703",
+ "messageParameters" : {
+ "objectName" : "`col1`",
+ "proposal" : "`col1`, `col1`"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 59,
+ "stopIndex" : 62,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 57,
+ "stopIndex" : 60,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1
+-- !query analysis
+Project [c#x, col1#x, col1#x]
++- Sort [col1#x ASC NULLS FIRST], true
+ +- Project [col1#x AS c#x, 2 AS col1#x, 3 AS col1#x, col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [c#x ASC NULLS FIRST], true
++- Aggregate [col1#x, 2, 3], [col1#x AS c#x, 2 AS col1#x, 3 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query analysis
+Filter (c#x > 50)
++- Aggregate [col1#x, 2, 3], [col1#x AS c#x, 2 AS col1#x, 3 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1#x, 2], [col1#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query analysis
+Filter (col1#x > 50)
++- Aggregate [col1#x, 2], [col1#x, 2 AS col1#x]
+ +- SubqueryAlias v1
+ +- View (`v1`, [col1#x])
+ +- Project [cast(col1#x as int) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [3 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [1 AS col1#x, 2 AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [3], [3 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [1 AS col1#x, 2 AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 >
50
+-- !query analysis
+Filter (col1#x > 50)
++- Aggregate [3], [3 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [1 AS col1#x, 2 AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
HAVING col1 > 50
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 'col1' FROM v2 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1], [col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query analysis
+Filter (col1#x > banana)
++- Aggregate [col1], [col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1#x AS c#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1#x, col1], [col1#x AS c#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query analysis
+Filter (c#x > banana)
++- Aggregate [col1#x, col1], [col1#x AS c#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 ORDER BY col1
+-- !query analysis
+Project [col1#x, col1#x]
++- Sort [col1#x ASC NULLS FIRST], true
+ +- Project [col1 AS col1#x, col1 AS col1#x, col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.catalyst.ExtendedAnalysisException
+{
+ "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION",
+ "sqlState" : "42703",
+ "messageParameters" : {
+ "objectName" : "`col1`",
+ "proposal" : "`col1`, `col1`"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 53,
+ "stopIndex" : 56,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 51,
+ "stopIndex" : 54,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 ORDER BY col1
+-- !query analysis
+Project [c#x, col1#x, col1#x]
++- Sort [col1#x ASC NULLS FIRST], true
+ +- Project [col1#x AS c#x, col1 AS col1#x, col1 AS col1#x, col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [c#x ASC NULLS FIRST], true
++- Aggregate [col1#x, col1, col1], [col1#x AS c#x, col1 AS col1#x, col1 AS
col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query analysis
+Filter (c#x > banana)
++- Aggregate [col1#x, col1, col1], [col1#x AS c#x, col1 AS col1#x, col1 AS
col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1#x, col1], [col1#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query analysis
+Filter (col1#x > banana)
++- Aggregate [col1#x, col1], [col1#x, col1 AS col1#x]
+ +- SubqueryAlias v2
+ +- View (`v2`, [col1#x])
+ +- Project [cast(col1#x as string) AS col1#x]
+ +- Project [col1#x]
+ +- LocalRelation [col1#x]
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Project [col1 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [a AS col1#x, b AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1
+-- !query analysis
+Sort [col1#x ASC NULLS FIRST], true
++- Aggregate [col1], [col1 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [a AS col1#x, b AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1
> 'banana'
+-- !query analysis
+Filter (col1#x > banana)
++- Aggregate [col1], [col1 AS col1#x]
+ +- SubqueryAlias __auto_generated_subquery_name
+ +- Project [a AS col1#x, b AS col1#x]
+ +- OneRowRelation
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
ORDER BY col1
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
HAVING col1 > 'banana'
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+DROP VIEW v2
+-- !query analysis
+DropTempViewCommand v2
+
+
+-- !query
+DROP VIEW v1
+-- !query analysis
+DropTempViewCommand v1
diff --git
a/sql/core/src/test/resources/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql
b/sql/core/src/test/resources/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql
new file mode 100644
index 000000000000..fa6b61b2c4e7
--- /dev/null
+++
b/sql/core/src/test/resources/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql
@@ -0,0 +1,114 @@
+CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT col1 FROM VALUES
+ (42), (17), (99), (5), (42),
+ (23), (8), (17), (76), (33),
+ (99), (55), (3), (42), (8)
+;
+
+CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT col1 FROM VALUES
+ ('apple'), ('banana'), ('cherry'), ('date'), ('apple'),
+ ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'),
+ ('cherry'), ('mango'), ('orange'), ('apple'), ('grape')
+;
+
+-- Explicit aliases
+
+-- Baseline
+
+SELECT 2 AS col1 FROM v1 ORDER BY col1;
+
+SELECT 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1;
+
+SELECT 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50;
+
+SELECT col1 AS c, 2 AS col1 FROM v1 ORDER BY col1;
+
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1;
+
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50;
+
+-- Conflict in main output
+
+SELECT 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1;
+
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1;
+
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50;
+
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1;
+
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1;
+
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50;
+
+SELECT col1, 2 AS col1 FROM v1 ORDER BY col1;
+
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1;
+
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50;
+
+-- Conflict in hidden output
+
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1;
+
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1;
+
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 >
50;
+
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1;
+
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
ORDER BY col1;
+
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
HAVING col1 > 50;
+
+-- Implicit aliases
+
+-- Baseline
+
+SELECT 'col1' FROM v2 ORDER BY col1;
+
+SELECT 'col1' FROM v2 GROUP BY ALL ORDER BY col1;
+
+SELECT 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana';
+
+SELECT col1 AS c, 'col1' FROM v2 ORDER BY col1;
+
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL ORDER BY col1;
+
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana';
+
+-- Conflict in main output
+
+SELECT 'col1', 'col1' FROM v2 ORDER BY col1;
+
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1;
+
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana';
+
+SELECT col1 AS c, 'col1', 'col1' FROM v2 ORDER BY col1;
+
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1;
+
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana';
+
+SELECT col1, 'col1' FROM v2 ORDER BY col1;
+
+SELECT col1, 'col1' FROM v2 GROUP BY ALL ORDER BY col1;
+
+SELECT col1, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana';
+
+-- Conflict in hidden output
+
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1;
+
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY
col1;
+
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1
> 'banana';
+
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1;
+
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
ORDER BY col1;
+
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
HAVING col1 > 'banana';
+
+DROP VIEW v2;
+DROP VIEW v1;
diff --git
a/sql/core/src/test/resources/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
b/sql/core/src/test/resources/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
new file mode 100644
index 000000000000..181f7c9a395a
--- /dev/null
+++
b/sql/core/src/test/resources/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out
@@ -0,0 +1,744 @@
+-- Automatically generated by SQLQueryTestSuite
+-- !query
+CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT col1 FROM VALUES
+ (42), (17), (99), (5), (42),
+ (23), (8), (17), (76), (33),
+ (99), (55), (3), (42), (8)
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT col1 FROM VALUES
+ ('apple'), ('banana'), ('cherry'), ('date'), ('apple'),
+ ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'),
+ ('cherry'), ('mango'), ('orange'), ('apple'), ('grape')
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 ORDER BY col1
+-- !query schema
+struct<col1:int>
+-- !query output
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:int>
+-- !query output
+2
+
+
+-- !query
+SELECT 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query schema
+struct<col1:int>
+-- !query output
+
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 ORDER BY col1
+-- !query schema
+struct<c:int,col1:int>
+-- !query output
+42 2
+17 2
+99 2
+5 2
+42 2
+23 2
+8 2
+17 2
+76 2
+33 2
+99 2
+55 2
+3 2
+42 2
+8 2
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<c:int,col1:int>
+-- !query output
+42 2
+17 2
+99 2
+23 2
+5 2
+8 2
+76 2
+55 2
+33 2
+3 2
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query schema
+struct<c:int,col1:int>
+-- !query output
+55 2
+76 2
+99 2
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1
+-- !query schema
+struct<col1:int,col1:int>
+-- !query output
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+2 3
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.catalyst.ExtendedAnalysisException
+{
+ "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION",
+ "sqlState" : "42703",
+ "messageParameters" : {
+ "objectName" : "`col1`",
+ "proposal" : "`col1`, `col1`"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 59,
+ "stopIndex" : 62,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 57,
+ "stopIndex" : 60,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1
+-- !query schema
+struct<c:int,col1:int,col1:int>
+-- !query output
+3 2 3
+5 2 3
+8 2 3
+8 2 3
+17 2 3
+17 2 3
+23 2 3
+33 2 3
+42 2 3
+42 2 3
+42 2 3
+55 2 3
+76 2 3
+99 2 3
+99 2 3
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<c:int,col1:int,col1:int>
+-- !query output
+3 2 3
+5 2 3
+8 2 3
+17 2 3
+23 2 3
+33 2 3
+42 2 3
+55 2 3
+76 2 3
+99 2 3
+
+
+-- !query
+SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query schema
+struct<c:int,col1:int,col1:int>
+-- !query output
+55 2 3
+76 2 3
+99 2 3
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 ORDER BY col1
+-- !query schema
+struct<col1:int,col1:int>
+-- !query output
+3 2
+5 2
+8 2
+8 2
+17 2
+17 2
+23 2
+33 2
+42 2
+42 2
+42 2
+55 2
+76 2
+99 2
+99 2
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:int,col1:int>
+-- !query output
+3 2
+5 2
+8 2
+17 2
+23 2
+33 2
+42 2
+55 2
+76 2
+99 2
+
+
+-- !query
+SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50
+-- !query schema
+struct<col1:int,col1:int>
+-- !query output
+55 2
+76 2
+99 2
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1
+-- !query schema
+struct<col1:int>
+-- !query output
+3
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:int>
+-- !query output
+3
+
+
+-- !query
+SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 >
50
+-- !query schema
+struct<col1:int>
+-- !query output
+
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL
HAVING col1 > 50
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 'col1' FROM v2 ORDER BY col1
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+col1
+
+
+-- !query
+SELECT 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+
+
+-- !query
+SELECT 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 ORDER BY col1
+-- !query schema
+struct<c:string,col1:string>
+-- !query output
+apple col1
+banana col1
+cherry col1
+date col1
+apple col1
+fig col1
+grape col1
+banana col1
+kiwi col1
+lemon col1
+cherry col1
+mango col1
+orange col1
+apple col1
+grape col1
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<c:string,col1:string>
+-- !query output
+date col1
+cherry col1
+grape col1
+apple col1
+banana col1
+fig col1
+mango col1
+kiwi col1
+lemon col1
+orange col1
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query schema
+struct<c:string,col1:string>
+-- !query output
+cherry col1
+date col1
+fig col1
+grape col1
+kiwi col1
+lemon col1
+mango col1
+orange col1
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 ORDER BY col1
+-- !query schema
+struct<col1:string,col1:string>
+-- !query output
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+col1 col1
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.catalyst.ExtendedAnalysisException
+{
+ "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION",
+ "sqlState" : "42703",
+ "messageParameters" : {
+ "objectName" : "`col1`",
+ "proposal" : "`col1`, `col1`"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 53,
+ "stopIndex" : 56,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 51,
+ "stopIndex" : 54,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 ORDER BY col1
+-- !query schema
+struct<c:string,col1:string,col1:string>
+-- !query output
+apple col1 col1
+apple col1 col1
+apple col1 col1
+banana col1 col1
+banana col1 col1
+cherry col1 col1
+cherry col1 col1
+date col1 col1
+fig col1 col1
+grape col1 col1
+grape col1 col1
+kiwi col1 col1
+lemon col1 col1
+mango col1 col1
+orange col1 col1
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<c:string,col1:string,col1:string>
+-- !query output
+apple col1 col1
+banana col1 col1
+cherry col1 col1
+date col1 col1
+fig col1 col1
+grape col1 col1
+kiwi col1 col1
+lemon col1 col1
+mango col1 col1
+orange col1 col1
+
+
+-- !query
+SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query schema
+struct<c:string,col1:string,col1:string>
+-- !query output
+cherry col1 col1
+date col1 col1
+fig col1 col1
+grape col1 col1
+kiwi col1 col1
+lemon col1 col1
+mango col1 col1
+orange col1 col1
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 ORDER BY col1
+-- !query schema
+struct<col1:string,col1:string>
+-- !query output
+apple col1
+apple col1
+apple col1
+banana col1
+banana col1
+cherry col1
+cherry col1
+date col1
+fig col1
+grape col1
+grape col1
+kiwi col1
+lemon col1
+mango col1
+orange col1
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:string,col1:string>
+-- !query output
+apple col1
+banana col1
+cherry col1
+date col1
+fig col1
+grape col1
+kiwi col1
+lemon col1
+mango col1
+orange col1
+
+
+-- !query
+SELECT col1, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'
+-- !query schema
+struct<col1:string,col1:string>
+-- !query output
+cherry col1
+date col1
+fig col1
+grape col1
+kiwi col1
+lemon col1
+mango col1
+orange col1
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+
+
+-- !query
+SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1
> 'banana'
+-- !query schema
+struct<col1:string>
+-- !query output
+col1
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
ORDER BY col1
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL
HAVING col1 > 'banana'
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+ "errorClass" : "AMBIGUOUS_REFERENCE",
+ "sqlState" : "42704",
+ "messageParameters" : {
+ "name" : "`col1`",
+ "referenceNames" : "[`col1`, `col1`]"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 11,
+ "fragment" : "col1"
+ } ]
+}
+
+
+-- !query
+DROP VIEW v2
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+DROP VIEW v1
+-- !query schema
+struct<>
+-- !query output
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]