Skip to content

Commit ce3ad14

Browse files
committed
[datafusion] prepend physical_optimizer_rule before other rules
This is a bug fix that was introduced in restatedev#2004 Which change the order that optimizers are registered. The reason for this is described as a comment few lines above.
1 parent 062429b commit ce3ad14

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/storage-query-datafusion/src/context.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use datafusion::error::DataFusionError;
1818
use datafusion::execution::context::SQLOptions;
1919
use datafusion::execution::runtime_env::{RuntimeConfig, RuntimeEnv};
2020
use datafusion::execution::SessionStateBuilder;
21-
use datafusion::physical_optimizer::PhysicalOptimizerRule;
2221
use datafusion::physical_plan::SendableRecordBatchStream;
2322
use datafusion::prelude::{SessionConfig, SessionContext};
2423

@@ -159,6 +158,7 @@ impl QueryContext {
159158
Ok(ctx)
160159
}
161160

161+
#[allow(deprecated)]
162162
fn new(
163163
memory_limit: usize,
164164
temp_folder: Option<String>,
@@ -225,12 +225,14 @@ impl QueryContext {
225225
// A far more involved but potentially more robust solution would be wrap the SymmetricHashJoin in a ProjectionExec
226226
// If this would become an issue for any reason, then we can explore that alternative.
227227
//
228-
let physical_optimizers: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>> =
229-
vec![Arc::new(physical_optimizer::JoinRewrite::new())];
230228

231-
state_builder = state_builder.with_physical_optimizer_rules(physical_optimizers);
229+
let mut state = state_builder.build();
232230

233-
let state = state_builder.build();
231+
let join_rewrite = Arc::new(physical_optimizer::JoinRewrite::new());
232+
let mut optimizers = state.physical_optimizers().to_vec();
233+
optimizers.insert(0, join_rewrite);
234+
235+
state = state.with_physical_optimizer_rules(optimizers);
234236

235237
let ctx = SessionContext::new_with_state(state);
236238

0 commit comments

Comments
 (0)