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: conditional statement parsing edge case #2967

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

georgesittas
Copy link
Contributor

This PR aims to fix the following case:

>>> from sqlmesh.core.dialect import parse_one
>>> parse_one("@IF(cond, VACUUM ANALYZE)", dialect="postgres")
'@IF(cond, VACUUM ANALYZE' contains unsupported syntax. Falling back to parsing as a 'Command'.
Alias(
  this=MacroFunc(
    this=Anonymous(
      this=IF,
      expressions=[
        Column(
          this=Identifier(this=cond, quoted=False)),
        Command(this=VACUUM)])),
  alias=Identifier(this=ANALYZE, quoted=False))

The problem is that we're currently producing an Alias node as shown above, which happens because SQLGlot tokenizes both VACUUM and ANALYZE as TokenType.COMMAND, instead of producing a STRING for the latter.

This is a SQLMesh-related edge case, since SQLGlot doesn't generally expect a statement to show within a function, such as @IF in this case.

@georgesittas georgesittas requested review from tobymao and a team July 30, 2024 16:31
@georgesittas georgesittas merged commit 6d1c54b into main Jul 30, 2024
21 checks passed
@georgesittas georgesittas deleted the jo/fix_conditional_stmt_parsing_edge_case branch July 30, 2024 16:46
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