Skip to content

Commit

Permalink
Update code, mark config_options() deprecated, add options()
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Mar 14, 2023
1 parent c0e80de commit 768cb38
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
5 changes: 1 addition & 4 deletions datafusion/core/src/catalog/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,7 @@ impl PartitionStream for InformationSchemaDfSettings {
// TODO: Stream this
futures::stream::once(async move {
// create a mem table with the names of tables
config.make_df_settings(
ctx.session_config().config_options(),
&mut builder,
);
config.make_df_settings(ctx.session_config().options(), &mut builder);
Ok(builder.finish())
}),
))
Expand Down
38 changes: 18 additions & 20 deletions datafusion/core/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ pub use datafusion_physical_expr::execution_props::ExecutionProps;
use datafusion_physical_expr::var_provider::is_system_variables;
use parking_lot::RwLock;
use std::collections::hash_map::Entry;
use std::string::String;
use std::sync::Arc;
use std::{
any::{Any, TypeId},
hash::{BuildHasherDefault, Hasher},
string::String,
};
use std::{
collections::{HashMap, HashSet},
fmt::Debug,
Expand Down Expand Up @@ -87,7 +83,7 @@ use crate::physical_plan::PhysicalPlanner;
use crate::variable::{VarProvider, VarType};
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use datafusion_common::{config::Extensions, OwnedTableReference, ScalarValue};
use datafusion_common::{config::Extensions, OwnedTableReference};
use datafusion_sql::{
parser::DFParser,
planner::{ContextProvider, SqlToRel},
Expand All @@ -107,6 +103,9 @@ use datafusion_optimizer::OptimizerConfig;
use datafusion_sql::planner::object_name_to_table_reference;
use uuid::Uuid;

// backwards compatibility
pub use datafusion_execution::config::SessionConfig;

use super::options::{
AvroReadOptions, CsvReadOptions, NdJsonReadOptions, ParquetReadOptions, ReadOptions,
};
Expand Down Expand Up @@ -296,7 +295,7 @@ impl SessionContext {
self.state
.read()
.config
.options
.options()
.sql_parser
.enable_ident_normalization
}
Expand Down Expand Up @@ -423,8 +422,7 @@ impl SessionContext {
variable, value, ..
}) => {
let mut state = self.state.write();
let config_options = &mut state.config.options;
config_options.set(&variable, &value)?;
state.config.options_mut().set(&variable, &value)?;
drop(state);

self.return_empty_dataframe()
Expand All @@ -445,7 +443,7 @@ impl SessionContext {
let (catalog, schema_name) = match tokens.len() {
1 => {
let state = self.state.read();
let name = &state.config.options.catalog.default_catalog;
let name = &state.config.options().catalog.default_catalog;
let catalog =
state.catalog_list.catalog(name).ok_or_else(|| {
DataFusionError::Execution(format!(
Expand Down Expand Up @@ -1237,7 +1235,7 @@ impl SessionState {

default_catalog
.register_schema(
&config.config_options().catalog.default_schema,
&config.options().catalog.default_schema,
Arc::new(MemorySchemaProvider::new()),
)
.expect("memory catalog provider can register schema");
Expand All @@ -1250,7 +1248,7 @@ impl SessionState {
);

catalog_list.register_catalog(
config.config_options().catalog.default_catalog.clone(),
config.options().catalog.default_catalog.clone(),
Arc::new(default_catalog),
);
}
Expand Down Expand Up @@ -1326,16 +1324,16 @@ impl SessionState {
runtime: &Arc<RuntimeEnv>,
default_catalog: &MemoryCatalogProvider,
) {
let url = config.options.catalog.location.as_ref();
let format = config.options.catalog.format.as_ref();
let url = config.options().catalog.location.as_ref();
let format = config.options().catalog.format.as_ref();
let (url, format) = match (url, format) {
(Some(url), Some(format)) => (url, format),
_ => return,
};
let url = url.to_string();
let format = format.to_string();

let has_header = config.options.catalog.has_header;
let has_header = config.options().catalog.has_header;
let url = Url::parse(url.as_str()).expect("Invalid default catalog location!");
let authority = match url.host_str() {
Some(host) => format!("{}://{}", url.scheme(), host),
Expand Down Expand Up @@ -1551,7 +1549,7 @@ impl SessionState {
}

let enable_ident_normalization =
self.config.options.sql_parser.enable_ident_normalization;
self.config.options().sql_parser.enable_ident_normalization;
relations
.into_iter()
.map(|x| object_name_to_table_reference(x, enable_ident_normalization))
Expand All @@ -1571,9 +1569,9 @@ impl SessionState {
};

let enable_ident_normalization =
self.config.options.sql_parser.enable_ident_normalization;
self.config.options().sql_parser.enable_ident_normalization;
let parse_float_as_decimal =
self.config.options.sql_parser.parse_float_as_decimal;
self.config.options().sql_parser.parse_float_as_decimal;
for reference in references {
let table = reference.table();
let resolved = self.resolve_table_ref(reference.as_table_reference());
Expand Down Expand Up @@ -1682,7 +1680,7 @@ impl SessionState {

/// return the configuration options
pub fn config_options(&self) -> &ConfigOptions {
self.config.config_options()
self.config.options()
}

/// Get a new TaskContext to run in this session
Expand Down Expand Up @@ -2620,7 +2618,7 @@ mod tests {

let test = task_context
.session_config()
.config_options()
.options()
.extensions
.get::<TestExtension>();
assert!(test.is_some());
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_plan/file_format/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl ExecutionPlan for ParquetExec {
})
})?;

let config_options = ctx.session_config().config_options();
let config_options = ctx.session_config().options();

let opener = ParquetOpener {
partition_index,
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl ContextWithParquet {
let file = match unit {
Unit::RowGroup => make_test_file_rg(scenario).await,
Unit::Page => {
let config = config.config_options_mut();
let config = config.options_mut();
config.execution.parquet.enable_page_index = true;
make_test_file_page(scenario).await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ fn create_new_table(
let sql_to_rel = SqlToRel::new_with_options(
&LogicTestContextProvider {},
ParserOptions {
parse_float_as_decimal: config
.config_options()
.sql_parser
.parse_float_as_decimal,
parse_float_as_decimal: config.options().sql_parser.parse_float_as_decimal,
enable_ident_normalization: config
.config_options()
.options()
.sql_parser
.enable_ident_normalization,
},
Expand Down
25 changes: 19 additions & 6 deletions datafusion/execution/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// specific language governing permissions and limitations
// under the License.

use std::{collections::HashMap, hash::{BuildHasherDefault, Hasher}, sync::Arc, any::{TypeId, Any}};

use datafusion_common::{config::ConfigOptions, ScalarValue, Result};


use std::{
any::{Any, TypeId},
collections::HashMap,
hash::{BuildHasherDefault, Hasher},
sync::Arc,
};

use datafusion_common::{config::ConfigOptions, Result, ScalarValue};

/// Configuration options for Execution context
#[derive(Clone)]
Expand Down Expand Up @@ -242,15 +244,27 @@ impl SessionConfig {
}

/// Return a handle to the configuration options.
#[deprecated(since = "21.0.0", note = "use options() instead")]
pub fn config_options(&self) -> &ConfigOptions {
&self.options
}

/// Return a mutable handle to the configuration options.
#[deprecated(since = "21.0.0", note = "use options_mut() instead")]
pub fn config_options_mut(&mut self) -> &mut ConfigOptions {
&mut self.options
}

/// Return a handle to the configuration options.
pub fn options(&self) -> &ConfigOptions {
&self.options
}

/// Return a mutable handle to the configuration options.
pub fn options_mut(&mut self) -> &mut ConfigOptions {
&mut self.options
}

/// Add extensions.
///
/// Extensions can be used to attach extra data to the session config -- e.g. tracing information or caches.
Expand Down Expand Up @@ -329,7 +343,6 @@ impl From<ConfigOptions> for SessionConfig {
}
}


/// Map that holds opaque objects indexed by their type.
///
/// Data is wrapped into an [`Arc`] to enable [`Clone`] while still being [object safe].
Expand Down

0 comments on commit 768cb38

Please sign in to comment.