Skip to content

fix(e6): flatten FROM_JSON schema whitespace so the type descriptor stays backslash-free - #320

Merged
tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-from-json-schema-newlines
Sep 22, 2026
Merged

tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-from-json-schema-newlines

Conversation

@tkaunlaky-e6

Copy link
Copy Markdown

Problem

Freshworks Power BI queries that SELECT … FROM <view> where the view uses EXPLODE(FROM_JSON(col, 'array<struct<…>>')) fail at parse time with:

Lexical error at line 1, column 14. Encountered: "\" (92), after : ""

(Confirmed in the planner logs — the query is transpiled databricks → E6, then tryParseWithE6 dies on the backslash.)

Root cause

FROM_JSON's 2nd argument is a type descriptor, not a normal string value. The engine parses it at SQL-parse time via DataTypeParser.parseJsonSchemaString(), which spins up a JsonSchema() sub-parser over the raw string body (so it resets to line 1). That lexer skips whitespace but has no rule for a backslash.

The views write the schema multi-line for readability, so the source string literal contains real newlines. e6 escapes those newlines as \n (backslash-n) on output, and the sub-parser dies on the \ — at column 14, which is exactly the char after array<struct< (13 chars).

Fix

Whitespace is insignificant inside a type descriptor, so when rendering a FROM_JSON string arg (anonymous_sql), collapse it with " ".join(val.split()). That drops the newlines that would otherwise be backslash-escaped, so array<struct<\n id:string… becomes array<struct< id:string… — backslash-free, and the sub-parser skips the spaces and derives the identical type. Already single-line schemas are unchanged (idempotent), so nothing else in the workload shifts.

Tests

Adds test_from_json_schema_newlines: a multi-line schema transpiles to a clean single-line, backslash-free descriptor; a single-line schema is left untouched. The existing test_json_extract (value: → `value` rewrite) still passes.

make check is green — style (ruff, ruff-format, mypy), test (1010) and test-rs (1010).

…tays backslash-free

FROM_JSON's 2nd arg is a type descriptor that the e6 engine re-parses via a JsonSchema()
sub-parser over the raw string body. That lexer skips whitespace but has no rule for a
backslash, so a view whose schema is written multi-line -- the real newlines are emitted
as "\n" (backslash-n) -- fails at parse time with "Lexical error ... Encountered \ (92)"
at the column right after "array<struct<".

Whitespace is insignificant in a type descriptor, so collapse it (" ".join(val.split()))
when rendering a FROM_JSON string arg, dropping the newlines that would otherwise be
backslash-escaped. Already single-line schemas are unchanged (idempotent).

Adds test_from_json_schema_newlines.
@tkaunlaky-e6
tkaunlaky-e6 merged commit 6951ef3 into main Sep 22, 2026
6 checks passed
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