Repository navigation
fix: escape relation string literals in metadata queries (#1747) - #1758
MsMansiDhruv wants to merge 1 commit into
Conversation
|
@MsMansiDhruv can you look at the failing test for code quality. Thx ! |
b93993e to
5257e50
Compare
Hey @sd-db , I applied ruff format across the new unit test files to resolve the failing test. Unit test cases run locally. Will await on the test results if something fails. |
5257e50 to
231dfd5
Compare
|
Hi @sd-db, Could you please trigger a quick re-run on the |
Resolves #1747
Description
Several metadata macros interpolate relation components (catalog, schema, table) directly into SQL string literals (
= '{{ relation.<part>|lower }}') without escaping special characters. In Databricks Unity Catalog, relation identifiers can contain quotes and backslashes when backtick-quoted (e.g.`orders'eu`or`cat\log`). For such relations, the unescaped string literals produce invalid SQL syntax and cause query execution errors when queryinginformation_schemaviews or running metadata-dependent operations (such as table tags, row filters, column masks, constraints, and catalog generation).This PR:
escape_relation_literal(value)inmacros/relations/escape.sqlthat escapes backslashes first (\ -> \\) and then single quotes (' -> \'), matching the comment escaping convention used inmacros/relations/components/comment.sql.macros/relations/tags.sql:fetch_tags_sqlmacros/relations/components/row_filter.sql:fetch_row_filters_sqlmacros/relations/components/column_mask.sql:fetch_column_masks_sqlmacros/relations/components/column_tags.sql:fetch_column_tags_sqlmacros/relations/components/constraints.sql:fetch_non_null_constraint_columns_sql,fetch_primary_key_constraints_sql,fetch_foreign_key_constraints_sqlmacros/adapters/catalog.sql:databricks__get_catalog_schemas_where_clause_sql,databricks__get_catalog_relations_where_clause_sqlmacros/adapters/metadata.sql:get_relation_last_modified_sql,get_view_description_sql,get_uc_tables_sqlescape_relation_literalas well as tests covering relation names with single quotes (') and backslashes (\) for each modified macro test suite.CHANGELOG.md.Checklist
CHANGELOG.mdand added information about my change to the "dbt-databricks next" section.