Skip to content

fix: Add alias_tokens parameter to _parse_join() for sqlglot 30.9.0 compatibility - #5847

Open
iawanish wants to merge 6 commits into
SQLMesh:mainfrom
iawanish:fix/sqlglot-30-9-compatibility-clean
Open

iawanish wants to merge 6 commits into
SQLMesh:mainfrom
iawanish:fix/sqlglot-30-9-compatibility-clean

Conversation

@iawanish

@iawanish iawanish commented Jun 18, 2026 •

Copy link
Copy Markdown

Description

Fixes #5840
This PR fixes compatibility with sqlglot 30.9.0 by updating the overridden _parse_join() method in sqlmesh/core/dialect.py to match the upstream parser signature.

Problem

With sqlglot 30.9.0+, SQLMesh raises:

TypeError: _parse_join() got an unexpected keyword argument 'alias_tokens'

This happens because sqlglot introduced the alias_tokens parameter in Parser._parse_join(), while SQLMesh's override was still using the older method signature.

Changes

  • Added the optional alias_tokens parameter to _parse_join().
  • Forwarded alias_tokens to the internal __parse_join() calls.
  • Preserved backward compatibility by making the parameter optional.

This change allows SQLMesh to work correctly with sqlglot 30.9.0+ without affecting existing behavior.

Test Plan

  • Tested with sqlglot==30.9.0.
  • Verified that the previous TypeError no longer occurs.
  • Tested the DB2 adapter using the external DB2 sqlglot dialect.
  • Confirmed that SQL parsing behaves as expected after the change.

Checklist

  • I have run make style and fixed any issues (ruff, ruff-format and mypy pass via pre-commit)
  • I have added tests for my changes (if applicable) - no new tests; the existing parser/dialect tests exercise _parse_join
  • All existing tests pass (make fast-test) - relying on CI; locally tests/core/test_dialect.py and tests/core/engine_adapter/test_db2.py pass on sqlglot 30.9.0
  • My commits are signed off (git commit -s) per the DCO

Summary by CodeRabbit

  • Bug Fixes
    • Improved parsing of SQL joins with aliases, including joins wrapped in macros.
  • Chores
    • Updated the SQL parsing dependency.

…ompatibility

- Add missing alias_tokens parameter to _parse_join() method signature
- Pass alias_tokens to internal __parse_join() calls
- Maintain backward compatibility with optional parameter
- Fixes TypeError when using sqlglot 30.9.0 or later

Resolves compatibility issue where SQLMesh's _parse_join() override
was incompatible with sqlglot 30.9.0's updated method signature.

Signed-off-by: Awanish Gupta <awanishgupta159@gmail.com>
@StuffbyYuki

StuffbyYuki commented Jun 20, 2026 •

Copy link
Copy Markdown
Collaborator

@iawanish Thanks for the PR!

A few nits:

  • perhaps fix the title typo, correct the “tests added” checklist item, and confirm CI passes.
  • If the goal is official sqlglot 30.9 support (not just compatibility when users override the pin), consider a follow-up to bump sqlglot~=30.9.0 and run the full test suite.

Also it looks like a bunch of ci tests failed. Prob due to sqlglot version changes in this pr

- Update sqlglot dependency from ~=30.8.0 to ~=30.9.0
- This makes sqlglot 30.9.0 the officially supported version
- Works in conjunction with the alias_tokens parameter fix
- Enables full sqlglot 30.9.0 feature support

Signed-off-by: Awanish Gupta <awanishgupta159@gmail.com>
@iawanish
iawanish force-pushed the fix/sqlglot-30-9-compatibility-clean branch from 83ab276 to 0c1abe1 Compare June 22, 2026 10:42
iawanish and others added 3 commits June 24, 2026 08:42
The previous implementation used self.__parse_join() which relies on Python's
name mangling and doesn't work correctly. This changes it to use super(Parser, self)._parse_join()
which properly calls the parent class method.

This fixes the mypy error: Parser has no attribute __parse_join

Signed-off-by: Awanish Gupta <awanishgupta159@gmail.com>
@cmgoffena13

Copy link
Copy Markdown
Collaborator

@iawanish -- initial failure is the mypy check: 2026-10-21T02:01:09.0810847Z sqlmesh/core/dialect.py:328: error: "_parse_join" undefined in superclass [misc] -- it will need to be fixed before we can merge. You can validate by running make style locally to trigger mypy

