Skip to content

Commit

Permalink
[SPARK-8358] [SQL] Wait for child resolution when resolving generators
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marmbrus committed Jun 14, 2015
1 parent ea7fd2f commit 9073a42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,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,
Expand All @@ -572,7 +574,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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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"),
Expand Down

0 comments on commit 9073a42

Please sign in to comment.