11import typing as t
22
3+ import os
34import pandas as pd # noqa: TID253
45import pytest
6+ from pytest_mock .plugin import MockerFixture
57from sqlglot import expressions as exp
68from sqlglot import parse_one
7-
89from sqlmesh .core .engine_adapter import DuckDBEngineAdapter , EngineAdapter
910from tests .core .engine_adapter import to_sql_calls
1011
@@ -77,9 +78,12 @@ def test_set_current_catalog(make_mocked_engine_adapter: t.Callable, duck_conn):
7778 ]
7879
7980
80- def test_temporary_table (make_mocked_engine_adapter : t .Callable , duck_conn ):
81+ def test_temporary_table (make_mocked_engine_adapter : t .Callable , mocker : MockerFixture ):
8182 adapter = make_mocked_engine_adapter (DuckDBEngineAdapter )
8283
84+ mocker .patch .object (adapter , "get_current_catalog" , return_value = "test_catalog" )
85+ mocker .patch .object (adapter , "fetchone" , return_value = ("test_catalog" ,))
86+
8387 adapter .create_table (
8488 "test_table" ,
8589 {"a" : exp .DataType .build ("INT" ), "b" : exp .DataType .build ("INT" )},
@@ -103,3 +107,32 @@ def test_drop_catalog(make_mocked_engine_adapter: t.Callable) -> None:
103107 adapter .drop_catalog (exp .to_identifier ("foo" ))
104108
105109 assert to_sql_calls (adapter ) == ['DETACH DATABASE IF EXISTS "foo"' ]
110+
111+
112+ def test_ducklake_partitioning (adapter : EngineAdapter , duck_conn , tmp_path ):
113+ os .chdir (tmp_path )
114+ catalog = "a_ducklake_db"
115+
116+ duck_conn .install_extension ("ducklake" )
117+ duck_conn .load_extension ("ducklake" )
118+ duck_conn .execute (f"ATTACH 'ducklake:{ catalog } ';" )
119+
120+ # no partitions on catalog creation
121+ partition_info = duck_conn .execute (
122+ f"SELECT * FROM __ducklake_metadata_{ catalog } .main.ducklake_partition_info"
123+ ).fetchdf ()
124+ assert partition_info .empty
125+
126+ adapter .set_current_catalog (catalog )
127+ adapter .create_schema ("test_schema" )
128+ adapter .create_table (
129+ "test_schema.test_table" ,
130+ {"a" : exp .DataType .build ("INT" ), "b" : exp .DataType .build ("INT" )},
131+ partitioned_by = [exp .to_column ("a" ), exp .to_column ("b" )],
132+ )
133+
134+ # 1 partition after table creation
135+ partition_info = duck_conn .execute (
136+ f"SELECT * FROM __ducklake_metadata_{ catalog } .main.ducklake_partition_info"
137+ ).fetchdf ()
138+ assert partition_info .shape [0 ] == 1
0 commit comments