Skip to content

Commit

Permalink
Actually, this issue has been fixed by 3684fd2.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhuai committed Jan 12, 2015
1 parent d42b707 commit 6cfadd2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ class Analyzer(catalog: Catalog,

aggregateExprs.find { e =>
!isValidAggregateExpression(e.transform {
// Should trim aliases. These aliases can be introduced while resolving unnamed
// expressions like `GetField` and UDF calls, and when a user explicitly assigns
// an alias to a grouping expression in the SELECT clause.
case a: Alias => a.child
// Should trim aliases around `GetField`s. These aliases are introduced while
// resolving struct field accesses, because `GetField` is not a `NamedExpression`.
// (Should we just turn `GetField` into a `NamedExpression`?)
case Alias(g: GetField, _) => g
})
}.foreach { e =>
throw new TreeNodeException(plan, s"Expression not in GROUP BY: $e")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ object PartialAggregation {
// referenced in the second aggregation.
val namedGroupingExpressions: Map[Expression, NamedExpression] = groupingExpressions.map {
case n: NamedExpression => (n, n)
// TODO: When a UDF is used in the group by clause, for example, GROUP BY YEAR(...),
// PartialGroup will not be a proper name.
case other => (other, Alias(other, "PartialGroup")())
}.toMap

Expand Down
11 changes: 0 additions & 11 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -997,17 +997,6 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
dropTempTable("data")
}

test("SPARK-4296 Grouping field with UDF as sub expression") {
registerFunction("triple", (_: Int) * 3)
jsonRDD(sparkContext.makeRDD("""{"a": 1}""" :: Nil)).registerTempTable("data")
checkAnswer(sql("SELECT triple(a) FROM data GROUP BY triple(a)"), 3)
dropTempTable("data")

jsonRDD(sparkContext.makeRDD("""{"a": 1}""" :: Nil)).registerTempTable("data")
checkAnswer(sql("SELECT triple(a) + 1 FROM data GROUP BY triple(a) + 1"), 4)
dropTempTable("data")
}

test("SPARK-4432 Fix attribute reference resolution error when using ORDER BY") {
checkAnswer(
sql("SELECT a + b FROM testData2 ORDER BY a"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,19 @@ class SQLQuerySuite extends QueryTest {
Seq.empty[Row])
}
}

test("SPARK-4296 Grouping field with Hive UDF as sub expression") {
val rdd = sparkContext.makeRDD("""{"a": "str", "b":"1", "c":"1970-01-01 00:00:00"}""" :: Nil)
jsonRDD(rdd).registerTempTable("data")
checkAnswer(
sql("SELECT concat(a, '-', b), year(c) FROM data GROUP BY concat(a, '-', b), year(c)"),
Seq(Seq("str-1", 1970)))

dropTempTable("data")

jsonRDD(rdd).registerTempTable("data")
checkAnswer(sql("SELECT year(c) + 1 FROM data GROUP BY year(c) + 1"), Seq(Seq(1971)))

dropTempTable("data")
}
}

0 comments on commit 6cfadd2

Please sign in to comment.