Skip to content

Commit 2705a34

Browse files
fix: quote catalog names in SHOW SCHEMAS commands (#1325) (#1332)
resolves #1325 ### Description when a unity catalog name contains hyphens or other special characters (e.g., `data_engineering-uc-dev`), `SHOW SCHEMAS` commands fail with `INVALID_IDENTIFIER` because the catalog name is not quoted. **fix:** added backtick quoting around `{{ database }}` in the `list_schemas_sql` and `check_schema_exists_sql` macros in `metadata.sql`. **before:** ```sql SHOW SCHEMAS IN data_engineering-uc-dev ``` **after:** ```sql SHOW SCHEMAS IN `data_engineering-uc-dev` ``` added 4 unit tests covering normal, hyphenated, and null database names for both macros. ### Checklist - [x] I have run this code in development and it appears to resolve the stated issue - [x] This PR includes tests, or tests are not required/relevant for this PR - [x] I have updated the `CHANGELOG.md` and added information about my change to the "dbt-databricks next" section. --------- Signed-off-by: aarushisingh04 <aarushi07.singh@gmail.com> Co-authored-by: Shubham Dhal <shubham.dhal@databricks.com>
1 parent 33cca1d commit 2705a34

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
gated behind the `use_concurrent_microbatch` behavior flag (default: `false`).
77
Opt in via `flags: {use_concurrent_microbatch: true}` in `dbt_project.yml`
88
([#914](https://github.com/databricks/dbt-databricks/issues/914))
9+
10+
### Fixes
11+
12+
- Fix catalog names with special characters (e.g., hyphens) not being quoted in `SHOW SCHEMAS` commands, causing `INVALID_IDENTIFIER` errors ([#1325](https://github.com/databricks/dbt-databricks/issues/1325))
913

1014
## dbt-databricks 1.11.5 (Feb 19, 2026)
1115

dbt/include/databricks/macros/adapters/metadata.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SHOW TABLES IN {{ relation.render() }}
3333

3434
{% macro list_schemas_sql(database) %}
3535
{% if database %}
36-
SHOW SCHEMAS IN {{ database }}
36+
SHOW SCHEMAS IN {{ adapter.quote(database) }}
3737
{% else %}
3838
SHOW SCHEMAS
3939
{% endif %}
@@ -44,7 +44,7 @@ SHOW TABLES IN {{ relation.render() }}
4444
{% endmacro %}
4545

4646
{% macro check_schema_exists_sql(database, schema) %}
47-
SHOW SCHEMAS IN {{ database }} LIKE '{{ schema }}'
47+
SHOW SCHEMAS IN {{ adapter.quote(database) }} LIKE '{{ schema }}'
4848
{% endmacro %}
4949

5050
{% macro show_views(relation) %}

tests/unit/macros/adapters/test_metadata_macros.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ def test_get_uc_tables_sql_without_identifier(self, template_bundle, mock_schema
166166
""" # noqa
167167
self.assert_sql_equal(result, expected_sql)
168168

169+
def test_list_schemas_sql_with_database(self, template_bundle):
170+
result = self.run_macro(template_bundle.template, "list_schemas_sql", "my_catalog")
171+
172+
expected_sql = "SHOW SCHEMAS IN `my_catalog`"
173+
self.assert_sql_equal(result, expected_sql)
174+
175+
def test_list_schemas_sql_with_hyphenated_database(self, template_bundle):
176+
result = self.run_macro(
177+
template_bundle.template, "list_schemas_sql", "data_engineering-uc-dev"
178+
)
179+
180+
expected_sql = "SHOW SCHEMAS IN `data_engineering-uc-dev`"
181+
self.assert_sql_equal(result, expected_sql)
182+
183+
def test_list_schemas_sql_without_database(self, template_bundle):
184+
result = self.run_macro(template_bundle.template, "list_schemas_sql", None)
185+
186+
expected_sql = "SHOW SCHEMAS"
187+
self.assert_sql_equal(result, expected_sql)
188+
189+
def test_check_schema_exists_sql_with_hyphenated_database(self, template_bundle):
190+
result = self.run_macro(
191+
template_bundle.template,
192+
"check_schema_exists_sql",
193+
"data_engineering-uc-dev",
194+
"my_schema",
195+
)
196+
197+
expected_sql = "SHOW SCHEMAS IN `data_engineering-uc-dev` LIKE 'my_schema'"
198+
self.assert_sql_equal(result, expected_sql)
199+
169200
def test_case_sensitivity(self, template_bundle):
170201
relation = Mock()
171202
relation.database = "TEST_DB"

0 commit comments

Comments
 (0)