@@ -148,10 +148,34 @@ impl Catalog for SqlCatalog {
148148 /// Create a namespace in the catalog
149149 async fn create_namespace (
150150 & self ,
151- _namespace : & Namespace ,
152- _properties : Option < HashMap < String , String > > ,
151+ namespace : & Namespace ,
152+ properties : Option < HashMap < String , String > > ,
153153 ) -> Result < HashMap < String , String > , IcebergError > {
154- todo ! ( )
154+ let catalog_name = self . name . clone ( ) ;
155+ let namespace_str = namespace. to_string ( ) ;
156+ let properties = properties. unwrap_or_default ( ) ;
157+
158+ // Insert namespace properties into the database
159+ for ( key, value) in & properties {
160+ sqlx:: query ( & format ! (
161+ "insert into iceberg_namespace_properties (catalog_name, namespace, property_key, property_value) values ('{catalog_name}', '{namespace_str}', '{key}', '{value}');"
162+ ) )
163+ . execute ( & self . pool )
164+ . await
165+ . map_err ( Error :: from) ?;
166+ }
167+
168+ // If no properties were provided, still create an entry to mark the namespace as existing
169+ if properties. is_empty ( ) {
170+ sqlx:: query ( & format ! (
171+ "insert into iceberg_namespace_properties (catalog_name, namespace, property_key, property_value) values ('{catalog_name}', '{namespace_str}', 'exists', 'true');"
172+ ) )
173+ . execute ( & self . pool )
174+ . await
175+ . map_err ( Error :: from) ?;
176+ }
177+
178+ Ok ( properties)
155179 }
156180 /// Drop a namespace in the catalog
157181 async fn drop_namespace ( & self , _namespace : & Namespace ) -> Result < ( ) , IcebergError > {
@@ -201,8 +225,7 @@ impl Catalog for SqlCatalog {
201225
202226 let rows = {
203227 sqlx:: query ( & format ! (
204- "select distinct table_namespace from iceberg_tables where catalog_name = '{}';" ,
205- & name
228+ "select distinct namespace from iceberg_namespace_properties where catalog_name = '{name}';" ,
206229 ) )
207230 . fetch_all ( & self . pool )
208231 . await
@@ -840,6 +863,19 @@ pub mod tests {
840863
841864 ctx. register_catalog ( "warehouse" , catalog) ;
842865
866+ let sql = & "CREATE SCHEMA warehouse.tpch;" . to_string ( ) ;
867+
868+ let plan = ctx. state ( ) . create_logical_plan ( sql) . await . unwrap ( ) ;
869+
870+ let transformed = plan. transform ( iceberg_transform) . data ( ) . unwrap ( ) ;
871+
872+ ctx. execute_logical_plan ( transformed)
873+ . await
874+ . unwrap ( )
875+ . collect ( )
876+ . await
877+ . expect ( "Failed to execute query plan." ) ;
878+
843879 let sql = "CREATE EXTERNAL TABLE lineitem (
844880 L_ORDERKEY BIGINT NOT NULL,
845881 L_PARTKEY BIGINT NOT NULL,
0 commit comments