Skip to content

Commit 47db754

Browse files
fix the bug in unittest
1 parent 44ac17d commit 47db754

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
198198
resolveGetField(e, fieldName, resolver)
199199
}
200200

201+
// TODO the alias name is quite tricky to me, set it to _col1, _col2.. ?
202+
// Set it as original attribute name like "a.b.c" seems still confusing,
203+
// and we may never reference this column by its name (with "."), except
204+
// people write SQL like: SELECT a.b.c as newCol FROM nestedTable, which
205+
// explicitly specifying the alias name for the output column
201206
Some(Alias(fieldExprs, name)())
202207

203208
// No matches.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
6868
"""
6969
|select attribute, sum(cnt)
7070
|from (
71-
| select nested.attribute, count(*) as cnt
71+
| select nested.attribute as attribute, count(*) as cnt
7272
| from rows
7373
| group by nested.attribute) a
7474
|group by attribute

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class SQLQuerySuite extends QueryTest {
4848
Row(1) :: Row(2) :: Row(3) :: Nil)
4949
}
5050

51+
test("SPARK-6145 insert into table by selecting data from a nested table") {
52+
jsonRDD(sparkContext.parallelize(
53+
"""{"a": {"a": {"a": 1}}, "c": 1}""" :: Nil)).registerTempTable("nestedOrder")
54+
55+
sql("CREATE TABLE gen_tmp_6145 (key Int)")
56+
sql("INSERT INTO table gen_tmp_6145 SELECT a.a.a from nestedOrder")
57+
sql("DROP TABLE gen_tmp_6145")
58+
}
59+
5160
test("SPARK-4512 Fix attribute reference resolution error when using SORT BY") {
5261
checkAnswer(
5362
sql("SELECT * FROM (SELECT key + key AS a FROM src SORT BY value) t ORDER BY t.a"),

0 commit comments

Comments
 (0)