Skip to content

Commit 31bc00d

Browse files
authored
Feat: add support for METADATA_SCHEMA in ducklake config.yml (#5616)
1 parent f421449 commit 31bc00d

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

docs/integrations/engines/duckdb.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ SQLMesh will place models with the explicit catalog "ephemeral", such as `epheme
8181
data_path: data/ducklake
8282
encrypted: True
8383
data_inlining_row_limit: 10
84+
metadata_schema: main
8485
```
85-
86+
8687
=== "Python"
8788

8889
```python linenums="1"
@@ -106,6 +107,7 @@ SQLMesh will place models with the explicit catalog "ephemeral", such as `epheme
106107
data_path="data/ducklake",
107108
encrypted=True,
108109
data_inlining_row_limit=10,
110+
metadata_schema="main",
109111
),
110112
}
111113
)
@@ -114,6 +116,14 @@ SQLMesh will place models with the explicit catalog "ephemeral", such as `epheme
114116
)
115117
```
116118

119+
**DuckLake Configuration Options:**
120+
121+
- `path`: Path to the DuckLake catalog file
122+
- `data_path`: Path where DuckLake data files are stored
123+
- `encrypted`: Whether to enable encryption for the catalog (default: `False`)
124+
- `data_inlining_row_limit`: Maximum number of rows to inline in the catalog (default: `0`)
125+
- `metadata_schema`: The schema in the catalog server in which to store the DuckLake metadata tables (default: `main`)
126+
117127
#### Other Connection Catalogs Example
118128

119129
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class DuckDBAttachOptions(BaseConfig):
238238
data_path: t.Optional[str] = None
239239
encrypted: bool = False
240240
data_inlining_row_limit: t.Optional[int] = None
241+
metadata_schema: t.Optional[str] = None
241242

242243
def to_sql(self, alias: str) -> str:
243244
options = []
@@ -259,6 +260,8 @@ def to_sql(self, alias: str) -> str:
259260
options.append("ENCRYPTED")
260261
if self.data_inlining_row_limit is not None:
261262
options.append(f"DATA_INLINING_ROW_LIMIT {self.data_inlining_row_limit}")
263+
if self.metadata_schema is not None:
264+
options.append(f"METADATA_SCHEMA '{self.metadata_schema}'")
262265

263266
options_sql = f" ({', '.join(options)})" if options else ""
264267
alias_sql = ""

tests/core/test_connection_config.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,37 @@ def test_ducklake_attach_add_ducklake_prefix():
822822
)
823823

824824

825+
def test_ducklake_metadata_schema():
826+
# Test that metadata_schema parameter is included when specified
827+
options = DuckDBAttachOptions(
828+
type="ducklake", path="catalog.ducklake", metadata_schema="custom_schema"
829+
)
830+
assert (
831+
options.to_sql(alias="my_ducklake")
832+
== "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake' AS my_ducklake (METADATA_SCHEMA 'custom_schema')"
833+
)
834+
835+
# Test that metadata_schema is not included when not specified (default behavior)
836+
options = DuckDBAttachOptions(type="ducklake", path="catalog.ducklake")
837+
assert (
838+
options.to_sql(alias="my_ducklake")
839+
== "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake' AS my_ducklake"
840+
)
841+
842+
# Test metadata_schema with other ducklake options
843+
options = DuckDBAttachOptions(
844+
type="ducklake",
845+
path="catalog.ducklake",
846+
data_path="/path/to/data",
847+
encrypted=True,
848+
metadata_schema="workspace_schema",
849+
)
850+
assert (
851+
options.to_sql(alias="my_ducklake")
852+
== "ATTACH IF NOT EXISTS 'ducklake:catalog.ducklake' AS my_ducklake (DATA_PATH '/path/to/data', ENCRYPTED, METADATA_SCHEMA 'workspace_schema')"
853+
)
854+
855+
825856
def test_duckdb_config_json_strings(make_config):
826857
config = make_config(
827858
type="duckdb",

0 commit comments

Comments
 (0)