Skip to content

Commit de14086

Browse files
gatorsmilecloud-fan
authored andcommitted
[SPARK-21295][SQL] Use qualified names in error message for missing references
### What changes were proposed in this pull request? It is strange to see the following error message. Actually, the column is from another table. ``` cannot resolve '`right.a`' given input columns: [a, c, d]; ``` After the PR, the error message looks like ``` cannot resolve '`right.a`' given input columns: [left.a, right.c, right.d]; ``` ### How was this patch tested? Added a test case Author: gatorsmile <[email protected]> Closes #18520 from gatorsmile/removeSQLConf.
1 parent daabf42 commit de14086

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait CheckAnalysis extends PredicateHelper {
8686
case operator: LogicalPlan =>
8787
operator transformExpressionsUp {
8888
case a: Attribute if !a.resolved =>
89-
val from = operator.inputSet.map(_.name).mkString(", ")
89+
val from = operator.inputSet.map(_.qualifiedName).mkString(", ")
9090
a.failAnalysis(s"cannot resolve '${a.sql}' given input columns: [$from]")
9191

9292
case e: Expression if e.checkInputDataTypes().isFailure =>

sql/core/src/test/resources/sql-tests/results/columnresolution-negative.sql.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ SELECT mydb1.t1.i1 FROM t1, mydb1.t1
9090
struct<>
9191
-- !query 10 output
9292
org.apache.spark.sql.AnalysisException
93-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1, i1]; line 1 pos 7
93+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1, t1.i1]; line 1 pos 7
9494

9595

9696
-- !query 11
@@ -161,7 +161,7 @@ SELECT db1.t1.i1 FROM t1, mydb2.t1
161161
struct<>
162162
-- !query 18 output
163163
org.apache.spark.sql.AnalysisException
164-
cannot resolve '`db1.t1.i1`' given input columns: [i1, i1]; line 1 pos 7
164+
cannot resolve '`db1.t1.i1`' given input columns: [t1.i1, t1.i1]; line 1 pos 7
165165

166166

167167
-- !query 19
@@ -186,7 +186,7 @@ SELECT mydb1.t1 FROM t1
186186
struct<>
187187
-- !query 21 output
188188
org.apache.spark.sql.AnalysisException
189-
cannot resolve '`mydb1.t1`' given input columns: [i1]; line 1 pos 7
189+
cannot resolve '`mydb1.t1`' given input columns: [t1.i1]; line 1 pos 7
190190

191191

192192
-- !query 22
@@ -204,7 +204,7 @@ SELECT t1 FROM mydb1.t1
204204
struct<>
205205
-- !query 23 output
206206
org.apache.spark.sql.AnalysisException
207-
cannot resolve '`t1`' given input columns: [i1]; line 1 pos 7
207+
cannot resolve '`t1`' given input columns: [t1.i1]; line 1 pos 7
208208

209209

210210
-- !query 24
@@ -221,7 +221,7 @@ SELECT mydb1.t1.i1 FROM t1
221221
struct<>
222222
-- !query 25 output
223223
org.apache.spark.sql.AnalysisException
224-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1]; line 1 pos 7
224+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1]; line 1 pos 7
225225

226226

227227
-- !query 26

sql/core/src/test/resources/sql-tests/results/columnresolution-views.sql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ SELECT global_temp.view1.i1 FROM global_temp.view1
105105
struct<>
106106
-- !query 12 output
107107
org.apache.spark.sql.AnalysisException
108-
cannot resolve '`global_temp.view1.i1`' given input columns: [i1]; line 1 pos 7
108+
cannot resolve '`global_temp.view1.i1`' given input columns: [view1.i1]; line 1 pos 7
109109

110110

111111
-- !query 13

sql/core/src/test/resources/sql-tests/results/columnresolution.sql.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SELECT mydb1.t1.i1 FROM t1
9696
struct<>
9797
-- !query 11 output
9898
org.apache.spark.sql.AnalysisException
99-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1]; line 1 pos 7
99+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1]; line 1 pos 7
100100

101101

102102
-- !query 12
@@ -105,7 +105,7 @@ SELECT mydb1.t1.i1 FROM mydb1.t1
105105
struct<>
106106
-- !query 12 output
107107
org.apache.spark.sql.AnalysisException
108-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1]; line 1 pos 7
108+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1]; line 1 pos 7
109109

110110

111111
-- !query 13
@@ -154,7 +154,7 @@ SELECT mydb1.t1.i1 FROM mydb1.t1
154154
struct<>
155155
-- !query 18 output
156156
org.apache.spark.sql.AnalysisException
157-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1]; line 1 pos 7
157+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1]; line 1 pos 7
158158

