17
17
18
18
//! SessionContext contains methods for registering data sources and executing queries
19
19
use crate :: {
20
- catalog:: {
21
- catalog:: { CatalogList , MemoryCatalogList } ,
22
- information_schema:: CatalogWithInformationSchema ,
23
- } ,
20
+ catalog:: catalog:: { CatalogList , MemoryCatalogList } ,
24
21
config:: {
25
22
OPT_COLLECT_STATISTICS , OPT_CREATE_DEFAULT_CATALOG_AND_SCHEMA ,
26
23
OPT_INFORMATION_SCHEMA , OPT_PARQUET_ENABLE_PRUNING , OPT_REPARTITION_AGGREGATIONS ,
@@ -97,6 +94,7 @@ use datafusion_sql::{
97
94
use parquet:: file:: properties:: WriterProperties ;
98
95
use url:: Url ;
99
96
97
+ use crate :: catalog:: information_schema:: { InformationSchemaProvider , INFORMATION_SCHEMA } ;
100
98
use crate :: catalog:: listing_schema:: ListingSchemaProvider ;
101
99
use crate :: datasource:: object_store:: ObjectStoreUrl ;
102
100
use crate :: execution:: memory_pool:: MemoryPool ;
@@ -422,10 +420,6 @@ impl SessionContext {
422
420
) )
423
421
}
424
422
}
425
- // Since information_schema config may have changed, revalidate
426
- if variable == OPT_INFORMATION_SCHEMA {
427
- state. update_information_schema ( ) ;
428
- }
429
423
drop ( state) ;
430
424
431
425
self . return_empty_dataframe ( )
@@ -877,18 +871,10 @@ impl SessionContext {
877
871
catalog : Arc < dyn CatalogProvider > ,
878
872
) -> Option < Arc < dyn CatalogProvider > > {
879
873
let name = name. into ( ) ;
880
- let information_schema = self . copied_config ( ) . information_schema ( ) ;
881
- let state = self . state . read ( ) ;
882
- let catalog = if information_schema {
883
- Arc :: new ( CatalogWithInformationSchema :: new (
884
- Arc :: downgrade ( & state. catalog_list ) ,
885
- catalog,
886
- ) )
887
- } else {
888
- catalog
889
- } ;
890
-
891
- state. catalog_list . register_catalog ( name, catalog)
874
+ self . state
875
+ . read ( )
876
+ . catalog_list
877
+ . register_catalog ( name, catalog)
892
878
}
893
879
894
880
/// Retrieves the list of available catalog names.
@@ -1587,7 +1573,7 @@ impl SessionState {
1587
1573
// rule below performs this analysis and removes unnecessary `SortExec`s.
1588
1574
physical_optimizers. push ( Arc :: new ( OptimizeSorts :: new ( ) ) ) ;
1589
1575
1590
- let mut this = SessionState {
1576
+ SessionState {
1591
1577
session_id,
1592
1578
optimizer : Optimizer :: new ( ) ,
1593
1579
physical_optimizers,
@@ -1598,60 +1584,6 @@ impl SessionState {
1598
1584
config,
1599
1585
execution_props : ExecutionProps :: new ( ) ,
1600
1586
runtime_env : runtime,
1601
- } ;
1602
- this. update_information_schema ( ) ;
1603
- this
1604
- }
1605
-
1606
- /// Enables/Disables information_schema support based on the value of
1607
- /// config.information_schema()
1608
- ///
1609
- /// When enabled, all catalog providers are wrapped with
1610
- /// [`CatalogWithInformationSchema`] if needed
1611
- ///
1612
- /// When disabled, any [`CatalogWithInformationSchema`] is unwrapped
1613
- fn update_information_schema ( & mut self ) {
1614
- let enabled = self . config . information_schema ( ) ;
1615
- let catalog_list = & self . catalog_list ;
1616
-
1617
- let new_catalogs: Vec < _ > = self
1618
- . catalog_list
1619
- . catalog_names ( )
1620
- . into_iter ( )
1621
- . map ( |catalog_name| {
1622
- // unwrap because the list of names came from catalog
1623
- // list so it should still be there
1624
- let catalog = catalog_list. catalog ( & catalog_name) . unwrap ( ) ;
1625
-
1626
- let unwrapped = catalog
1627
- . as_any ( )
1628
- . downcast_ref :: < CatalogWithInformationSchema > ( )
1629
- . map ( |wrapped| wrapped. inner ( ) ) ;
1630
-
1631
- let new_catalog = match ( enabled, unwrapped) {
1632
- // already wrapped, no thing needed
1633
- ( true , Some ( _) ) => catalog,
1634
- ( true , None ) => {
1635
- // wrap the catalog in information schema
1636
- Arc :: new ( CatalogWithInformationSchema :: new (
1637
- Arc :: downgrade ( catalog_list) ,
1638
- catalog,
1639
- ) )
1640
- }
1641
- // disabling, currently wrapped
1642
- ( false , Some ( unwrapped) ) => unwrapped,
1643
- // disabling, currently unwrapped
1644
- ( false , None ) => catalog,
1645
- } ;
1646
-
1647
- ( catalog_name, new_catalog)
1648
- } )
1649
- // collect to avoid concurrent modification
1650
- . collect ( ) ;
1651
-
1652
- // replace all catalogs
1653
- for ( catalog_name, new_catalog) in new_catalogs {
1654
- catalog_list. register_catalog ( catalog_name, new_catalog) ;
1655
1587
}
1656
1588
}
1657
1589
@@ -1721,6 +1653,12 @@ impl SessionState {
1721
1653
table_ref : impl Into < TableReference < ' a > > ,
1722
1654
) -> Result < Arc < dyn SchemaProvider > > {
1723
1655
let resolved_ref = self . resolve_table_ref ( table_ref) ;
1656
+ if self . config . information_schema ( ) && resolved_ref. schema == INFORMATION_SCHEMA {
1657
+ return Ok ( Arc :: new ( InformationSchemaProvider :: new (
1658
+ self . catalog_list . clone ( ) ,
1659
+ ) ) ) ;
1660
+ }
1661
+
1724
1662
self . catalog_list
1725
1663
. catalog ( resolved_ref. catalog )
1726
1664
. ok_or_else ( || {
0 commit comments