Skip to content

fix(e6): alias unaliased Databricks colon projections by final path segment - #287

Open
tkaunlaky-e6 wants to merge 1 commit into
e6data:mainfrom
tkaunlaky-e6:fix/e6-colon-implicit-alias
Open

fix(e6): alias unaliased Databricks colon projections by final path segment#287
tkaunlaky-e6 wants to merge 1 commit into
e6data:mainfrom
tkaunlaky-e6:fix/e6-colon-implicit-alias

Conversation

@tkaunlaky-e6

Copy link
Copy Markdown

Problem

A Databricks colon/variant projection written without an alias — e.g. SELECT deep_dives:metrics_per_level — is implicitly named by Databricks after its final path segment (metrics_per_level). E6 has no such naming rule, so when an outer query references that column by name it fails:

Column 'metrics_per_level' not found in any table

This is the "colon path stripped by transpiler" failure bucket.

Fix

For Databricks-sourced transpiles (from_dialect="databricks"), make the implicit name explicit: a bare colon/variant JSONExtract appearing as a top-level SELECT projection is wrapped in AS <final-segment>.

Scoped precisely by iterating the Select's own expressions, so these are left untouched:

  • colon access inside WHERE / GROUP BY / a function / CASE (not a top-level projection)
  • an already-aliased projection (… AS x)
  • a path ending in a subscript (col:arr[0] — no implicit key name)
  • Snowflake variant access (databricks-gated)

Example

Databricks: SELECT price FROM (SELECT box:price FROM orders) t
e6 (before): SELECT price FROM (SELECT box:price FROM orders) AS t -- inner col unnamed -> "not found"
e6 (after): SELECT price FROM (SELECT box:price AS price FROM orders) AS t -- resolves

Validation

  • Live E6 engine: the aliased form resolves the outer reference and returns rows; the unaliased form fails with Column not found. Edge cases confirmed on the engine — reserved-word segment (box:limitbox:"limit" AS "limit") works; a duplicate final segment (a:x, b:x) reports ambiguous, which is faithful (Databricks also names both columns x).
  • tests/dialects/test_e6.py: existing top-level colon projections now carry their implicit alias, plus a new subquery-reference regression test. Full suite: 59 passed / 900 subtests.

…egment
Databricks derives an implicit column name from the final segment of an
unaliased colon/variant access (deep_dives:metrics_per_level ->
metrics_per_level). E6 has no such rule, so an outer query that references
that column by name fails with "Column not found in any table".
For Databricks-sourced transpiles, make the implicit name explicit: a bare
colon/variant JSONExtract that is a top-level SELECT projection is wrapped in
"AS <final-segment>". Scoped to the SELECT list, so colon access inside
WHERE / GROUP BY / a function / CASE, an already-aliased projection, and a
path ending in a subscript are all left untouched. Snowflake variant access
is unaffected (databricks-gated).
Validated on the live E6 engine: the aliased form resolves the outer
reference and returns rows; the unaliased form fails with "Column not found".
Sign up for freeto 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.

1 participant

@tkaunlaky-e6