@@ -249,7 +249,6 @@ impl ExecutionContext {
249
249
} else {
250
250
Some ( Arc :: new ( schema. as_ref ( ) . to_owned ( ) . into ( ) ) )
251
251
} ;
252
-
253
252
self . register_listing_table ( name, location, options, provided_schema)
254
253
. await ?;
255
254
let plan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
@@ -289,25 +288,52 @@ impl ExecutionContext {
289
288
..
290
289
} ) => {
291
290
// sqlparser doesnt accept database / catalog as parameter to CREATE SCHEMA
292
- // so for now, we default to "public" schema
293
- let catalog = self . catalog ( "public" ) ;
294
- match catalog {
295
- Some ( c) => {
296
- if if_not_exists { }
297
- if let Some ( s) = c. schema ( & schema_name) {
298
- Err ( DataFusionError :: Execution ( format ! (
299
- "Schema {:?} already exists" ,
300
- schema_name
301
- ) ) )
302
- } ;
291
+ // so for now, we default to "datafusion" catalog
292
+ let default_catalog = "datafusion" ;
293
+ let catalog = self . catalog ( default_catalog) . ok_or_else ( || {
294
+ DataFusionError :: Execution ( String :: from (
295
+ "Missing 'datafusion' catalog" ,
296
+ ) )
297
+ } ) ?;
298
+
299
+ let schema = catalog. schema ( & schema_name) ;
303
300
301
+ match ( if_not_exists, schema) {
302
+ //
303
+ ( true , Some ( _) ) => {
304
+ println ! ( "Schema '{:?}' already exists" , & schema_name) ;
305
+ let plan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
306
+ Ok ( Arc :: new ( DataFrameImpl :: new ( self . state . clone ( ) , & plan) ) )
307
+ }
308
+ ( true , None ) | ( false , None ) => {
309
+ println ! ( "Creating schema {:?}" , schema_name) ;
304
310
let schema = Arc :: new ( MemorySchemaProvider :: new ( ) ) ;
305
- c. register_schema ( & schema_name, schema) ;
311
+ let plan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
312
+ schema. register_table (
313
+ "test" . into ( ) ,
314
+ Arc :: new ( DataFrameImpl :: new ( self . state . clone ( ) , & plan) ) ,
315
+ ) ?;
316
+ let schem_reg_res = catalog. register_schema ( & schema_name, schema) ;
317
+ match schem_reg_res {
318
+ Some ( _) => {
319
+ println ! ( "Existing schema with name" )
320
+ }
321
+ None => {
322
+ println ! ( "Succesfully registerd" )
323
+ }
324
+ } ;
325
+ // println!("Schemas pre reg: {:?}", catalog.schema_names);
326
+ self . register_catalog ( default_catalog, catalog) ;
327
+ println ! (
328
+ "Schema names: {:?}" ,
329
+ self . catalog( default_catalog) . unwrap( ) . schema_names( )
330
+ ) ;
306
331
let plan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
307
332
Ok ( Arc :: new ( DataFrameImpl :: new ( self . state . clone ( ) , & plan) ) )
308
333
}
309
- None => Err ( DataFusionError :: Execution ( String :: from (
310
- "'public' catalog does not exist" ,
334
+ ( false , Some ( _) ) => Err ( DataFusionError :: Execution ( format ! (
335
+ "Schema '{:?}' already exists" ,
336
+ schema_name
311
337
) ) ) ,
312
338
}
313
339
}
@@ -563,10 +589,18 @@ impl ExecutionContext {
563
589
564
590
let state = self . state . lock ( ) ;
565
591
let catalog = if state. config . information_schema {
566
- Arc :: new ( CatalogWithInformationSchema :: new (
567
- Arc :: downgrade ( & state. catalog_list ) ,
568
- catalog,
569
- ) )
592
+ let is = state
593
+ . catalog_list
594
+ . catalog ( "datafusion" )
595
+ . unwrap ( )
596
+ . schema ( "information_schema" ) ;
597
+ match is {
598
+ Some ( _) => catalog,
599
+ None => Arc :: new ( CatalogWithInformationSchema :: new (
600
+ Arc :: downgrade ( & state. catalog_list ) ,
601
+ catalog,
602
+ ) ) ,
603
+ }
570
604
} else {
571
605
catalog
572
606
} ;
@@ -1183,6 +1217,10 @@ impl ExecutionContextState {
1183
1217
table_ref : impl Into < TableReference < ' a > > ,
1184
1218
) -> Result < Arc < dyn SchemaProvider > > {
1185
1219
let resolved_ref = self . resolve_table_ref ( table_ref. into ( ) ) ;
1220
+ println ! (
1221
+ "Resolved ref: {:?}:{:?}:{:?}" ,
1222
+ resolved_ref. catalog, resolved_ref. schema, resolved_ref. table
1223
+ ) ;
1186
1224
1187
1225
self . catalog_list
1188
1226
. catalog ( resolved_ref. catalog )
0 commit comments