159159

160160
-- !query 19
@@ -270,7 +270,7 @@ SELECT * FROM mydb1.t3 WHERE c1 IN
270270
struct<>
271271
-- !query 32 output
272272
org.apache.spark.sql.AnalysisException
273-
cannot resolve '`mydb1.t4.c3`' given input columns: [c2, c3]; line 2 pos 42
273+
cannot resolve '`mydb1.t4.c3`' given input columns: [t4.c2, t4.c3]; line 2 pos 42
274274

275275

276276
-- !query 33
@@ -287,7 +287,7 @@ SELECT mydb1.t1.i1 FROM t1, mydb2.t1
287287
struct<>
288288
-- !query 34 output
289289
org.apache.spark.sql.AnalysisException
290-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1, i1]; line 1 pos 7
290+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1, t1.i1]; line 1 pos 7
291291

292292

293293
-- !query 35
@@ -296,7 +296,7 @@ SELECT mydb1.t1.i1 FROM mydb1.t1, mydb2.t1
296296
struct<>
297297
-- !query 35 output
298298
org.apache.spark.sql.AnalysisException
299-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1, i1]; line 1 pos 7
299+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1, t1.i1]; line 1 pos 7
300300

301301

302302
-- !query 36
@@ -313,7 +313,7 @@ SELECT mydb1.t1.i1 FROM t1, mydb1.t1
313313
struct<>
314314
-- !query 37 output
315315
org.apache.spark.sql.AnalysisException
316-
cannot resolve '`mydb1.t1.i1`' given input columns: [i1, i1]; line 1 pos 7
316+
cannot resolve '`mydb1.t1.i1`' given input columns: [t1.i1, t1.i1]; line 1 pos 7
317317

318318

319319
-- !query 38
@@ -402,7 +402,7 @@ SELECT mydb1.t5.t5.i1 FROM mydb1.t5
402402
struct<>
403403
-- !query 48 output
404404
org.apache.spark.sql.AnalysisException
405-
cannot resolve '`mydb1.t5.t5.i1`' given input columns: [i1, t5]; line 1 pos 7
405+
cannot resolve '`mydb1.t5.t5.i1`' given input columns: [t5.i1, t5.t5]; line 1 pos 7
406406

407407

408408
-- !query 49
@@ -411,7 +411,7 @@ SELECT mydb1.t5.t5.i2 FROM mydb1.t5
411411
struct<>
412412
-- !query 49 output
413413
org.apache.spark.sql.AnalysisException
414-
cannot resolve '`mydb1.t5.t5.i2`' given input columns: [i1, t5]; line 1 pos 7
414+
cannot resolve '`mydb1.t5.t5.i2`' given input columns: [t5.i1, t5.t5]; line 1 pos 7
415415

416416

417417
-- !query 50

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ SELECT a AS k, COUNT(b) FROM testData GROUP BY k
202202
struct<>
203203
-- !query 21 output
204204
org.apache.spark.sql.AnalysisException
205-
cannot resolve '`k`' given input columns: [a, b]; line 1 pos 47
205+
cannot resolve '`k`' given input columns: [testdata.a, testdata.b]; line 1 pos 47
206206

207207

208208
-- !query 22

sql/core/src/test/resources/sql-tests/results/table-aliases.sql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ SELECT a AS col1, b AS col2 FROM testData AS t(c, d)
6060
struct<>
6161
-- !query 6 output
6262
org.apache.spark.sql.AnalysisException
63-
cannot resolve '`a`' given input columns: [c, d]; line 1 pos 7
63+
cannot resolve '`a`' given input columns: [t.c, t.d]; line 1 pos 7

sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,9 @@ class SubquerySuite extends QueryTest with SharedSQLContext {
870870

871871
test("SPARK-20688: correctly check analysis for scalar sub-queries") {
872872
withTempView("t") {
873-
Seq(1 -> "a").toDF("i", "j").createTempView("t")
873+
Seq(1 -> "a").toDF("i", "j").createOrReplaceTempView("t")
874874
val e = intercept[AnalysisException](sql("SELECT (SELECT count(*) FROM t WHERE a = 1)"))
875-
assert(e.message.contains("cannot resolve '`a`' given input columns: [i, j]"))
875+
assert(e.message.contains("cannot resolve '`a`' given input columns: [t.i, t.j]"))
876876
}
877877
}
878878
}

0 commit comments

Comments
 (0)