Skip to content

Commit

Permalink
MINOR: reduce pub in OptimizerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Sep 17, 2022
1 parent 12f047e commit 543f8c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
18 changes: 10 additions & 8 deletions datafusion/core/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,14 +1564,16 @@ impl SessionState {

/// Optimizes the logical plan by applying optimizer rules.
pub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan> {
let mut optimizer_config = OptimizerConfig::new().with_skip_failing_rules(
self.config
.config_options
.read()
.get_bool(OPT_OPTIMIZER_SKIP_FAILED_RULES),
);
optimizer_config.query_execution_start_time =
self.execution_props.query_execution_start_time;
let mut optimizer_config = OptimizerConfig::new()
.with_skip_failing_rules(
self.config
.config_options
.read()
.get_bool(OPT_OPTIMIZER_SKIP_FAILED_RULES),
)
.with_query_execution_start_time(
self.execution_props.query_execution_start_time,
);

if let LogicalPlan::Explain(e) = plan {
let mut stringified_plans = e.stringified_plans.clone();
Expand Down
31 changes: 26 additions & 5 deletions datafusion/optimizer/src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ pub trait OptimizerRule {
fn name(&self) -> &str;
}

/// Placeholder for optimizer configuration options
/// Options to control the DataFusion Optimizer.
#[derive(Debug)]
pub struct OptimizerConfig {
/// Query execution start time that can be used to rewrite expressions such as `now()`
/// to use a literal value instead
pub query_execution_start_time: DateTime<Utc>,
/// Query execution start time that can be used to rewrite
/// expressions such as `now()` to use a literal value instead
query_execution_start_time: DateTime<Utc>,
/// id generator for optimizer passes
// TODO this should not be on the config,
// it should be its own 'OptimizerState' or something)
next_id: usize,
/// Option to skip rules that produce errors
skip_failing_rules: bool,
Expand All @@ -59,16 +62,34 @@ impl OptimizerConfig {
}
}

/// Specify whether the optimizer should skip rules that produce errors, or fail the query
/// Specify whether the optimizer should skip rules that produce
/// errors, or fail the query
pub fn with_query_execution_start_time(
mut self,
query_execution_tart_time: DateTime<Utc>,
) -> Self {
self.query_execution_start_time = query_execution_tart_time;
self
}

/// Specify whether the optimizer should skip rules that produce
/// errors, or fail the query
pub fn with_skip_failing_rules(mut self, b: bool) -> Self {
self.skip_failing_rules = b;
self
}

/// Generate the next ID needed
pub fn next_id(&mut self) -> usize {
self.next_id += 1;
self.next_id
}

/// Return the time at which the query execution started. This
/// time is used as the value for now()
pub fn query_execution_start_time(&self) -> DateTime<Utc> {
self.query_execution_start_time
}
}

impl Default for OptimizerConfig {
Expand Down
10 changes: 5 additions & 5 deletions datafusion/optimizer/src/simplify_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl OptimizerRule for SimplifyExpressions {
) -> Result<LogicalPlan> {
let mut execution_props = ExecutionProps::new();
execution_props.query_execution_start_time =
optimizer_config.query_execution_start_time;
optimizer_config.query_execution_start_time();
self.optimize_internal(plan, &execution_props)
}
}
Expand Down Expand Up @@ -1887,8 +1887,8 @@ mod tests {

// expect optimizing will result in an error, returning the error string
fn get_optimized_plan_err(plan: &LogicalPlan, date_time: &DateTime<Utc>) -> String {
let mut config = OptimizerConfig::new();
config.query_execution_start_time = *date_time;
let mut config =
OptimizerConfig::new().with_query_execution_start_time(*date_time);
let rule = SimplifyExpressions::new();

let err = rule
Expand All @@ -1902,8 +1902,8 @@ mod tests {
plan: &LogicalPlan,
date_time: &DateTime<Utc>,
) -> String {
let mut config = OptimizerConfig::new();
config.query_execution_start_time = *date_time;
let mut config =
OptimizerConfig::new().with_query_execution_start_time(*date_time);
let rule = SimplifyExpressions::new();

let optimized_plan = rule
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl OptimizerRule for TypeCoercion {

let mut execution_props = ExecutionProps::new();
execution_props.query_execution_start_time =
optimizer_config.query_execution_start_time;
optimizer_config.query_execution_start_time();
let const_evaluator = ConstEvaluator::try_new(&execution_props)?;

let mut expr_rewrite = TypeCoercionRewriter {
Expand Down

0 comments on commit 543f8c2

Please sign in to comment.