Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-13698][SQL] Fix Analysis Exceptions when Using Backticks in Generate #11538

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,16 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
}

val attributes = clauses.collect {
case Token(a, Nil) => UnresolvedAttribute(a.toLowerCase)
case Token(a, Nil) => UnresolvedAttribute(cleanIdentifier(a.toLowerCase))
}

Generate(generator, join = true, outer = outer, Some(alias.toLowerCase), attributes, child)
Generate(
generator,
join = true,
outer = outer,
Some(cleanIdentifier(alias.toLowerCase)),
attributes,
child)
}

protected def nodeToGenerator(node: ASTNode): Generator = noParseRule("Generator", node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,24 @@ class HiveQlSuite extends SparkFunSuite with BeforeAndAfterAll {
|USING 'cat' AS (`thing1` int, `thing2` string) FROM `default`.`parquet_t1`) AS t
""".stripMargin)
}

test("use backticks in output of Generator") {
val plan = parser.parsePlan(
"""
|SELECT `gentab2`.`gencol2`
|FROM `default`.`src`
|LATERAL VIEW explode(array(array(1, 2, 3))) `gentab1` AS `gencol1`
|LATERAL VIEW explode(`gentab1`.`gencol1`) `gentab2` AS `gencol2`
""".stripMargin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

test("use escaped backticks in output of Generator") {
val plan = parser.parsePlan(
"""
|SELECT `gen``tab2`.`gen``col2`
|FROM `default`.`src`
|LATERAL VIEW explode(array(array(1, 2, 3))) `gen``tab1` AS `gen``col1`
|LATERAL VIEW explode(`gen``tab1`.`gen``col1`) `gen``tab2` AS `gen``col2`
""".stripMargin)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
checkAnswer(
sql("SELECT ints FROM nestedArray LATERAL VIEW explode(a.b) a AS ints"),
Row(1) :: Row(2) :: Row(3) :: Nil)

checkAnswer(
sql("SELECT `ints` FROM nestedArray LATERAL VIEW explode(a.b) `a` AS `ints`"),
Row(1) :: Row(2) :: Row(3) :: Nil)

checkAnswer(
sql("SELECT `a`.`ints` FROM nestedArray LATERAL VIEW explode(a.b) `a` AS `ints`"),
Row(1) :: Row(2) :: Row(3) :: Nil)

checkAnswer(
sql(
"""
|SELECT `weird``tab`.`weird``col`
|FROM nestedArray
|LATERAL VIEW explode(a.b) `weird``tab` AS `weird``col`
""".stripMargin),
Row(1) :: Row(2) :: Row(3) :: Nil)
}

test("SPARK-4512 Fix attribute reference resolution error when using SORT BY") {
Expand Down