Repository navigation
fix(profiler): emit valid Databricks SQL for unquoted identifiers - #31347
Conversation
The Databricks compiler override that re-quotes STRUCT children assumed the compiler always emits backtick-quoted identifiers. Databricks only quotes an identifier when it needs it, so an all-lowercase schema.table.column arrives unquoted, the struct heuristic fires on it and rejoins the parts without the outer backticks, producing an unbalanced reference and a PARSE_SYNTAX_ERROR on every column metric. ModuloFn had no Databricks compiler and fell through to the generic `%%` escape, which only pyformat/format paramstyle drivers unescape. The Databricks driver uses named paramstyle, so Spark received a literal `%%`.
The progress and metrics mixins logged only str(exc), so an HTTP failure reduced to "400 Client Error: Bad Request for url: ..." with the server's reason discarded. Report a truncated response body alongside it.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ ApprovedFixes Databricks profiler SQL generation for unquoted identifiers and ModuloFn compilation, and improves server response logging on progress endpoint failures. No issues found. OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
✅ Playwright Results — workflow succeededValidated commit ✅ 110 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 51m 38s ⏱️ Max setup 3m 2s · max shard execution 13m 21s · max shard-job elapsed before upload 19m 55s · reporting 3s 🌐 214.34 requests/attempt · 1.79 app boots/UI scenario · 0.00% common-shard skew Optimization targets still in progress:
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
| RESPONSE_BODY_LOG_LIMIT = 500 | ||
|
|
||
|
|
||
| def error_detail(exc: Exception) -> str: |
There was a problem hiding this comment.
Do you know why we need to truncate it?
🚦 Removed from the merge queue —
|
…1347) (#31373) * fix(profiler): emit valid Databricks SQL for unquoted identifiers The Databricks compiler override that re-quotes STRUCT children assumed the compiler always emits backtick-quoted identifiers. Databricks only quotes an identifier when it needs it, so an all-lowercase schema.table.column arrives unquoted, the struct heuristic fires on it and rejoins the parts without the outer backticks, producing an unbalanced reference and a PARSE_SYNTAX_ERROR on every column metric. ModuloFn had no Databricks compiler and fell through to the generic `%%` escape, which only pyformat/format paramstyle drivers unescape. The Databricks driver uses named paramstyle, so Spark received a literal `%%`. * fix(ingestion): log the server response on progress endpoint failures The progress and metrics mixins logged only str(exc), so an HTTP failure reduced to "400 Client Error: Bad Request for url: ..." with the server's reason discarded. Report a truncated response body alongside it. (cherry picked from commit 6814fc2)
…1347) (#31374) * fix(profiler): emit valid Databricks SQL for unquoted identifiers The Databricks compiler override that re-quotes STRUCT children assumed the compiler always emits backtick-quoted identifiers. Databricks only quotes an identifier when it needs it, so an all-lowercase schema.table.column arrives unquoted, the struct heuristic fires on it and rejoins the parts without the outer backticks, producing an unbalanced reference and a PARSE_SYNTAX_ERROR on every column metric. ModuloFn had no Databricks compiler and fell through to the generic `%%` escape, which only pyformat/format paramstyle drivers unescape. The Databricks driver uses named paramstyle, so Spark received a literal `%%`. * fix(ingestion): log the server response on progress endpoint failures The progress and metrics mixins logged only str(exc), so an HTTP failure reduced to "400 Client Error: Bad Request for url: ..." with the server's reason discarded. Report a truncated response body alongside it. (cherry picked from commit 6814fc2)
…en-metadata#31347) * fix(profiler): emit valid Databricks SQL for unquoted identifiers The Databricks compiler override that re-quotes STRUCT children assumed the compiler always emits backtick-quoted identifiers. Databricks only quotes an identifier when it needs it, so an all-lowercase schema.table.column arrives unquoted, the struct heuristic fires on it and rejoins the parts without the outer backticks, producing an unbalanced reference and a PARSE_SYNTAX_ERROR on every column metric. ModuloFn had no Databricks compiler and fell through to the generic `%%` escape, which only pyformat/format paramstyle drivers unescape. The Databricks driver uses named paramstyle, so Spark received a literal `%%`. * fix(ingestion): log the server response on progress endpoint failures The progress and metrics mixins logged only str(exc), so an HTTP failure reduced to "400 Client Error: Bad Request for url: ..." with the server's reason discarded. Report a truncated response body alongside it.



Describe your changes:
Profiling a Databricks or Unity Catalog asset fails with
[PARSE_SYNTAX_ERROR] ... SQLSTATE: 42601on every column, because the generated SQL has unbalanced identifier quoting:DatabricksProfilerInterface.visit_columnis monkeypatched ontoDatabricksDialect.statement_compilerto re-quote STRUCT children (`db`.`sc`.`tbl`.`col.child`→…`col`.`child`). It assumed the compiler always emits backtick-quoted identifiers, butDatabricksIdentifierPreparerdeclareslegal_characters = ^[A-Z0-9_]+$, so SQLAlchemy quotes an identifier only when it is mixed-case, reserved, or contains illegal characters. An all-lowercaseschema.table.columntherefore arrives unquoted, still satisfies thedot_count > 1guard, and gets rejoined with`.`separators while the branch that would supply the leading backtick is skipped — so the outer backticks are lost. Every column-level metric becomes unparseable on any table whose schema, table and column names are all lowercase, which is the common case.The fix returns early when the compiled reference carries no backticks: there is no struct path to repair, so there is nothing to rewrite.
A second defect sits behind the first on the same code path.
ModuloFnhas no Databricks compiler and falls through to the genericf"{value} %% {base}". The%%is an escape forformat/pyformatparamstyle drivers;databricks-sql-connectorusesnamedparamstyle, so nothing unescapes it and Spark receives a literal%%. RegisteringDialects.Databrickson the existingMOD(...)group fixes it — without this the backtick fix alone still leaves profiling broken.Separately, the progress and operation-metrics mixins logged only
str(exc), which reduces a server rejection to400 Client Error: Bad Request for url: ...and discards the server's reason. They now report a truncated response body alongside it, so this class of failure is diagnosable from agent logs.Blast radius
This needs no opt-in. It reproduces on the stock profiler defaults (
randomizedSample: false,profileSampleConfig: DYNAMICwithsmartSampling), because that configuration still routes throughget_sample_queryand emits the_rndsample CTE that forces three-part column references.Verified against a live Databricks workspace
A/B on OM
2.0.0-rc1against a real Unity Catalog service — same pipeline, same data, only these files differing:Unpatched, both defects in one line:
Patched: 6/6 tables and 30/30 columns carry profiles, with real values.
New
test_databricks_profiler_sql.pycompiles against the realDatabricksDialectinstead of a mocked compiler. The pre-existingtest_visit_column.pyonly ever fed pre-quoted strings to a mockedvisit_column, which is why the real preparer's behaviour was never observed; it gains the unquoted case.Backports
Needs cherry-picking to
1.13and2.0after merge. Both branches carry these files unchanged frommain, so the picks apply clean.Type of change:
Manual test steps:
[PARSE_SYNTAX_ERROR] Syntax error at or near '<table>'. SQLSTATE: 42601, and only table-levelrowCountsucceeds. After: column metrics compute normally.