aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWenchen Fan <cloud0fan@outlook.com>2015-07-26 23:58:03 -0700
committerReynold Xin <rxin@databricks.com>2015-07-26 23:58:03 -0700
commit4ffd3a1db5ecff653b02aa325786e734351c8bd2 (patch)
tree876da425614d16f71420600088dc469fb1a78f63
parentaa80c64fcf9626b3720ee000a653db9266b74839 (diff)
downloadspark-4ffd3a1db5ecff653b02aa325786e734351c8bd2.tar.gz
spark-4ffd3a1db5ecff653b02aa325786e734351c8bd2.tar.bz2
spark-4ffd3a1db5ecff653b02aa325786e734351c8bd2.zip
[SPARK-9371][SQL] fix the support for special chars in column names for hive context
Author: Wenchen Fan <cloud0fan@outlook.com> 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
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala6
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala8
2 files changed, 11 insertions, 3 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
index 620b8a44d8..2f79b0aad0 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
@@ -1321,11 +1321,11 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
/* Attribute References */
case Token("TOK_TABLE_OR_COL",
Token(name, Nil) :: Nil) =>
- UnresolvedAttribute(cleanIdentifier(name))
+ UnresolvedAttribute.quoted(cleanIdentifier(name))
case Token(".", qualifier :: Token(attr, Nil) :: Nil) =>
nodeToExpr(qualifier) match {
- case UnresolvedAttribute(qualifierName) =>
- UnresolvedAttribute(qualifierName :+ cleanIdentifier(attr))
+ case UnresolvedAttribute(nameParts) =>
+ UnresolvedAttribute(nameParts :+ cleanIdentifier(attr))
case other => UnresolvedExtractValue(other, Literal(attr))
}
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index 013936377b..8371dd0716 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -1067,4 +1067,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
)
TestHive.dropTempTable("test_SPARK8588")
}
+
+ test("SPARK-9371: fix the support for special chars in column names for hive context") {
+ TestHive.read.json(TestHive.sparkContext.makeRDD(
+ """{"a": {"c.b": 1}, "b.$q": [{"a@!.q": 1}], "q.w": {"w.i&": [1]}}""" :: Nil))
+ .registerTempTable("t")
+
+ checkAnswer(sql("SELECT a.`c.b`, `b.$q`[0].`a@!.q`, `q.w`.`w.i&`[0] FROM t"), Row(1, 1, 1))
+ }
}