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-3371][SQL] Renaming a function expression with group by gives error #2511

Closed
wants to merge 3 commits into from

Conversation

ravipesala
Copy link
Contributor

The following code gives error.

sqlContext.registerFunction("len", (s: String) => s.length)
sqlContext.sql("select len(foo) as a, count(1) from t1 group by len(foo)").collect() 

Because SQl parser creates the aliases to the functions in grouping expressions with generated alias names. So if user gives the alias names to the functions inside projection then it does not match the generated alias name of grouping expression.
This kind of queries are working in Hive.
So the fix I have given that if user provides alias to the function in projection then don't generate alias in grouping expression,use the same alias.

@SparkQA
Copy link

SparkQA commented Sep 23, 2014

Can one of the admins verify this patch?

@marmbrus
Copy link
Contributor

ok to test

@SparkQA
Copy link

SparkQA commented Sep 26, 2014

QA tests have started for PR 2511 at commit f8ace79.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Sep 26, 2014

QA tests have finished for PR 2511 at commit f8ace79.

  • This patch passes unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/20839/

@@ -166,7 +186,7 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
val withFilter = f.map(f => Filter(f, base)).getOrElse(base)
val withProjection =
g.map {g =>
Aggregate(assignAliases(g), assignAliases(p), withFilter)
Aggregate(assignAliasesForGroups(g,p), assignAliases(p), withFilter)
Copy link
Contributor

Choose a reason for hiding this comment

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

A simpler solution is to just not assignAliases to the grouping expressions (I'm not sure why we are. That is probably my mistake). That change also seems to also make your test case pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @marmbrus , better we remove assignAliases to grouping expressions.Updated code as per that. Please review.

@SparkQA
Copy link

SparkQA commented Oct 2, 2014

QA tests have started for PR 2511 at commit 9fb973f.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Oct 2, 2014

QA tests have finished for PR 2511 at commit 9fb973f.

  • This patch passes unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/21173/

@marmbrus
Copy link
Contributor

marmbrus commented Oct 2, 2014

Thanks! Merged to master.

@asfgit asfgit closed this in bbdf1de Oct 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants