Skip to content

feat(exasol): transpile USE/OPEN SCHEMA and SHOW TABLES to system-table query#7538

Merged
georgesittas merged 4 commits intotobymao:mainfrom
mkcorneli:feat/exasol-use-show-tables
Apr 23, 2026
Merged

feat(exasol): transpile USE/OPEN SCHEMA and SHOW TABLES to system-table query#7538
georgesittas merged 4 commits intotobymao:mainfrom
mkcorneli:feat/exasol-use-show-tables

Conversation

@mkcorneli
Copy link
Copy Markdown
Contributor

Summary

Two related Exasol statement-transpilation features:

  1. USE <schema>OPEN SCHEMA <schema> — Exasol uses OPEN SCHEMA where other dialects use USE. Before this PR, parsing OPEN SCHEMA test raised a ParseError, and transpiling USE test from MySQL produced a literal USE test which Exasol rejects.
  2. SHOW TABLES [FROM <schema>] → SELECT on SYS.EXA_ALL_TABLES — Exasol has no native SHOW TABLES. Before this PR the base generator emitted an empty string, leaving callers with no query to run.

Before

>>> sqlglot.transpile("USE test", read="mysql", write="exasol")[0]
'USE test'                                 # Exasol rejects

>>> sqlglot.parse_one("OPEN SCHEMA test", dialect="exasol")
ParseError: Invalid expression / Unexpected token. Line 1, Col: 16.

>>> sqlglot.transpile("SHOW TABLES FROM test", read="mysql", write="exasol")[0]
''                                         # base generator marks SHOW unsupported

After

>>> sqlglot.transpile("USE test", read="mysql", write="exasol")[0]
'OPEN SCHEMA test'

>>> sqlglot.transpile("OPEN SCHEMA test", read="exasol", write="exasol")[0]
'OPEN SCHEMA test'

>>> sqlglot.transpile("SHOW TABLES FROM test", read="mysql", write="exasol")[0]
\"SELECT TABLE_NAME FROM SYS.EXA_ALL_TABLES WHERE TABLE_SCHEMA = 'TEST'\"

>>> sqlglot.transpile("SHOW TABLES", read="mysql", write="exasol")[0]
'SELECT TABLE_NAME FROM SYS.EXA_ALL_TABLES WHERE TABLE_SCHEMA = CURRENT_SCHEMA'

Implementation notes

  • `use_sql` rejects non-schema kinds. For `USE ROLE admin` or `USE WAREHOUSE wh` (Snowflake forms), the generator emits an unsupported warning and falls back to the base `USE` output — it does not silently rewrite them as `OPEN SCHEMA admin`, which would be semantically wrong.
  • `show_sql` falls through for other SHOW kinds. Only `SHOW TABLES` is rewritten; every other kind (SHOW DATABASES, SHOW ENGINES, etc.) falls through to the base `show_sql` which marks them unsupported as before — so there is no semantic regression for any kind we don't explicitly handle.
  • Schema literal is uppercased. Exasol stores identifiers in `EXA_ALL_TABLES` uppercased, so `SHOW TABLES FROM test` becomes `... WHERE TABLE_SCHEMA = 'TEST'` to match.
  • `OPEN SCHEMA` parsing. `OPEN` has no dedicated `TokenType`, so the parser override intercepts it via `_match_text_seq("OPEN", "SCHEMA")` in `_parse_statement` and falls through to the base parser for everything else.

Test plan

  • New `test_use_to_open_schema` covers basic form, quoted identifier, Exasol round-trip, and `USE ROLE admin` unsupported path
  • New `test_show_tables` covers `SHOW TABLES FROM schema` and `SHOW TABLES` (CURRENT_SCHEMA fallback)
  • Full `tests/dialects/` suite runs cleanly (no new failures vs. main)
  • `ruff check` + `ruff format --check` pass

…le query

Exasol uses `OPEN SCHEMA <name>` where other dialects use `USE <name>`, and
has no native `SHOW TABLES` statement — the equivalent is a SELECT on
`SYS.EXA_ALL_TABLES`. Previously both statements produced invalid Exasol
output (parse error or empty string).

Changes:

* Add `use_sql` in ExasolGenerator that emits `OPEN SCHEMA <this>` for the
  default `USE schema` form. For other kinds (e.g. `USE ROLE admin`,
  `USE WAREHOUSE wh`), emit an unsupported warning and fall back to the
  base `USE` generator rather than silently rewriting them as schema
  switches.
* Add parser support in ExasolParser for `OPEN SCHEMA <id>` so it round-
  trips as an `exp.Use` node.
* Add `show_sql` in ExasolGenerator that rewrites `SHOW TABLES [FROM db]`
  to `SELECT TABLE_NAME FROM SYS.EXA_ALL_TABLES WHERE TABLE_SCHEMA = ...`,
  using the provided schema (uppercased to match Exasol metadata) or
  `CURRENT_SCHEMA` when absent. Other SHOW kinds fall through to the base
  generator (which marks them unsupported).
Copy link
Copy Markdown
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

Thanks! Can you please rebase off of main and resolve conflicts?

Comment thread sqlglot/parsers/exasol.py Outdated
Comment thread sqlglot/parsers/exasol.py Outdated
@georgesittas georgesittas merged commit cd4cd99 into tobymao:main Apr 23, 2026
2 of 8 checks passed
georgesittas added a commit that referenced this pull request Apr 23, 2026
…le query (#7538)

* feat(exasol): transpile USE/OPEN SCHEMA and SHOW TABLES to system-table query

Exasol uses `OPEN SCHEMA <name>` where other dialects use `USE <name>`, and
has no native `SHOW TABLES` statement — the equivalent is a SELECT on
`SYS.EXA_ALL_TABLES`. Previously both statements produced invalid Exasol
output (parse error or empty string).

Changes:

* Add `use_sql` in ExasolGenerator that emits `OPEN SCHEMA <this>` for the
  default `USE schema` form. For other kinds (e.g. `USE ROLE admin`,
  `USE WAREHOUSE wh`), emit an unsupported warning and fall back to the
  base `USE` generator rather than silently rewriting them as schema
  switches.
* Add parser support in ExasolParser for `OPEN SCHEMA <id>` so it round-
  trips as an `exp.Use` node.
* Add `show_sql` in ExasolGenerator that rewrites `SHOW TABLES [FROM db]`
  to `SELECT TABLE_NAME FROM SYS.EXA_ALL_TABLES WHERE TABLE_SCHEMA = ...`,
  using the provided schema (uppercased to match Exasol metadata) or
  `CURRENT_SCHEMA` when absent. Other SHOW kinds fall through to the base
  generator (which marks them unsupported).

* Update sqlglot/parsers/exasol.py

* Update sqlglot/parsers/exasol.py

---------

Co-authored-by: Jo <46752250+georgesittas@users.noreply.github.com>
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