Skip to content

Commit 3508ce8

Browse files
ravipesalamarmbrus
authored andcommitted
[SPARK-3708][SQL] Backticks aren't handled correctly is aliases
The below query gives error sql("SELECT k FROM (SELECT \`key\` AS \`k\` FROM src) a") It gives error because the aliases are not cleaned so it could not be resolved in further processing. Author: ravipesala <[email protected]> Closes #2594 from ravipesala/SPARK-3708 and squashes the following commits: d55db54 [ravipesala] Fixed SPARK-3708 (Backticks aren't handled correctly is aliases)
1 parent d61f2c1 commit 3508ce8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
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
@@ -855,7 +855,7 @@ private[hive] object HiveQl {
855855

856856
case Token("TOK_SELEXPR",
857857
e :: Token(alias, Nil) :: Nil) =>
858-
Some(Alias(nodeToExpr(e), alias)())
858+
Some(Alias(nodeToExpr(e), cleanIdentifier(alias))())
859859

860860
/* Hints are ignored */
861861
case Token("TOK_HINTLIST", _) => None

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ class SQLQuerySuite extends QueryTest {
6363
sql("SELECT key, value FROM test_ctas_123 ORDER BY key"),
6464
sql("SELECT key, value FROM src ORDER BY key").collect().toSeq)
6565
}
66+
67+
test("SPARK-3708 Backticks aren't handled correctly is aliases") {
68+
checkAnswer(
69+
sql("SELECT k FROM (SELECT `key` AS `k` FROM src) a"),
70+
sql("SELECT `key` FROM src").collect().toSeq)
71+
}
6672
}

0 commit comments

Comments
 (0)