-
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
Add config option for coalesce_batches physical optimization rule, make optional #2791
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
use arrow::datatypes::DataType; | ||
use datafusion_common::ScalarValue; | ||
use itertools::Itertools; | ||
use std::collections::HashMap; | ||
|
||
/// Configuration option "datafusion.optimizer.filter_null_join_keys" | ||
|
@@ -27,6 +28,13 @@ pub const OPT_FILTER_NULL_JOIN_KEYS: &str = "datafusion.optimizer.filter_null_jo | |
/// Configuration option "datafusion.execution.batch_size" | ||
pub const OPT_BATCH_SIZE: &str = "datafusion.execution.batch_size"; | ||
|
||
/// Configuration option "datafusion.execution.coalesce_batches" | ||
pub const OPT_COALESCE_BATCHES: &str = "datafusion.execution.coalesce_batches"; | ||
|
||
/// Configuration option "datafusion.execution.coalesce_target_batch_size" | ||
pub const OPT_COALESCE_TARGET_BATCH_SIZE: &str = | ||
"datafusion.execution.coalesce_target_batch_size"; | ||
|
||
/// Definition of a configuration option | ||
pub struct ConfigDefinition { | ||
/// key used to identifier this configuration option | ||
|
@@ -115,6 +123,21 @@ impl BuiltInConfigs { | |
buffer-in-memory batches since creating tiny batches would results in too much metadata \ | ||
memory consumption.", | ||
8192, | ||
), | ||
ConfigDefinition::new_bool( | ||
OPT_COALESCE_BATCHES, | ||
format!("When set to true, record batches will be examined between each operator and \ | ||
small batches will be coalesced into larger batches. This is helpful when there \ | ||
are highly selective filters or joins that could produce tiny output batches. The \ | ||
target batch size is determined by the configuration setting \ | ||
'{}'.", OPT_COALESCE_TARGET_BATCH_SIZE), | ||
false, | ||
), | ||
ConfigDefinition::new_u64( | ||
OPT_COALESCE_TARGET_BATCH_SIZE, | ||
format!("Target batch size when coalescing batches. Uses in conjunction with the \ | ||
configuration setting '{}}'.", OPT_COALESCE_BATCHES), | ||
4096, | ||
)], | ||
} | ||
} | ||
|
@@ -124,7 +147,11 @@ impl BuiltInConfigs { | |
let configs = Self::new(); | ||
let mut docs = "| key | type | default | description |\n".to_string(); | ||
docs += "|-----|------|---------|-------------|\n"; | ||
for config in configs.config_definitions { | ||
for config in configs | ||
.config_definitions | ||
.iter() | ||
.sorted_by_key(|c| c.key.clone()) | ||
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. Make the output deterministic |
||
{ | ||
docs += &format!( | ||
"| {} | {} | {} | {} |\n", | ||
config.key, config.data_type, config.default_value, config.description | ||
|
@@ -206,10 +233,6 @@ mod test { | |
#[test] | ||
fn docs() { | ||
let docs = BuiltInConfigs::generate_config_markdown(); | ||
// uncomment this println to see the docs so they can be copy-and-pasted to | ||
// docs/source/user-guide/configs.md until this task is automated | ||
// in https://github.com/apache/arrow-datafusion/issues/2770 | ||
//println!("{}", docs); | ||
let mut lines = docs.lines(); | ||
assert_eq!( | ||
lines.next().unwrap(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,10 @@ use crate::physical_optimizer::coalesce_batches::CoalesceBatches; | |
use crate::physical_optimizer::merge_exec::AddCoalescePartitionsExec; | ||
use crate::physical_optimizer::repartition::Repartition; | ||
|
||
use crate::config::{ConfigOptions, OPT_BATCH_SIZE, OPT_FILTER_NULL_JOIN_KEYS}; | ||
use crate::config::{ | ||
ConfigOptions, OPT_BATCH_SIZE, OPT_COALESCE_BATCHES, OPT_COALESCE_TARGET_BATCH_SIZE, | ||
OPT_FILTER_NULL_JOIN_KEYS, | ||
}; | ||
use crate::execution::runtime_env::{RuntimeConfig, RuntimeEnv}; | ||
use crate::logical_plan::plan::Explain; | ||
use crate::physical_plan::file_format::{plan_to_csv, plan_to_json, plan_to_parquet}; | ||
|
@@ -1247,16 +1250,26 @@ impl SessionState { | |
rules.push(Arc::new(LimitPushDown::new())); | ||
rules.push(Arc::new(SingleDistinctToGroupBy::new())); | ||
|
||
let mut physical_optimizers: Vec<Arc<dyn PhysicalOptimizerRule + Sync + Send>> = vec![ | ||
Arc::new(AggregateStatistics::new()), | ||
Arc::new(HashBuildProbeOrder::new()), | ||
]; | ||
if config.config_options.get_bool(OPT_COALESCE_BATCHES) { | ||
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. I wonder if it would be helpful to add a test to ensure the option to disable coalsce'ing batches doesn't get broken in the future 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. Sounds good. I will get to this in the next day or two. 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. I have added tests for disabling the optimizer rule and also for setting a custom batch size. |
||
physical_optimizers.push(Arc::new(CoalesceBatches::new( | ||
config | ||
.config_options | ||
.get_u64(OPT_COALESCE_TARGET_BATCH_SIZE) | ||
.try_into() | ||
.unwrap(), | ||
))); | ||
} | ||
physical_optimizers.push(Arc::new(Repartition::new())); | ||
physical_optimizers.push(Arc::new(AddCoalescePartitionsExec::new())); | ||
|
||
SessionState { | ||
session_id, | ||
optimizer: Optimizer::new(rules), | ||
physical_optimizers: vec![ | ||
Arc::new(AggregateStatistics::new()), | ||
Arc::new(HashBuildProbeOrder::new()), | ||
Arc::new(CoalesceBatches::new()), | ||
Arc::new(Repartition::new()), | ||
Arc::new(AddCoalescePartitionsExec::new()), | ||
], | ||
physical_optimizers, | ||
query_planner: Arc::new(DefaultQueryPlanner {}), | ||
catalog_list, | ||
scalar_functions: HashMap::new(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ pub mod optimizer; | |
pub mod pruning; | ||
pub mod repartition; | ||
mod utils; | ||
|
||
pub use optimizer::PhysicalOptimizerRule; |
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.
I really like how this new option framework is coming together ❤️