-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup InformationSchema plumbing #4740
Merged
tustvold
merged 1 commit into
apache:master
from
tustvold:cleanup-information-schema-plumbing
Dec 27, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,7 @@ | |
|
||
//! SessionContext contains methods for registering data sources and executing queries | ||
use crate::{ | ||
catalog::{ | ||
catalog::{CatalogList, MemoryCatalogList}, | ||
information_schema::CatalogWithInformationSchema, | ||
}, | ||
catalog::catalog::{CatalogList, MemoryCatalogList}, | ||
config::{ | ||
OPT_COLLECT_STATISTICS, OPT_CREATE_DEFAULT_CATALOG_AND_SCHEMA, | ||
OPT_INFORMATION_SCHEMA, OPT_PARQUET_ENABLE_PRUNING, OPT_REPARTITION_AGGREGATIONS, | ||
|
@@ -97,6 +94,7 @@ use datafusion_sql::{ | |
use parquet::file::properties::WriterProperties; | ||
use url::Url; | ||
|
||
use crate::catalog::information_schema::{InformationSchemaProvider, INFORMATION_SCHEMA}; | ||
use crate::catalog::listing_schema::ListingSchemaProvider; | ||
use crate::datasource::object_store::ObjectStoreUrl; | ||
use crate::execution::memory_pool::MemoryPool; | ||
|
@@ -422,10 +420,6 @@ impl SessionContext { | |
)) | ||
} | ||
} | ||
// Since information_schema config may have changed, revalidate | ||
if variable == OPT_INFORMATION_SCHEMA { | ||
state.update_information_schema(); | ||
} | ||
drop(state); | ||
|
||
self.return_empty_dataframe() | ||
|
@@ -877,18 +871,10 @@ impl SessionContext { | |
catalog: Arc<dyn CatalogProvider>, | ||
) -> Option<Arc<dyn CatalogProvider>> { | ||
let name = name.into(); | ||
let information_schema = self.copied_config().information_schema(); | ||
let state = self.state.read(); | ||
let catalog = if information_schema { | ||
Arc::new(CatalogWithInformationSchema::new( | ||
Arc::downgrade(&state.catalog_list), | ||
catalog, | ||
)) | ||
} else { | ||
catalog | ||
}; | ||
|
||
state.catalog_list.register_catalog(name, catalog) | ||
self.state | ||
.read() | ||
.catalog_list | ||
.register_catalog(name, catalog) | ||
} | ||
|
||
/// Retrieves the list of available catalog names. | ||
|
@@ -1587,7 +1573,7 @@ impl SessionState { | |
// rule below performs this analysis and removes unnecessary `SortExec`s. | ||
physical_optimizers.push(Arc::new(OptimizeSorts::new())); | ||
|
||
let mut this = SessionState { | ||
SessionState { | ||
session_id, | ||
optimizer: Optimizer::new(), | ||
physical_optimizers, | ||
|
@@ -1598,60 +1584,6 @@ impl SessionState { | |
config, | ||
execution_props: ExecutionProps::new(), | ||
runtime_env: runtime, | ||
}; | ||
this.update_information_schema(); | ||
this | ||
} | ||
|
||
/// Enables/Disables information_schema support based on the value of | ||
/// config.information_schema() | ||
/// | ||
/// When enabled, all catalog providers are wrapped with | ||
/// [`CatalogWithInformationSchema`] if needed | ||
/// | ||
/// When disabled, any [`CatalogWithInformationSchema`] is unwrapped | ||
fn update_information_schema(&mut self) { | ||
let enabled = self.config.information_schema(); | ||
let catalog_list = &self.catalog_list; | ||
|
||
let new_catalogs: Vec<_> = self | ||
.catalog_list | ||
.catalog_names() | ||
.into_iter() | ||
.map(|catalog_name| { | ||
// unwrap because the list of names came from catalog | ||
// list so it should still be there | ||
let catalog = catalog_list.catalog(&catalog_name).unwrap(); | ||
|
||
let unwrapped = catalog | ||
.as_any() | ||
.downcast_ref::<CatalogWithInformationSchema>() | ||
.map(|wrapped| wrapped.inner()); | ||
|
||
let new_catalog = match (enabled, unwrapped) { | ||
// already wrapped, no thing needed | ||
(true, Some(_)) => catalog, | ||
(true, None) => { | ||
// wrap the catalog in information schema | ||
Arc::new(CatalogWithInformationSchema::new( | ||
Arc::downgrade(catalog_list), | ||
catalog, | ||
)) | ||
} | ||
// disabling, currently wrapped | ||
(false, Some(unwrapped)) => unwrapped, | ||
// disabling, currently unwrapped | ||
(false, None) => catalog, | ||
}; | ||
|
||
(catalog_name, new_catalog) | ||
}) | ||
// collect to avoid concurrent modification | ||
.collect(); | ||
|
||
// replace all catalogs | ||
for (catalog_name, new_catalog) in new_catalogs { | ||
catalog_list.register_catalog(catalog_name, new_catalog); | ||
} | ||
} | ||
|
||
|
@@ -1721,6 +1653,12 @@ impl SessionState { | |
table_ref: impl Into<TableReference<'a>>, | ||
) -> Result<Arc<dyn SchemaProvider>> { | ||
let resolved_ref = self.resolve_table_ref(table_ref); | ||
if self.config.information_schema() && resolved_ref.schema == INFORMATION_SCHEMA { | ||
return Ok(Arc::new(InformationSchemaProvider::new( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cool -- it makes the information schema provider on demand 👍 |
||
self.catalog_list.clone(), | ||
))); | ||
} | ||
|
||
self.catalog_list | ||
.catalog(resolved_ref.catalog) | ||
.ok_or_else(|| { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There wasn't anything public in the module so we might as well just make it crate private
https://docs.rs/datafusion/latest/datafusion/catalog/information_schema/index.html