Skip to content

Commit dd73bb7

Browse files
authored
fix: add 'ducklake prefix if not present (#4941)
1 parent cccc5ea commit dd73bb7

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

sqlmesh/core/config/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ def to_sql(self, alias: str) -> str:
238238
options.append("READ_ONLY")
239239

240240
# DuckLake specific options
241+
path = self.path
241242
if self.type == "ducklake":
243+
if not path.startswith("ducklake:"):
244+
path = f"ducklake:{path}"
242245
if self.data_path is not None:
243246
options.append(f"DATA_PATH '{self.data_path}'")
244247
if self.encrypted:
@@ -254,7 +257,7 @@ def to_sql(self, alias: str) -> str:
254257
alias_sql = (
255258
f" AS {alias}" if not (self.type == "motherduck" or self.path.startswith("md:")) else ""
256259
)
257-
return f"ATTACH IF NOT EXISTS '{self.path}'{alias_sql}{options_sql}"
260+
return f"ATTACH IF NOT EXISTS '{path}'{alias_sql}{options_sql}"
258261

259262

260263
class BaseDuckDBConnectionConfig(ConnectionConfig):

tests/core/test_connection_config.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,29 @@ def test_duckdb_attach_ducklake_catalog(make_config):
742742
assert ducklake_catalog.encrypted is True
743743
assert ducklake_catalog.data_inlining_row_limit == 10
744744
# Check that the generated SQL includes DATA_PATH
745-
assert "DATA_PATH '/tmp/ducklake_data'" in ducklake_catalog.to_sql("ducklake")
746-
assert "ENCRYPTED" in ducklake_catalog.to_sql("ducklake")
747-
assert "DATA_INLINING_ROW_LIMIT 10" in ducklake_catalog.to_sql("ducklake")
745+
generated_sql = ducklake_catalog.to_sql("ducklake")
746+
assert "DATA_PATH '/tmp/ducklake_data'" in generated_sql
747+
assert "ENCRYPTED" in generated_sql
748+
assert "DATA_INLINING_ROW_LIMIT 10" in generated_sql
749+
# Check that the ducklake: prefix is automatically added
750+
assert "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake'" in generated_sql
751+
752+
# Test that a path with existing ducklake: prefix is preserved
753+
config_with_prefix = make_config(
754+
type="duckdb",
755+
catalogs={
756+
"ducklake": DuckDBAttachOptions(
757+
type="ducklake",
758+
path="ducklake:catalog.ducklake",
759+
data_path="/tmp/ducklake_data",
760+
),
761+
},
762+
)
763+
ducklake_catalog_with_prefix = config_with_prefix.catalogs.get("ducklake")
764+
generated_sql_with_prefix = ducklake_catalog_with_prefix.to_sql("ducklake")
765+
assert "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake'" in generated_sql_with_prefix
766+
# Ensure we don't have double prefixes
767+
assert "'ducklake:catalog.ducklake" in generated_sql_with_prefix
748768

749769

750770
def test_duckdb_attach_options():
@@ -762,6 +782,22 @@ def test_duckdb_attach_options():
762782
assert options.to_sql(alias="db") == "ATTACH IF NOT EXISTS 'test.db' AS db"
763783

764784

785+
def test_ducklake_attach_add_ducklake_prefix():
786+
# Test that ducklake: prefix is automatically added when missing
787+
options = DuckDBAttachOptions(type="ducklake", path="catalog.ducklake")
788+
assert (
789+
options.to_sql(alias="my_ducklake")
790+
== "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake' AS my_ducklake"
791+
)
792+
793+
# Test that ducklake: prefix is preserved when already present
794+
options = DuckDBAttachOptions(type="ducklake", path="ducklake:catalog.ducklake")
795+
assert (
796+
options.to_sql(alias="my_ducklake")
797+
== "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake' AS my_ducklake"
798+
)
799+
800+
765801
def test_duckdb_config_json_strings(make_config):
766802
config = make_config(
767803
type="duckdb",

0 commit comments

Comments
 (0)