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

Fix(dataframe): ensure Column.alias preserves quotes #2254

Merged
merged 2 commits into from
Sep 18, 2023

Conversation

georgesittas
Copy link
Collaborator

The issue here was that 1) name was parsed according to Spark, instead of using the session's dialect 2) if quotes were present in name, the whole alias name would be treated as an "unsafe identifier" in to_identifier, which resulted in adding more quotes and thus generating incorrect SQL.


alias: exp.Expression = sqlglot.maybe_parse(name, dialect=SparkSession().dialect)
new_expression = exp.alias_(
self.column_expression, alias.this if isinstance(alias, exp.Column) else name
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I check for exp.Column here because there were some tests where name was avg(...), generated in https://github.com/tobymao/sqlglot/blob/main/sqlglot/dataframe/sql/group.py#L24

@georgesittas georgesittas merged commit 3b654f2 into main Sep 18, 2023
@georgesittas georgesittas deleted the jo/dataframe_alias_quoting_fix branch September 18, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants