11import typing as t
2+ from pathlib import Path
23
34import pandas as pd # noqa: TID253
45import pytest
@@ -17,6 +18,15 @@ def adapter(duck_conn):
1718 return DuckDBEngineAdapter (lambda : duck_conn )
1819
1920
21+ @pytest .fixture
22+ def ducklake_conn (duck_conn , tmp_path_factory ):
23+ extension_directory = tmp_path_factory .getbasetemp () / "duckdb_extensions"
24+ duck_conn .execute ("SET extension_directory = ?" , [str (extension_directory )])
25+ duck_conn .install_extension ("ducklake" )
26+ duck_conn .load_extension ("ducklake" )
27+ return duck_conn
28+
29+
2030def test_create_view (adapter : EngineAdapter , duck_conn ):
2131 adapter .create_view ("test_view" , parse_one ("SELECT a FROM tbl" )) # type: ignore
2232 adapter .create_view ("test_view" , parse_one ("SELECT a FROM tbl" )) # type: ignore
@@ -126,17 +136,32 @@ def test_drop_catalog_motherduck(make_mocked_engine_adapter: t.Callable) -> None
126136 assert to_sql_calls (adapter ) == ['DROP DATABASE IF EXISTS "foo" CASCADE' ]
127137
128138
129- def test_ducklake_partitioning (adapter : EngineAdapter , duck_conn , tmp_path ):
139+ def test_ducklake_extension_uses_worker_owned_directory (ducklake_conn , tmp_path_factory ):
140+ worker_directory = tmp_path_factory .getbasetemp () / "duckdb_extensions"
141+ extension_directory = Path (
142+ ducklake_conn .execute (
143+ "SELECT value FROM duckdb_settings() WHERE name = 'extension_directory'"
144+ ).fetchone ()[0 ]
145+ )
146+ install_path = Path (
147+ ducklake_conn .execute (
148+ "SELECT install_path FROM duckdb_extensions() WHERE extension_name = 'ducklake'"
149+ ).fetchone ()[0 ]
150+ )
151+
152+ assert extension_directory == worker_directory
153+ assert install_path .is_relative_to (worker_directory )
154+
155+
156+ def test_ducklake_partitioning (adapter : EngineAdapter , ducklake_conn , tmp_path ):
130157 catalog = "a_ducklake_db"
131158
132- duck_conn .install_extension ("ducklake" )
133- duck_conn .load_extension ("ducklake" )
134- duck_conn .execute (
159+ ducklake_conn .execute (
135160 f"ATTACH 'ducklake:{ tmp_path } /{ catalog } .ducklake' AS { catalog } (DATA_PATH '{ tmp_path } ');"
136161 )
137162
138163 # no partitions on catalog creation
139- partition_info = duck_conn .execute (
164+ partition_info = ducklake_conn .execute (
140165 f"SELECT * FROM __ducklake_metadata_{ catalog } .main.ducklake_partition_info"
141166 ).fetchdf ()
142167 assert partition_info .empty
@@ -150,31 +175,29 @@ def test_ducklake_partitioning(adapter: EngineAdapter, duck_conn, tmp_path):
150175 )
151176
152177 # 1 partition after table creation
153- partition_info = duck_conn .execute (
178+ partition_info = ducklake_conn .execute (
154179 f"SELECT * FROM __ducklake_metadata_{ catalog } .main.ducklake_partition_info"
155180 ).fetchdf ()
156181 assert partition_info .shape [0 ] == 1
157182
158183
159- def test_drop_table_ducklake_no_cascade (adapter : EngineAdapter , duck_conn , tmp_path ):
184+ def test_drop_table_ducklake_no_cascade (adapter : EngineAdapter , ducklake_conn , tmp_path ):
160185 # DuckLake does not implement DROP TABLE/VIEW ... CASCADE, so the adapter must
161186 # omit CASCADE for objects in a DuckLake catalog while keeping it for native catalogs.
162187 catalog = "a_ducklake_db"
163188
164- duck_conn .install_extension ("ducklake" )
165- duck_conn .load_extension ("ducklake" )
166- duck_conn .execute (
189+ ducklake_conn .execute (
167190 f"ATTACH 'ducklake:{ tmp_path } /{ catalog } .ducklake' AS { catalog } (DATA_PATH '{ tmp_path } ');"
168191 )
169192
170- duck_conn .execute (f"CREATE SCHEMA { catalog } .phys" )
171- duck_conn .execute (f"CREATE SCHEMA { catalog } .virt" )
172- duck_conn .execute (f"CREATE TABLE { catalog } .phys.t (i INTEGER)" )
173- duck_conn .execute (f"CREATE VIEW { catalog } .virt.v AS SELECT * FROM { catalog } .phys.t" )
193+ ducklake_conn .execute (f"CREATE SCHEMA { catalog } .phys" )
194+ ducklake_conn .execute (f"CREATE SCHEMA { catalog } .virt" )
195+ ducklake_conn .execute (f"CREATE TABLE { catalog } .phys.t (i INTEGER)" )
196+ ducklake_conn .execute (f"CREATE VIEW { catalog } .virt.v AS SELECT * FROM { catalog } .phys.t" )
174197
175198 # native catalog, cascade is passed through
176- duck_conn .execute ("CREATE TABLE memory.main.native_t (i INTEGER)" )
177- duck_conn .execute ("CREATE VIEW memory.main.native_v AS SELECT * FROM memory.main.native_t" )
199+ ducklake_conn .execute ("CREATE TABLE memory.main.native_t (i INTEGER)" )
200+ ducklake_conn .execute ("CREATE VIEW memory.main.native_v AS SELECT * FROM memory.main.native_t" )
178201
179202 adapter .drop_table (f"{ catalog } .phys.t" , cascade = True )
180203 adapter .drop_view (f"{ catalog } .virt.v" , cascade = True )
@@ -188,18 +211,16 @@ def test_drop_table_ducklake_no_cascade(adapter: EngineAdapter, duck_conn, tmp_p
188211
189212
190213def test_drop_table_ducklake_no_cascade_mixed_case_alias (
191- adapter : EngineAdapter , duck_conn , tmp_path
214+ adapter : EngineAdapter , ducklake_conn , tmp_path
192215):
193216 # Catalog aliases keep their case in duckdb_databases(), but SQLMesh normalizes
194217 # table names to lowercase, so the catalog type lookup must be case-insensitive.
195- duck_conn .install_extension ("ducklake" )
196- duck_conn .load_extension ("ducklake" )
197- duck_conn .execute (
218+ ducklake_conn .execute (
198219 f"ATTACH 'ducklake:{ tmp_path } /my_lake.ducklake' AS \" MyLake\" (DATA_PATH '{ tmp_path } ');"
199220 )
200- duck_conn .execute ("CREATE SCHEMA MyLake.phys" )
201- duck_conn .execute ("CREATE TABLE MyLake.phys.t (i INTEGER)" )
202- duck_conn .execute ("CREATE VIEW MyLake.phys.v AS SELECT * FROM MyLake.phys.t" )
221+ ducklake_conn .execute ("CREATE SCHEMA MyLake.phys" )
222+ ducklake_conn .execute ("CREATE TABLE MyLake.phys.t (i INTEGER)" )
223+ ducklake_conn .execute ("CREATE VIEW MyLake.phys.v AS SELECT * FROM MyLake.phys.t" )
203224
204225 adapter .drop_table ("mylake.phys.t" , cascade = True )
205226 adapter .drop_view ("mylake.phys.v" , cascade = True )
0 commit comments