Github user nsyca commented on a diff in the pull request:
https://github.com/apache/spark/pull/17191#discussion_r105659975
--- Diff: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
---
@@ -2586,4 +2586,15 @@ class SQLQuerySuite extends QueryTest with
SharedSQLContext {
}
assert(!jobStarted.get(), "Command should not trigger a Spark job.")
}
+
+ test("SPARK-14471 Aliases in SELECT could be used in GROUP BY") {
+ Seq((1, "a", 0), (2, "a", 1), (1, "a", 2)).toDF("k1", "k2", "v")
+ .createOrReplaceTempView("t")
+ checkAnswer(
+ sql("SELECT k1 AS key1, k2 AS key2, SUM(v) FROM t GROUP BY key1,
key2"),
+ Row(1, "a", 2) :: Row(2, "a", 1) :: Nil)
+ checkAnswer(
+ sql("SELECT k1 AS key1, key1 + 1 AS key2, COUNT(1) FROM t GROUP BY
key1, key2"),
+ Row(1, 2, 2) :: Row(2, 3, 1) :: Nil)
+ }
--- End diff --
What if the alias has a collision with a valid column name, like,
`select k1 as k2, k2 from t`
`select k1 as k2 from t group by k1`
`select k1 as k2 from t group by k2`
This would be an interesting test case to add.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]