Signed-off-by: IBM Db2 Eco System <Hdm-dev-persona-db2-eco-system@ibm.com>
@iawanish iawanish changed the title fix: Add alias_tokens parameter to _parse_join() for sqlglot 30.9.0 compactibilty fix: Add alias_tokens parameter to _parse_join() for sqlglot 30.9.0 compatibility Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The required sqlglot version constraint changed to ~=30.9.0. The _parse_join override now accepts alias_tokens and forwards it to the underlying parser for ordinary and macro-wrapped joins.

Changes: sqlglot compatibility

Layer / File(s) Summary
sqlglot 30.9.0 join parser compatibility
pyproject.toml, sqlmesh/core/dialect.py
The required sqlglot constraint changed to ~=30.9.0. _parse_join accepts and forwards alias_tokens in both join paths. The ordinary-join path continues to pass parse_bracket.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested reviewers: mday-io, stuffbyyuki

Merge Risk: Minimal · up to b190d

This change lets SQLMesh's join parser work with sqlglot 30.9.0, which fixes the TypeError reported for external dialect plugins. No concrete merge-blocking risk was found. Confirm that CI passes before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding an alias_tokens parameter to _parse_join() to fix compatibility with sqlglot 30.9.0. The changeset matches this. The title is 81 characters, which is longer tha…
Linked Issues check Passed Issue #5840 requires either (1) support for sqlglot 30.9.0 or (2) a forward-compatible _parse_join() override that accepts the new alias_tokens argument. The reviewed head implements option 2. In …
Out of Scope Changes check Passed The sqlmesh/core/dialect.py diff changes only the _parse_join() override. It adds the alias_tokens parameter, forwards it, and adds formatting and a # type: ignore placement on the `__parse_jo…
Description check Passed The description follows the template. It has a Description section that explains the problem (sqlglot 30.9.0 raises TypeError on the alias_tokens argument), lists the changes, and gives a Test Plan. I…
Full details: Title check

Explanation

The title names the main change: adding an alias_tokens parameter to _parse_join() to fix compatibility with sqlglot 30.9.0. The changeset matches this. The title is 81 characters, which is longer than ideal, but it stays specific and accurate.

Full details: Linked Issues check

Explanation

Issue #5840 requires either (1) support for sqlglot 30.9.0 or (2) a forward-compatible _parse_join() override that accepts the new alias_tokens argument. The reviewed head implements option 2. In sqlmesh/core/dialect.py, _parse_join() now accepts alias_tokens: t.Optional[t.Collection[TokenType]] = None. It forwards this value to self.__parse_join(...) on the ordinary-join path and to the macro-wrapped JOIN path. The parameter is optional, so existing callers with the old signature still work. The fix matches the 30.9.0 signature shown in the issue. The PR does not add new tests. The issue does not list automated tests as a requirement. The author reports that make fast-test passes. This review did not run tests, so runtime behavior under sqlglot 30.9.0 rests on the code diff and the author's report.

Full details: Out of Scope Changes check

Explanation

The sqlmesh/core/dialect.py diff changes only the _parse_join() override. It adds the alias_tokens parameter, forwards it, and adds formatting and a # type: ignore placement on the __parse_join call. All of these support issue #5840. The raw summary reports a pyproject.toml change from sqlglot~=30.8.0 to ~=30.9.0. This matches the issue title and its option 1 (upgrade the pin). The pyproject.toml diff could not be read in this review because changed blobs were unavailable. The pin change therefore rests on the AI-generated summary and the PR description. Even so, the pin change relates directly to #5840 and does not appear unrelated.

Full details: Description check

Explanation

The description follows the template. It has a Description section that explains the problem (sqlglot 30.9.0 raises TypeError on the alias_tokens argument), lists the changes, and gives a Test Plan. It also includes the checklist. Gaps: the description does not say whether the sqlglot dependency bump is in scope. The raw summary shows the pyproject.toml pin changed from ~=30.8.0 to ~=30.9.0, but the description never mentions that change. The checklist has the tests item unchecked, and the full fast-test run is not confirmed locally. The description says the fix is for compatibility, but the PR objectives indicate a reviewer asked whether official 30.9 support is intended. The description also uses the phrase 'existing tests exercise _parse_join' without naming a specific test.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d5e09791-6bf7-4a6b-9c0b-b1eb678dde94
Commits

Reviewing files that changed from the base of the PR and between c1cc16b and b190d9b.

Files selected for processing: 2

  • pyproject.toml
  • sqlmesh/core/dialect.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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.

Upgrade to sqlglot 30.9.0 to support external dialect plugins

4 participants