Skip to content

fix(profiler): emit valid Databricks SQL for unquoted identifiers - #31347

Merged
IceS2 merged 2 commits into
mainfrom
fix/databricks-profiler-sql-quoting
Aug 12, 2026
Merged

IceS2 merged 2 commits into
mainfrom
fix/databricks-profiler-sql-quoting

Conversation

@IceS2

@IceS2 IceS2 commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Profiling a Databricks or Unity Catalog asset fails with [PARSE_SYNTAX_ERROR] ... SQLSTATE: 42601 on every column, because the generated SQL has unbalanced identifier quoting:

-- generated
SELECT my_schema`.`my_table`.`my_col FROM my_schema.my_table
-- expected
SELECT my_schema.my_table.my_col FROM my_schema.my_table

DatabricksProfilerInterface.visit_column is monkeypatched onto DatabricksDialect.statement_compiler to re-quote STRUCT children (`db`.`sc`.`tbl`.`col.child` → …`col`.`child`). It assumed the compiler always emits backtick-quoted identifiers, but DatabricksIdentifierPreparer declares legal_characters = ^[A-Z0-9_]+$, so SQLAlchemy quotes an identifier only when it is mixed-case, reserved, or contains illegal characters. An all-lowercase schema.table.column therefore arrives unquoted, still satisfies the dot_count > 1 guard, 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. ModuloFn has no Databricks compiler and falls through to the generic f"{value} %% {base}". The %% is an escape for format/pyformat paramstyle drivers; databricks-sql-connector uses named paramstyle, so nothing unescapes it and Spark receives a literal %%. Registering Dialects.Databricks on the existing MOD(...) 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 to 400 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: DYNAMIC with smartSampling), because that configuration still routes through get_sample_query and emits the _rnd sample CTE that forces three-part column references.

Verified against a live Databricks workspace

A/B on OM 2.0.0-rc1 against a real Unity Catalog service — same pipeline, same data, only these files differing:

Profiler records errors run state
unpatched 12 90 failed
patched 102 0 success

Unpatched, both defects in one line:

[PARSE_SYNTAX_ERROR] Syntax error at or near 'customers'. SQLSTATE: 42601 (line 3, pos 16)
(SELECT sales`.`customers`.`ssn AS ssn, ABS(RANDOM()) * 100 %% :`param_3` AS random
FROM sales.customers),

Patched: 6/6 tables and 30/30 columns carry profiles, with real values.

New test_databricks_profiler_sql.py compiles against the real DatabricksDialect instead of a mocked compiler. The pre-existing test_visit_column.py only ever fed pre-quoted strings to a mocked visit_column, which is why the real preparer's behaviour was never observed; it gains the unquoted case.

Backports

Needs cherry-picking to 1.13 and 2.0 after merge. Both branches carry these files unchanged from main, so the picks apply clean.

Type of change:

  • Bug fix

Manual test steps:

  1. Configure a Databricks or Unity Catalog service whose schema, table and column names are all lowercase.
  2. Run metadata ingestion, then a profiler pipeline on default settings.
  3. Before: every column metric fails with [PARSE_SYNTAX_ERROR] Syntax error at or near '<table>'. SQLSTATE: 42601, and only table-level rowCount succeeds. After: column metrics compute normally.

IceS2 added 2 commits August 11, 2026 17:00
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.
@IceS2
IceS2 requested a review from a team as a code owner August 11, 2026 15:06
Copilot AI lite review requested due to automatic review settings August 11, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Aug 11, 2026
@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Fixes Databricks profiler SQL generation for unquoted identifiers and ModuloFn compilation, and improves server response logging on progress endpoint failures. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 7cb06b80a390411db5a272f54111ffe745f12edb in Playwright run 31505218162, attempt 1.

✅ 110 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking 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:

  • Browser traffic was 214.34 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 1.79 per UI scenario (216 boots / 121 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 46 0 0 0 0 0
✅ Shard ingestion-01 33 0 0 0 0 0
✅ Shard ingestion-02 31 0 0 0 0 0

📦 Download artifacts

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you know why we need to truncate it?

@IceS2
IceS2 added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — checks_timed_out (2026-08-11T22:12:50Z)

No failing check on merge-queue commit 065bac8 — invalidated by an entry ahead in the queue, or a required check timed out.

@IceS2
IceS2 added this pull request to the merge queue Aug 11, 2026
Merged via the queue into main with commit 6814fc2 Aug 12, 2026
99 of 101 checks passed
@IceS2
IceS2 deleted the fix/databricks-profiler-sql-quoting branch August 12, 2026 01:29
IceS2 added a commit that referenced this pull request Aug 12, 2026
…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)
IceS2 added a commit that referenced this pull request Aug 12, 2026
…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)
k-anshul pushed a commit to k-anshul/OpenMetadata that referenced this pull request Aug 12, 2026
…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.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants