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: create the struct key properly in struct_extract_sql #2129

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Aug 30, 2023

The issue here was:

>>> sqlglot.parse_one("STRUCT_EXTRACT(foo, bar)").sql(dialect="spark")
'foo.``'

Notice how bar is dropped. The reason is that the identifier created in the following lines has an incorrect AST: there's a Column under the Indentifier node.

def struct_extract_sql(self: Generator, expression: exp.StructExtract) -> str:
this = self.sql(expression, "this")
struct_key = self.sql(exp.Identifier(this=expression.expression.copy(), quoted=True))
return f"{this}.{struct_key}"

@tobymao tobymao merged commit 6a0110a into main Aug 30, 2023
@tobymao tobymao deleted the jo/fix_struct_extract branch August 30, 2023 21:04
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