[SPARK-8358] [SQL] Wait for child resolution when resolving generators
Author: Michael Armbrust <michael@databricks.com>
Closes #6811 from marmbrus/aliasExplodeStar and squashes the following commits:
fbd2065 [Michael Armbrust] more style
806a373 [Michael Armbrust] fix style
7cbb530 [Michael Armbrust] [SPARK-8358][SQL] Wait for child resolution when resolving generatorsa
(cherry picked from commit 9073a426e4
)
Signed-off-by: Michael Armbrust <michael@databricks.com>
This commit is contained in:
parent
4634be5a7d
commit
2805d145e3
|
@ -561,7 +561,9 @@ class Analyzer(
|
|||
private object AliasedGenerator {
|
||||
def unapply(e: Expression): Option[(Generator, Seq[String])] = e match {
|
||||
case Alias(g: Generator, name)
|
||||
if g.elementTypes.size > 1 && java.util.regex.Pattern.matches("_c[0-9]+", name) => {
|
||||
if g.resolved &&
|
||||
g.elementTypes.size > 1 &&
|
||||
java.util.regex.Pattern.matches("_c[0-9]+", name) => {
|
||||
// Assume the default name given by parser is "_c[0-9]+",
|
||||
// TODO in long term, move the naming logic from Parser to Analyzer.
|
||||
// In projection, Parser gave default name for TGF as does for normal UDF,
|
||||
|
@ -570,7 +572,7 @@ class Analyzer(
|
|||
// Let's simply ignore the default given name for this case.
|
||||
Some((g, Nil))
|
||||
}
|
||||
case Alias(g: Generator, name) if g.elementTypes.size > 1 =>
|
||||
case Alias(g: Generator, name) if g.resolved && g.elementTypes.size > 1 =>
|
||||
// If not given the default names, and the TGF with multiple output columns
|
||||
failAnalysis(
|
||||
s"""Expect multiple names given for ${g.getClass.getName},
|
||||
|
|
|
@ -132,6 +132,14 @@ class DataFrameSuite extends QueryTest {
|
|||
)
|
||||
}
|
||||
|
||||
test("explode alias and star") {
|
||||
val df = Seq((Array("a"), 1)).toDF("a", "b")
|
||||
|
||||
checkAnswer(
|
||||
df.select(explode($"a").as("a"), $"*"),
|
||||
Row("a", Seq("a"), 1) :: Nil)
|
||||
}
|
||||
|
||||
test("selectExpr") {
|
||||
checkAnswer(
|
||||
testData.selectExpr("abs(key)", "value"),
|
||||
|
|
Loading…
Reference in a new issue