Skip to content

Commit 2e4b441

Browse files
Add data path and encrypted to duckdb catalog (#4600)
1 parent 5a24441 commit 2e4b441

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

docs/integrations/engines/duckdb.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,53 @@ SQLMesh will place models with the explicit catalog "ephemeral", such as `epheme
6464
)
6565
```
6666

67+
#### DuckLake Catalog Example
68+
69+
=== "YAML"
70+
71+
```yaml linenums="1"
72+
gateways:
73+
my_gateway:
74+
connection:
75+
type: duckdb
76+
catalogs:
77+
ducklake:
78+
type: ducklake
79+
path: 'catalog.ducklake'
80+
data_path: data/ducklake
81+
encrypted: True
82+
```
83+
84+
=== "Python"
85+
86+
```python linenums="1"
87+
from sqlmesh.core.config import (
88+
Config,
89+
ModelDefaultsConfig,
90+
GatewayConfig,
91+
DuckDBConnectionConfig
92+
)
93+
from sqlmesh.core.config.connection import DuckDBAttachOptions
94+
95+
config = Config(
96+
model_defaults=ModelDefaultsConfig(dialect=<dialect>),
97+
gateways={
98+
"my_gateway": GatewayConfig(
99+
connection=DuckDBConnectionConfig(
100+
catalogs={
101+
"ducklake": DuckDBAttachOptions(
102+
type="ducklake",
103+
path="catalog.ducklake",
104+
data_path="data/ducklake",
105+
encrypted=True
106+
),
107+
}
108+
)
109+
),
110+
}
111+
)
112+
```
113+
67114
#### Other Connection Catalogs Example
68115

69116
Catalogs can also be defined to connect to anything that [DuckDB can be attached to](https://duckdb.org/docs/sql/statements/attach.html).

sqlmesh/core/config/connection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class DuckDBAttachOptions(BaseConfig):
221221
path: str
222222
read_only: bool = False
223223

224+
# DuckLake specific options
225+
data_path: t.Optional[str] = None
226+
encrypted: bool = False
227+
224228
def to_sql(self, alias: str) -> str:
225229
options = []
226230
# 'duckdb' is actually not a supported type, but we'd like to allow it for
@@ -229,6 +233,14 @@ def to_sql(self, alias: str) -> str:
229233
options.append(f"TYPE {self.type.upper()}")
230234
if self.read_only:
231235
options.append("READ_ONLY")
236+
237+
# DuckLake specific options
238+
if self.type == "ducklake":
239+
if self.data_path:
240+
options.append(f"DATA_PATH '{self.data_path}'")
241+
if self.encrypted:
242+
options.append("ENCRYPTED")
243+
232244
options_sql = f" ({', '.join(options)})" if options else ""
233245
alias_sql = ""
234246
# TODO: Add support for Postgres schema. Currently adding it blocks access to the information_schema

tests/core/test_connection_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,30 @@ def test_duckdb_attach_catalog(make_config):
602602
assert not config.is_recommended_for_state_sync
603603

604604

605+
def test_duckdb_attach_ducklake_catalog(make_config):
606+
config = make_config(
607+
type="duckdb",
608+
catalogs={
609+
"ducklake": DuckDBAttachOptions(
610+
type="ducklake",
611+
path="catalog.ducklake",
612+
data_path="/tmp/ducklake_data",
613+
encrypted=True,
614+
),
615+
},
616+
)
617+
assert isinstance(config, DuckDBConnectionConfig)
618+
ducklake_catalog = config.catalogs.get("ducklake")
619+
assert ducklake_catalog is not None
620+
assert ducklake_catalog.type == "ducklake"
621+
assert ducklake_catalog.path == "catalog.ducklake"
622+
assert ducklake_catalog.data_path == "/tmp/ducklake_data"
623+
assert ducklake_catalog.encrypted is True
624+
# Check that the generated SQL includes DATA_PATH
625+
assert "DATA_PATH '/tmp/ducklake_data'" in ducklake_catalog.to_sql("ducklake")
626+
assert "ENCRYPTED" in ducklake_catalog.to_sql("ducklake")
627+
628+
605629
def test_duckdb_attach_options():
606630
options = DuckDBAttachOptions(
607631
type="postgres", path="dbname=postgres user=postgres host=127.0.0.1", read_only=True

0 commit comments

Comments
 (0)