Repository navigation
fix(e6): transpile the query inside a Databricks EXPLAIN - #328
Merged
Merged
Conversation
EXPLAIN is a tokenizer COMMAND, so everything after it became one string literal in an opaque exp.Command and the query was never transpiled; the planner then failed on Databricks-only syntax (e.g. the reserved alias AS time left unquoted). The Databricks parser now parses that string into the statement and returns a Databricks-only Explain (a Command that also holds the statement), so the query is part of the AST and AST passes reach it. E6 writes it as EXPLAIN <query>, dropping the Databricks-only EXTENDED/CODEGEN/COST/FORMATTED style; every other dialect still writes it back verbatim like any Command.
tkaunlaky-e6
force-pushed
the
fix/e6-explain-transpile-inner
branch
from
October 13, 2026 12:07
1116932 to
c57e9eb
Compare
gauravdawar-e6
approved these changes
Oct 13, 2026
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.
Problem
A Databricks
EXPLAIN <query>reaches the transpiler but is returned untranspiled.EXPLAINis a tokenizerCOMMAND, so the tokenizer swallows everything after it into one string:The query never becomes AST, so no transform reaches it and it is written back verbatim. The planner then fails on Databricks-only syntax that the plain query would have had transpiled.
Example from the planner logs (
Q403866-16-20261013.035120.090):EXPLAIN SELECT date_trunc('day', to_timestamp(date, 'MM/dd/yyyy')) AS time, SUM(costInBillingCurrency) AS cost FROM pu_orbis_platform_prod_catalog._maap.costs GROUP BY 1 ORDER BY 1(unchanged)Encountered "TIME" at line 1, column 71, thenParsing Failed. The reserved aliastimeis never quoted.The same query without
EXPLAINtranspiles and runs. Everymainbuild back to Sep 8 returns the EXPLAIN form unchanged, so this is not a regression.Change
databricks.py: the Databricks parser parses the string afterEXPLAINinto the statement (dropping the Databricks-onlyEXTENDED|CODEGEN|COST|FORMATTEDstyle) and returns a Databricks-onlyExplain.Explainis aCommandthat also holds the parsed statement:EXPLAINstays a plainCommand.e6.py:TRANSFORMS[databricks.Explain]writesEXPLAIN <transpiled statement>.Explainkeeps theCommandkey and raw text, and it is defined in the Databricks module, so no other dialect parses into it.After:
EXPLAIN SELECT DATE_TRUNC('DAY', TO_TIMESTAMP("date", 'MM/dd/yyyy')) "time", SUM(costInBillingCurrency) AS cost FROM ... GROUP BY 1 ORDER BY 1Verification
test_databricks_explainintests/dialects/test_e6.py. It fails onmainand passes here.EXPLAINandSHOW TABLES: only the e6EXPLAIN <query>rows change.from_dialect, pretty on and off: the EXPLAIN output equalsEXPLAIN+ the plain query's output in 72 of 72 cases./convert-query, java and native: 30 of 30 cases where the EXPLAIN output equalsEXPLAIN+ the plain output ("time"quoted,GET_JSON_OBJECT,ROLLUP,DATE_DIFF, CTEs). Unchanged: SnowflakeEXPLAIN, a column namedexplain, and theSKIP_E6_TRANSPILATIONpath.make checkpasses (ruff, ruff-format, mypy, 1015 tests).EXPLAIN SELECT ..., but the local engine only acceptsEXPLAIN PLAN FOR.