SQLMesh version: 0.231.1
Adapter: dbt-snowflake 1.11.3
Description
When a dbt source has a table identifier that contains a dot or space (common with Airbyte-ingested CSV files stored as Snowflake tables, e.g. "my_csv.csv"), loading the project fails
with:
Error: 1 validation error for SqlModel
depends_on
Value error, too many values to unpack (expected 3)
Root cause
SourceConfig.canonical_name() in sqlmesh/dbt/source.py unconditionally strips all identifier quoting before calling relation.render(). This produces a string like
database.my_schema.my_csv_file.CSV, which sqlglot cannot parse as a table expression. The fallback in exp.to_table calls split_num_words(sql_path, ".", 3), which raises ValueError: too many
values to unpack (expected 3) because the string splits into 4 parts.
Minimal reproduction
Source YAML:
sources:
- name: my_source
database: RAW_DEV
tables:
- name: my_table
identifier: "FILENAME.CSV"
quoting:
identifier: true
Fix
(will put a PR in soon)
In sqlmesh/dbt/source.py, preserve quoting when the identifier contains dots or spaces:
needs_identifier_quoting = bool(
self.table_name
and ("." in self.table_name or " " in self.table_name)
)
relation = relation.quote(
database=False,
schema=False,
identifier=needs_identifier_quoting,
)
SQLMesh version: 0.231.1
Adapter: dbt-snowflake 1.11.3
Description
When a dbt source has a table identifier that contains a dot or space (common with Airbyte-ingested CSV files stored as Snowflake tables, e.g. "my_csv.csv"), loading the project fails
with:
Root cause
SourceConfig.canonical_name() in sqlmesh/dbt/source.py unconditionally strips all identifier quoting before calling relation.render(). This produces a string like
database.my_schema.my_csv_file.CSV, which sqlglot cannot parse as a table expression. The fallback in exp.to_table calls split_num_words(sql_path, ".", 3), which raises ValueError: too many
values to unpack (expected 3) because the string splits into 4 parts.
Minimal reproduction
Fix
(will put a PR in soon)
In sqlmesh/dbt/source.py, preserve quoting when the identifier contains dots or spaces:
needs_identifier_quoting = bool(
self.table_name
and ("." in self.table_name or " " in self.table_name)
)
relation = relation.quote(
database=False,
schema=False,
identifier=needs_identifier_quoting,
)