Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sqlmesh/dbt/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ def canonical_name(self, context: DbtContext) -> str:
f"'source' macro failed for '{self.config_name}' with exception '{e}'."
)

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=False,
identifier=needs_identifier_quoting,
)
if relation.database == context.target.database:
relation = relation.include(database=False)
Expand Down
26 changes: 26 additions & 0 deletions tests/dbt/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,32 @@ def test_quoting():
assert str(BaseRelation.create(**source.relation_info)) == 'foo."bar"'


@pytest.mark.parametrize(
("identifier", "expected"),
[
("FILENAME.CSV", 'raw."FILENAME.CSV"'),
("FILE NAME", 'raw."FILE NAME"'),
],
)
def test_source_config_canonical_name_quotes_identifier_with_dot_or_space(
identifier: str, expected: str
):
context = DbtContext()
context.project_name = "test"
context.target = DuckDbConfig(name="target", schema="raw")

source = SourceConfig(
name="my_table",
source_name="my_source",
schema="raw",
identifier=identifier,
quoting={"identifier": False},
)
context.sources = {source.config_name: source}

assert source.canonical_name(context) == expected


def _test_warehouse_config(
config_yaml: str, target_class: t.Type[TargetConfig], *params_path: str
) -> TargetConfig:
Expand Down