Skip to content

Allow dashes in bundle init catalog/schema names and escape them in generated SQL - #6293

Merged
pavloKozlov merged 1 commit into
mainfrom
uc-catalog-dash
Aug 18, 2026
Merged

Allow dashes in bundle init catalog/schema names and escape them in generated SQL#6293
pavloKozlov merged 1 commit into
mainfrom
uc-catalog-dash

Conversation

@pavloKozlov

Copy link
Copy Markdown
Contributor

Unity Catalog names may contain dashes, but databricks bundle init rejected
them (pattern ^\w*$). This PR:

  • Loosens the default_catalog prompt to ^(\w[\w-]*)?$ (dashes allowed, blank still valid, leading-dash rejected) and shared_schema to ^\w[\w-]*$ across the built-in templates.
  • Escapes the catalog/schema identifiers with IDENTIFIER() in the SQL generated by the default-sql, default-python, and default-scala templates, so dashed names work at runtime.

Why

UC allows any character except ., space, /, and control chars, so my-catalog is valid — but init blocked it, and raw USE CATALOG my-catalog would fail at runtime. IDENTIFIER() is the safe form already used for the schema in default-sql.

Tests

New acceptance test default-sql-catalog-dash inits with dashed catalog/schema names, diffs the generated databricks.yml, and asserts leading-dash names are rejected at init. Existing template goldens regenerated; passes on both terraform and direct engines.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: d764e7f

Run: 32114326796

Env 🟨​KNOWN 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
🟨​ aws linux 3 1 4 286 1151 6:23
🟨​ aws windows 3 1 4 288 1149 7:15
🟨​ azure linux 3 1 4 285 1151 6:43
🟨​ azure windows 3 1 4 287 1149 7:24
💚​ gcp linux 1 5 286 1151 5:43
💚​ gcp windows 1 5 288 1149 5:48
8 interesting tests: 4 SKIP, 3 KNOWN, 1 RECOVERED
Test Name aws linux aws windows azure linux azure windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestFetchRepositoryInfoAPI_FromRepo 🟨​K 🟨​K 🟨​K 🟨​K 🙈​S 🙈​S
🟨​ TestFetchRepositoryInfoAPI_FromRepo/root 🟨​K 🟨​K 🟨​K 🟨​K
🟨​ TestFetchRepositoryInfoAPI_FromRepo/subdir 🟨​K 🟨​K 🟨​K 🟨​K
Top 6 slowest tests (at least 2 minutes):
duration env testname
5:50 aws windows TestAccept
5:39 gcp windows TestAccept
5:39 azure windows TestAccept
3:53 gcp linux TestAccept
3:52 azure linux TestAccept
3:47 aws linux TestAccept

"spark.sql(f\"USE CATALOG {catalog}\")\n",
"spark.sql(f\"USE SCHEMA {schema}\")"
"spark.sql(\"USE CATALOG IDENTIFIER(:catalog)\", args={\"catalog\": catalog})\n",
"spark.sql(\"USE SCHEMA IDENTIFIER(:schema)\", args={\"schema\": schema})"

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.

I like the idea of supporting -! But this is a very unfortunate change, it makes it seem more complex for first-time users and agents who might copy this pattern.

Could you look at alternatives

  • Perhaps backticks around the catalog/schema name also fix this?
  • Perhaps we should take the complexity to us as maintainers and only conditionally as needed, for dashes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank for your review.
I replaced IDENTIFIER with backticks as you suggested.
As of adding backticks conditionally I think it would add complexity to the code and for end users might cause issues when catalog is a ${var.catalog} variable and later they can point it to a dashed name. With applying backticks for all cases we mitigate this scenario. Let me know what you think.

Unity Catalog names may contain dashes, but `databricks bundle init` rejected
them (pattern `^\w*$`). Loosen the `default_catalog` pattern to `^(\w[\w-]*)?$`
(dashes allowed, blank still valid, leading dash rejected) and the
`shared_schema` pattern to `^\w[\w-]*$` across the built-in templates.

Backtick-quote the catalog and schema identifiers in the SQL generated by the
default-sql, default-python, and default-scala templates so dashed names work at
runtime. The names are already validated to word characters and dashes, so
backticks are sufficient and keep the generated code readable.

Tests: new acceptance test default-sql-catalog-dash inits with dashed
catalog/schema names, diffs the generated databricks.yml, and asserts
leading-dash names are rejected at init.

Co-authored-by: Isaac
@@ -0,0 +1,5 @@
[[Repls]]
# On Windows $TESTDIR expands with backslashes; normalize them so the diff.py

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.

best practice is to find the place where slashes are output and evaluate if we can make it forward slash on all platforms

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed it in a follow-up PR #6310.

@pavloKozlov
pavloKozlov added this pull request to the merge queue Aug 18, 2026
Merged via the queue into main with commit 319dfe1 Aug 18, 2026
30 checks passed
@pavloKozlov
pavloKozlov deleted the uc-catalog-dash branch August 18, 2026 13:58
pavloKozlov added a commit that referenced this pull request Aug 18, 2026
Normalize the TESTDIR env var with filepath.ToSlash so paths built from it
(e.g. the diff.py invocation echoed in trace output) are stable across OSes.
Previously TESTDIR carried Windows backslashes, so a test echoing it needed a
per-test `\\`->`/` replacement in test.toml.

Remove that now-redundant replacement from default-sql-catalog-dash, whose only
purpose was normalizing the TESTDIR path. Other backslash replacements in the
suite address paths emitted by the CLI itself and stay.

Follow-up to review feedback on #6293.

Co-authored-by: Isaac
bjornkpu pushed a commit to bjornkpu/databricks-cli that referenced this pull request Aug 19, 2026
)

## Changes

Normalize the `TESTDIR` env var in the acceptance harness with
`filepath.ToSlash`, so paths built from `$TESTDIR` (e.g. the `diff.py`
invocation echoed in `trace` output) use forward slashes on every OS.

The other backslash replacements across the suite address paths emitted
by the CLI itself (bundle roots, sync paths, artifact globs) and are
left in place.

## Why

Follow-up to review feedback from @denik on databricks#6293: rather than papering
over the Windows backslashes with a per-test replacement, fix it at the
source where the path is produced. This matches the repo rule "Always
output file paths with forward slashes, even on Windows. Use
`filepath.ToSlash`."

The `[TESTROOT]` replacement already registers both slash forms on
Windows (`SetPathNoEval`), so the forward-slash `TESTDIR` prefix is
still collapsed to `[TESTROOT]` — no golden changes.
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.

4 participants