Skip to content

Commit 2aa4ad9

Browse files
committed
[SPARK-25769][SQL]change nested columns from to .
1 parent c296254 commit 2aa4ad9

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ case class UnresolvedTableValuedFunction(
9898
*/
9999
case class UnresolvedAttribute(nameParts: Seq[String]) extends Attribute with Unevaluable {
100100

101-
def name: String =
102-
nameParts.map(n => if (n.contains(".")) s"`$n`" else n).mkString(".")
101+
def name: String = {
102+
nameParts.map(n =>
103+
if (n.contains(".")) s"`$n`"
104+
else {
105+
if (nameParts.length > 1) {
106+
s"`$n`"
107+
} else {
108+
n
109+
}
110+
}
111+
).mkString(".")
112+
}
103113

104114
override def exprId: ExprId = throw new UnresolvedException(this, "exprId")
105115
override def dataType: DataType = throw new UnresolvedException(this, "dataType")

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SELECT t1.i1 FROM t1, mydb1.t1
8181
struct<>
8282
-- !query 9 output
8383
org.apache.spark.sql.AnalysisException
84-
Reference 't1.i1' is ambiguous, could be: mydb1.t1.i1, mydb1.t1.i1.; line 1 pos 7
84+
Reference '`t1`.`i1`' is ambiguous, could be: mydb1.t1.i1, mydb1.t1.i1.; line 1 pos 7
8585

8686

8787
-- !query 10
@@ -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-
Reference 'mydb1.t1.i1' is ambiguous, could be: mydb1.t1.i1, mydb1.t1.i1.; line 1 pos 7
93+
Reference '`mydb1`.`t1`.`i1`' is ambiguous, could be: mydb1.t1.i1, mydb1.t1.i1.; line 1 pos 7
9494

9595

9696
-- !query 11
@@ -108,7 +108,7 @@ SELECT t1.i1 FROM t1, mydb2.t1
108108
struct<>
109109
-- !query 12 output
110110
org.apache.spark.sql.AnalysisException
111-
Reference 't1.i1' is ambiguous, could be: mydb1.t1.i1, mydb2.t1.i1.; line 1 pos 7
111+
Reference '`t1`.`i1`' is ambiguous, could be: mydb1.t1.i1, mydb2.t1.i1.; line 1 pos 7
112112

113113

114114
-- !query 13
@@ -134,7 +134,7 @@ SELECT t1.i1 FROM t1, mydb1.t1
134134
struct<>
135135
-- !query 15 output
136136
org.apache.spark.sql.AnalysisException
137-
Reference 't1.i1' is ambiguous, could be: mydb2.t1.i1, mydb1.t1.i1.; line 1 pos 7
137+
Reference '`t1`.`i1`' is ambiguous, could be: mydb2.t1.i1, mydb1.t1.i1.; line 1 pos 7
138138

139139

140140
-- !query 16
@@ -152,7 +152,7 @@ SELECT t1.i1 FROM t1, mydb2.t1
152152
struct<>
153153
-- !query 17 output
154154
org.apache.spark.sql.AnalysisException
155-
Reference 't1.i1' is ambiguous, could be: mydb2.t1.i1, mydb2.t1.i1.; line 1 pos 7
155+
Reference '`t1`.`i1`' is ambiguous, could be: mydb2.t1.i1, mydb2.t1.i1.; line 1 pos 7
156156

157157

158158
-- !query 18
@@ -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: [mydb2.t1.i1, mydb2.t1.i1]; line 1 pos 7
164+
cannot resolve '`db1`.`t1`.`i1`' given input columns: [mydb2.t1.i1, mydb2.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: [mydb1.t1.i1]; line 1 pos 7
189+
cannot resolve '`mydb1`.`t1`' given input columns: [mydb1.t1.i1]; line 1 pos 7
190190

191191

192192
-- !query 22
@@ -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: [mydb2.t1.i1]; line 1 pos 7
224+
cannot resolve '`mydb1`.`t1`.`i1`' given input columns: [mydb2.t1.i1]; line 1 pos 7
225225

226226

227227
-- !query 26

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ DESC FORMATTED desc_complex_col_table col.x
188188
struct<>
189189
-- !query 14 output
190190
org.apache.spark.sql.AnalysisException
191-
DESC TABLE COLUMN command does not support nested data types: col.x;
191+
DESC TABLE COLUMN command does not support nested data types: `col`.`x`;
192192

193193

194194
-- !query 15

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SELECT t.`(a)?+.+` FROM testData2 t WHERE a = 1
4545
struct<>
4646
-- !query 4 output
4747
org.apache.spark.sql.AnalysisException
48-
cannot resolve 't.`(a)?+.+`' given input columns: [t.A, t.B, t.c, t.d]; line 1 pos 7
48+
cannot resolve '`t`.`(a)?+.+`' given input columns: [t.A, t.B, t.c, t.d]; line 1 pos 7
4949

5050

5151
-- !query 5

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
11431143
|order by struct.a, struct.b
11441144
|""".stripMargin)
11451145
}
1146-
assert(error.message contains "cannot resolve '`struct.a`' given input columns: [a, b]")
1146+
assert(error.message contains "cannot resolve '`struct`.`a`' given input columns: [a, b]")
11471147

11481148
}
11491149

@@ -2702,7 +2702,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
27022702

27032703
val e = intercept[AnalysisException](sql("SELECT v.i from (SELECT i FROM v)"))
27042704
assert(e.message ==
2705-
"cannot resolve '`v.i`' given input columns: [__auto_generated_subquery_name.i]")
2705+
"cannot resolve '`v`.`i`' given input columns: [__auto_generated_subquery_name.i]")
27062706

27072707
checkAnswer(sql("SELECT __auto_generated_subquery_name.i from (SELECT i FROM v)"), Row(1))
27082708
}

0 commit comments

Comments
 (0)