Skip to content

Commit 4ffd3a1

Browse files
cloud-fanrxin
authored andcommitted
[SPARK-9371][SQL] fix the support for special chars in column names for hive context
Author: Wenchen Fan <[email protected]> Closes #7684 from cloud-fan/hive and squashes the following commits: da21ffe [Wenchen Fan] fix the support for special chars in column names for hive context
1 parent aa80c64 commit 4ffd3a1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,11 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
13211321
/* Attribute References */
13221322
case Token("TOK_TABLE_OR_COL",
13231323
Token(name, Nil) :: Nil) =>
1324-
UnresolvedAttribute(cleanIdentifier(name))
1324+
UnresolvedAttribute.quoted(cleanIdentifier(name))
13251325
case Token(".", qualifier :: Token(attr, Nil) :: Nil) =>
13261326
nodeToExpr(qualifier) match {
1327-
case UnresolvedAttribute(qualifierName) =>
1328-
UnresolvedAttribute(qualifierName :+ cleanIdentifier(attr))
1327+
case UnresolvedAttribute(nameParts) =>
1328+
UnresolvedAttribute(nameParts :+ cleanIdentifier(attr))
13291329
case other => UnresolvedExtractValue(other, Literal(attr))
13301330
}
13311331

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,4 +1067,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
10671067
)
10681068
TestHive.dropTempTable("test_SPARK8588")
10691069
}
1070+
1071+
test("SPARK-9371: fix the support for special chars in column names for hive context") {
1072+
TestHive.read.json(TestHive.sparkContext.makeRDD(
1073+
"""{"a": {"c.b": 1}, "b.$q": [{"a@!.q": 1}], "q.w": {"w.i&": [1]}}""" :: Nil))
1074+
.registerTempTable("t")
1075+
1076+
checkAnswer(sql("SELECT a.`c.b`, `b.$q`[0].`a@!.q`, `q.w`.`w.i&`[0] FROM t"), Row(1, 1, 1))
1077+
}
10701078
}

0 commit comments

Comments
 (0)