Skip to content

Commit 6f98902

Browse files
ravipesalamarmbrus
authored andcommitted
[SPARK-3834][SQL] Backticks not correctly handled in subquery aliases
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 #2737 from ravipesala/SPARK-3834 and squashes the following commits: 0e0ab98 [ravipesala] Fixing issue in backtick handling for subquery aliases
1 parent 421382d commit 6f98902

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ private[hive] object HiveQl {
638638
def nodeToRelation(node: Node): LogicalPlan = node match {
639639
case Token("TOK_SUBQUERY",
640640
query :: Token(alias, Nil) :: Nil) =>
641-
Subquery(alias, nodeToPlan(query))
641+
Subquery(cleanIdentifier(alias), nodeToPlan(query))
642642

643643
case Token(laterViewToken(isOuter), selectClause :: relationClause :: Nil) =>
644644
val Token("TOK_SELECT",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,11 @@ class SQLQuerySuite extends QueryTest {
6868
checkAnswer(
6969
sql("SELECT k FROM (SELECT `key` AS `k` FROM src) a"),
7070
sql("SELECT `key` FROM src").collect().toSeq)
71-
}
71+
}
72+
73+
test("SPARK-3834 Backticks not correctly handled in subquery aliases") {
74+
checkAnswer(
75+
sql("SELECT a.key FROM (SELECT key FROM src) `a`"),
76+
sql("SELECT `key` FROM src").collect().toSeq)
77+
}
7278
}

0 commit comments

Comments
 (0)