Skip to content

Commit

Permalink
[SPARK-3834][SQL] Backticks not correctly handled in subquery aliases
Browse files Browse the repository at this point in the history
The queries like SELECT a.key FROM (SELECT key FROM src) \`a\` does not work as backticks in subquery aliases are not handled properly. This PR fixes that.

Author : ravipesala ravindra.pesalahuawei.com

Author: ravipesala <[email protected]>

Closes apache#2737 from ravipesala/SPARK-3834 and squashes the following commits:

0e0ab98 [ravipesala] Fixing issue in backtick handling for subquery aliases

Conflicts:
	sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
  • Loading branch information
ravipesala authored and marmbrus committed Nov 11, 2014
1 parent 64945f8 commit f4e17cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ private[hive] object HiveQl {
def nodeToRelation(node: Node): LogicalPlan = node match {
case Token("TOK_SUBQUERY",
query :: Token(alias, Nil) :: Nil) =>
Subquery(alias, nodeToPlan(query))
Subquery(cleanIdentifier(alias), nodeToPlan(query))

case Token(laterViewToken(isOuter), selectClause :: relationClause :: Nil) =>
val Token("TOK_SELECT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,30 @@ class SQLQuerySuite extends QueryTest {
GROUP BY key, value
ORDER BY value) a""").collect().toSeq)
}

test("double nested data") {
sparkContext.parallelize(Nested1(Nested2(Nested3(1))) :: Nil).registerTempTable("nested")
checkAnswer(
sql("SELECT f1.f2.f3 FROM nested"),
1)
}

test("test CTAS") {
checkAnswer(sql("CREATE TABLE test_ctas_123 AS SELECT key, value FROM src"), Seq.empty[Row])
checkAnswer(
sql("SELECT key, value FROM test_ctas_123 ORDER BY key"),
sql("SELECT key, value FROM src ORDER BY key").collect().toSeq)
}

test("SPARK-3708 Backticks aren't handled correctly is aliases") {
checkAnswer(
sql("SELECT k FROM (SELECT `key` AS `k` FROM src) a"),
sql("SELECT `key` FROM src").collect().toSeq)
}

test("SPARK-3834 Backticks not correctly handled in subquery aliases") {
checkAnswer(
sql("SELECT a.key FROM (SELECT key FROM src) `a`"),
sql("SELECT `key` FROM src").collect().toSeq)
}
}

0 comments on commit f4e17cd

Please sign in to comment.