Metadata queries break on catalog, schema or table names containing a quote or backslash
メンテナーはふだん 6 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
Start with the listed macros in relations/tags.sql, relations/components/, adapters/catalog.sql, adapters/metadata.sql, and materializations/clone/strategies.sql; compare their string literal handling with relations/components/comment.sql. Also inspect show_table_extended_sql and check_schema_exists_sql for the related LIKE pattern issue. Add unit cases for names containing both a quote and a backslash, and confirm the generated SQL escapes both correctly across the affected macros.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Several metadata macros paste relation names straight into SQL string literals without escaping them. Unity Catalog allows a ' or \ in a catalog, schema or table name when the name is backtick-quoted, for example `orders'eu`. For such a relation, the generated query is invalid:
... WHERE table_catalog = 'main' AND table_schema = 'prod' AND table_name = 'orders'eu'
The query fails to parse, so the materialization or command that issued it fails before running any DDL. Identifier quoting in these macros is fine; only the string literals are affected.
Affected macros (all build = '{{ relation.<part>|lower }}' predicates):
relations/tags.sql:fetch_tags_sqlrelations/components/row_filter.sql:fetch_row_filters_sqlrelations/components/column_mask.sql:fetch_column_masks_sqlrelations/components/column_tags.sql:fetch_column_tags_sqlrelations/components/constraints.sql:fetch_non_null_constraint_columns_sql,fetch_primary_key_constraints_sql,fetch_foreign_key_constraints_sqladapters/catalog.sql:databricks__get_catalog_schemas_where_clause_sql,databricks__get_catalog_relations_where_clause_sqladapters/metadata.sql:get_relation_last_modified_sql,get_view_description_sql,get_uc_tables_sqlmaterializations/clone/strategies.sql:clone_source_policies_sql, added in #1745, which runs on everydbt cloneof a Unity Catalog table.
Related, but a different quoting problem: show_table_extended_sql and check_schema_exists_sql build LIKE '<name>' patterns from relation names. Those need both literal escaping and LIKE-pattern handling.
Steps To Reproduce
CREATE SCHEMA main.quote_probe;
CREATE TABLE main.quote_probe.`orders'eu` (id INT);
-- What fetch_row_filters_sql / clone_source_policies_sql generate today: fails to parse
SELECT 1 FROM main.information_schema.row_filters
WHERE table_catalog = 'main' AND table_schema = 'quote_probe' AND table_name = 'orders'eu';
-- Escaped: runs, and finds the filter once one is set
SELECT 1 FROM main.information_schema.row_filters
WHERE table_catalog = 'main' AND table_schema = 'quote_probe' AND table_name = 'orders\'eu';
In dbt, a model with alias: "orders'eu" hits this as soon as one of the macros above runs for it. Examples:
dbt cloneonce #1745 lands.- Tag or constraint diffs on a later
dbt run. dbt docs generate, which goes through the catalog macros.
Expected behavior
Every relation-name string literal in generated SQL is escaped, \ first and then ', the way relations/components/comment.sql already escapes comments: | replace("\\", "\\\\") | replace("'", "\\'"). A shared helper macro would keep the call sites consistent. Each fixed *_sql macro gets a unit case with a name containing ' and \.
System information
Reproduced on a Unity Catalog SQL warehouse against the 1.13.latest branch. The pattern is the same on main.
Additional context
Found while reviewing #1745. We agreed to fix all call sites together on the next .latest branch rather than in that PR.
- 主要言語
- Python
- スター
- 391
- フォーク
- 231
- 平均マージ
- 9日 7時間
- マージ済み PR(30日)
- 29
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
databricks/dbt-databricks のほかの issue
-
persist_docs.columns triggers a full-plan probe query on views even when the model has no column docs対応中かも @DelorneN007 が 59 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
databricks/dbt-databricks#1680 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 半日 初心者へのやさしさ 68/100
databricks/dbt-databricks#1003 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
Emit COMMENT and DEFAULT for function arguments and descriptions in CREATE FUNCTION対応中かも @alvinism が 7 日前に担当しました。 オープンenhancement
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
databricks/dbt-databricks#1764 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 46/100
databricks/dbt-databricks#1762 ·
メンテナーはふだん 6 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
databricks/dbt-databricks#1761 ·
メンテナーはふだん 6 日以内に返信
databricks/dbt-databricks の issue をすべて見る
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
aws-samples/sample-per-model-bedrock#857 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
521xueweihan/HelloGitHub#4328 ·
-
documentation maintainer-managed
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
awslabs/visual-asset-management-system#1418 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信