fix(exasol)!: qualified select list with "LOCAL"#6450
Merged
georgesittas merged 5 commits intotobymao:mainfrom Dec 8, 2025
Merged
fix(exasol)!: qualified select list with "LOCAL"#6450georgesittas merged 5 commits intotobymao:mainfrom
georgesittas merged 5 commits intotobymao:mainfrom
Conversation
VaggelisD
reviewed
Dec 5, 2025
tests/dialects/test_exasol.py
Outdated
Comment on lines
+685
to
+688
| self.validate_identity( | ||
| 'SELECT a_year AS a_year FROM "LOCAL" GROUP BY "LOCAL".a_year', | ||
| 'SELECT a_year AS a_year FROM "LOCAL" GROUP BY "LOCAL".a_year', | ||
| ) |
Collaborator
There was a problem hiding this comment.
The output SQL is identical to input, we don't need to redefine it
Suggested change
| self.validate_identity( | |
| 'SELECT a_year AS a_year FROM "LOCAL" GROUP BY "LOCAL".a_year', | |
| 'SELECT a_year AS a_year FROM "LOCAL" GROUP BY "LOCAL".a_year', | |
| ) | |
| self.validate_identity( | |
| 'SELECT a_year AS a_year FROM "LOCAL" GROUP BY "LOCAL".a_year' | |
| ) |
tests/dialects/test_exasol.py
Outdated
Comment on lines
+689
to
+692
| self.validate_identity( | ||
| "SELECT YEAR(current_date) AS current_year, current_year + 1 AS next_year", | ||
| "SELECT YEAR(CURRENT_DATE) AS current_year, LOCAL.current_year + 1 AS next_year", | ||
| ) |
Collaborator
There was a problem hiding this comment.
Does the input query work on Exasol? If not, we shouldn't be adding validate_identity that the input SQL does not work on that engine, those should be done through validate_all as you have done for DBX
sqlglot/dialects/exasol.py
Outdated
Comment on lines
+115
to
+117
| alias_node = sel.args.get("alias") | ||
| if alias_node and alias_node.name: | ||
| seen_aliases[alias_node.name] = bool(alias_node.args.get("quoted")) |
Collaborator
There was a problem hiding this comment.
Afaict this can be simplified to:
Suggested change
| alias_node = sel.args.get("alias") | |
| if alias_node and alias_node.name: | |
| seen_aliases[alias_node.name] = bool(alias_node.args.get("quoted")) | |
| seen_aliases[sel.alias] = bool(alias_node.args.get("quoted")) |
georgesittas
approved these changes
Dec 8, 2025
georgesittas
pushed a commit
that referenced
this pull request
Dec 8, 2025
* chore(exasol): qualified select list with "LOCAL" * chore(exasol): implementing alias referencing using local keyword for select list * chore(exasol): refactored test and simplifying implementation * chore(exasol): refactored the test and added safe checking when reading alias.node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What motivated this PR?
Exasol requires the
LOCALqualifier when referencing column aliases inGROUP BY,HAVING,WHERE, and theSELECTlist.The previous implementation only handled
GROUP BY,WHERE, andHAVING, but did not applyLOCALto alias references inside the SELECT list.This PR adds the missing behavior in accordance with Exasol’s documented rules:
https://docs.exasol.com/db/latest/sql/select.htm
What was incorrect in the existing logic?
Given a query such as:
The transpiler did not rewrite
current_yeartoLOCAL.current_yearinside the SELECT list.Since Exasol requires
LOCAL.aliasfor any alias referenced within the same SELECT clause, the generated SQL was invalid.How does this PR resolve the issue?
The PR extends the existing alias-handling transformation so that:
LOCAL.alias, consistent with Exasol requirements.This makes alias resolution behavior complete and aligned across
SELECT,GROUP BY,HAVING, andWHERE.Documentation & Semantic Notes
Exasol’s rules for alias qualification are documented here:
https://docs.exasol.com/db/latest/sql/select.htm
The semantics are fully preserved — the PR does not change query meaning.
It only adds the required
LOCALprefix in the SELECT list so that transpiled queries execute correctly on Exasol.