Skip to content

Apache DataFusion SQL Query Engine

refactor: consolidate benchmark options and environment settings (#26768)

mattsu7ee8f526da59
diff --git a/benchmarks/README.md b/benchmarks/README.md
index 151f1e7df5..bceb33dc02 100644
--- a/benchmarks/README.md
+++ b/benchmarks/README.md
@@ -127,7 +127,7 @@ The benchmark runs with `prefer_hash_join == true` by default, which enforces HA
To run TPCH benchmarks with join other than HASH:
```shell
-PREFER_HASH_JOIN=false ./bench.sh run tpch
+DATAFUSION_OPTIMIZER_PREFER_HASH_JOIN=false ./bench.sh run tpch
```
### Configure with environment variables
diff --git a/benchmarks/bench.sh b/benchmarks/bench.sh
index 65ea19651e..156e33f507 100755
--- a/benchmarks/bench.sh
+++ b/benchmarks/bench.sh
@@ -42,7 +42,6 @@ DATAFUSION_DIR=${DATAFUSION_DIR:-$SCRIPT_DIR/..}
DATA_DIR=${DATA_DIR:-$SCRIPT_DIR/data}
CARGO_COMMAND=${CARGO_COMMAND:-"cargo run --release"}
SQL_CARGO_COMMAND=${SQL_CARGO_COMMAND:-"cargo bench --bench sql"}
-PREFER_HASH_JOIN=${PREFER_HASH_JOIN:-true}
SIMULATE_LATENCY=${SIMULATE_LATENCY:-false}
# Build latency arg based on SIMULATE_LATENCY setting
@@ -187,7 +186,6 @@ DATA_DIR directory to store datasets
CARGO_COMMAND command that runs the benchmark binary
DATAFUSION_DIR directory to use (default $DATAFUSION_DIR)
RESULTS_NAME folder where the benchmark files are stored
-PREFER_HASH_JOIN Prefer hash join algorithm (default true)
SIMULATE_LATENCY Serve local files as if they were remote object storage: per-request
latency, per-connection bandwidth and paginated LIST (default false)
DATAFUSION_* Set the given datafusion configuration
@@ -237,7 +235,6 @@ main() {
echo "BENCHMARK: ${BENCHMARK}"
echo "DATA_DIR: ${DATA_DIR}"
echo "CARGO_COMMAND: ${CARGO_COMMAND}"
- echo "PREFER_HASH_JOIN: ${PREFER_HASH_JOIN}"
echo "***************************"
case "$BENCHMARK" in
all)
@@ -480,7 +477,6 @@ main() {
echo "DATA_DIR: ${DATA_DIR}"
echo "RESULTS_DIR: ${RESULTS_DIR}"
echo "CARGO_COMMAND: ${CARGO_COMMAND}"
- echo "PREFER_HASH_JOIN: ${PREFER_HASH_JOIN}"
echo "SIMULATE_LATENCY: ${SIMULATE_LATENCY}"
echo "***************************"
@@ -846,7 +842,6 @@ run_tpch() {
BENCH_RESULTS_FILE="$(sql_results_file tpch_sf${SCALE_FACTOR}_${FORMAT})" \
BENCH_SIZE="${SCALE_FACTOR}" \
DATA_DIR="${DATA_DIR}" \
- PREFER_HASH_JOIN="${PREFER_HASH_JOIN}" \
TPCH_FILE_TYPE="${FORMAT}" \
SIMULATE_LATENCY="${SIMULATE_LATENCY}" \
${QUERY:+BENCH_QUERY="${QUERY}"} \
@@ -1058,7 +1053,6 @@ run_tpch_mem() {
BENCH_SIZE="${SCALE_FACTOR}" \
DATA_DIR="${DATA_DIR}" \
TPCH_FILE_TYPE="mem" \
- PREFER_HASH_JOIN="${PREFER_HASH_JOIN}" \
SIMULATE_LATENCY="${SIMULATE_LATENCY}" \
${QUERY:+BENCH_QUERY="${QUERY}"} \
bash -c "$SQL_CARGO_COMMAND"
@@ -1081,7 +1075,7 @@ run_tpcds() {
echo "RESULTS_FILE: ${RESULTS_FILE}"
echo "Running tpcds benchmark..."
- debug_run $CARGO_COMMAND --bin dfbench -- tpcds --iterations 5 --path "${TPCDS_DIR}" --query_path "../datafusion/core/tests/tpc-ds" --prefer_hash_join "${PREFER_HASH_JOIN}" -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
+ debug_run $CARGO_COMMAND --bin dfbench -- tpcds --iterations 5 --path "${TPCDS_DIR}" --query_path "../datafusion/core/tests/tpc-ds" -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
}
# Runs the compile profile benchmark helper
@@ -1298,7 +1292,7 @@ run_imdb() {
RESULTS_FILE="${RESULTS_DIR}/imdb.json"
echo "RESULTS_FILE: ${RESULTS_FILE}"
echo "Running imdb benchmark..."
- debug_run $CARGO_COMMAND --bin imdb -- benchmark datafusion --iterations 5 --path "${IMDB_DIR}" --prefer_hash_join "${PREFER_HASH_JOIN}" --format parquet -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
+ debug_run $CARGO_COMMAND --bin imdb -- benchmark datafusion --iterations 5 --path "${IMDB_DIR}" --format parquet -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
}
data_h2o() {
diff --git a/benchmarks/sql_benchmarks/README.md b/benchmarks/sql_benchmarks/README.md
index 55a1cc5898..97a258b423 100644
--- a/benchmarks/sql_benchmarks/README.md
+++ b/benchmarks/sql_benchmarks/README.md
@@ -141,6 +141,31 @@ compatibility with benchmark files and direct Criterion runs. Direct
`cargo bench --bench sql` invocations cannot accept custom arguments, so they
still use environment variables.
+DataFusion session settings are read through `SessionConfig::from_env()` in both
+CLI and direct Criterion runs. Use the standard `DATAFUSION_*` environment variables:
+
+| Setting | Environment variable |
+| ------------------------------ | --------------------------------------------------- |
+| Parallel partitions | `DATAFUSION_EXECUTION_TARGET_PARTITIONS` |
+| Batch size | `DATAFUSION_EXECUTION_BATCH_SIZE` |
+| Sort spill reservation (bytes) | `DATAFUSION_EXECUTION_SORT_SPILL_RESERVATION_BYTES` |
+| Prefer hash joins | `DATAFUSION_OPTIMIZER_PREFER_HASH_JOIN` |
+| Enable Piecewise Merge Join | `DATAFUSION_OPTIMIZER_ENABLE_PIECEWISE_MERGE_JOIN` |
+| Hash join buffering capacity | `DATAFUSION_EXECUTION_HASH_JOIN_BUFFERING_CAPACITY` |
+| Collect statistics | `DATAFUSION_EXECUTION_COLLECT_STATISTICS` |
+
+Explicit CLI settings override environment settings; otherwise DataFusion's defaults
+apply. The old `PARTITIONS`, `BATCH_SIZE`, `SORT_SPILL_RESERVATION_BYTES`,
+`PREFER_HASH_JOIN`, and `HASH_JOIN_BUFFERING_CAPACITY` environment variables are
+no longer used. For example:
+
+```shell
+DATAFUSION_EXECUTION_TARGET_PARTITIONS=2 DATAFUSION_OPTIMIZER_PREFER_HASH_JOIN=false cargo bench --bench sql
+```
+
+Memory limits and pool types configure `RuntimeEnv` separately. `MEMORY_LIMIT`
+(or `--memory-limit`) takes precedence over `DATAFUSION_RUNTIME_MEMORY_LIMIT`.
+
The SQL benchmarking tool uses the following environment variables:
| Environment Variable | Description |
@@ -171,8 +196,6 @@ Some benchmarks use custom environment variables as outlined below:
| H2O_FILE_TYPE | Used in the h2o benchmark to specify which file type to query against. The valid options are `csv` and `parquet` | `csv` |
| CLICKBENCH_TYPE | The type of partitioning for the clickbench benchmark. Valid options are `single` and `partitioned` | `single` |
| H2O_BENCH_SIZE | Used in the h2o benchmark. The valid options are `small`, `medium` and `big` | `small` |
-| PREFER_HASH_JOIN | Control datafusion's config option `datafusion.optimizer.prefer_hash_join` | true |
-| HASH_JOIN_BUFFERING_CAPACITY | Control datafusion's config option `datafusion.execution.hash_join_buffering_capacity` | 0 |
| BENCH_SORTED | Used in the sort_tpch benchmark to indicate whether the lineitem table should be sorted. | false |
| SORTED_BY | Used in the clickbench_sorted benchmark to indicate the column to sort by. | `EventTime` |
| SORTED_ORDER | Used in the clickbench_sorted benchmark to indicate the sort order of the column. | `ASC` |
@@ -422,7 +445,7 @@ QUERY_NUMBER_PADDED=01
The echo directive allows for echoing a string to stdout during the execution of the benchmark and may be useful for
debugging.<br/><br/>Example:<br/>
<blockquote>
-echo The value for batch size is ${BATCH_SIZE:-8192}
+echo The value for batch size is ${DATAFUSION_EXECUTION_BATCH_SIZE:-8192}
</blockquote>
</td>
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q01.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q01.benchmark
index d490927df3..47e56f00a3 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q01.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q01.benchmark
@@ -2,8 +2,6 @@ name Q01
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q02.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q02.benchmark
index 6f365248b4..125cec11c0 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q02.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q02.benchmark
@@ -2,8 +2,6 @@ name Q02
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q03.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q03.benchmark
index cb16b10c2b..a6057f1761 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q03.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q03.benchmark
@@ -2,8 +2,6 @@ name Q03
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q04.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q04.benchmark
index f2e6f9a558..7fc8705f31 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q04.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q04.benchmark
@@ -2,8 +2,6 @@ name Q04
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q05.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q05.benchmark
index 9b5fbda63b..f33ec7e8ce 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q05.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q05.benchmark
@@ -2,8 +2,6 @@ name Q05
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q06.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q06.benchmark
index 761875cbf3..8ca0492823 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q06.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q06.benchmark
@@ -2,8 +2,6 @@ name Q06
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q07.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q07.benchmark
index 30c4c520de..25b4c519d7 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q07.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q07.benchmark
@@ -2,8 +2,6 @@ name Q07
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q08.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q08.benchmark
index 86caded4b7..4853908d22 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q08.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q08.benchmark
@@ -2,8 +2,6 @@ name Q08
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q09.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q09.benchmark
index 3302cf6f0b..8b2bf41bba 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q09.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q09.benchmark
@@ -2,8 +2,6 @@ name Q09
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q10.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q10.benchmark
index 4ef08e3fd2..73d9276eba 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q10.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q10.benchmark
@@ -2,8 +2,6 @@ name Q10
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q11.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q11.benchmark
index 833799a39d..8a326212c8 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q11.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q11.benchmark
@@ -2,8 +2,6 @@ name Q11
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q12.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q12.benchmark
index 37aee848c9..3aacca4fe1 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q12.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q12.benchmark
@@ -2,8 +2,6 @@ name Q12
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q13.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q13.benchmark
index dfb09853d0..9390b8fa6f 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q13.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q13.benchmark
@@ -2,8 +2,6 @@ name Q13
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q14.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q14.benchmark
index b48d95043f..0efb695ed3 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q14.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q14.benchmark
@@ -2,8 +2,6 @@ name Q14
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q15.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q15.benchmark
index 0f50fc499d..4b25709419 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q15.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q15.benchmark
@@ -2,8 +2,6 @@ name Q15
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q16.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q16.benchmark
index 3fa6c68e29..a9b3690869 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q16.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q16.benchmark
@@ -2,8 +2,6 @@ name Q16
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q17.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q17.benchmark
index a31c837d1e..12620dff58 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q17.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q17.benchmark
@@ -2,8 +2,6 @@ name Q17
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q18.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q18.benchmark
index 149b0efd01..69718227c1 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q18.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q18.benchmark
@@ -2,8 +2,6 @@ name Q18
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q19.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q19.benchmark
index f93ad6cb73..cdc544c1e8 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q19.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q19.benchmark
@@ -2,8 +2,6 @@ name Q19
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q20.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q20.benchmark
index 123386055b..b02420d0fc 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q20.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q20.benchmark
@@ -2,8 +2,6 @@ name Q20
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q21.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q21.benchmark
index 24d754a4cb..f714c17260 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q21.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q21.benchmark
@@ -2,8 +2,6 @@ name Q21
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/benchmarks/q22.benchmark b/benchmarks/sql_benchmarks/tpch/benchmarks/q22.benchmark
index 7ef6a78496..c39173fbfc 100644
--- a/benchmarks/sql_benchmarks/tpch/benchmarks/q22.benchmark
+++ b/benchmarks/sql_benchmarks/tpch/benchmarks/q22.benchmark
@@ -2,8 +2,6 @@ name Q22
group tpch
subgroup sf${BENCH_SIZE:-1}
-init sql_benchmarks/tpch/init/set_config.sql
-
load sql_benchmarks/tpch/init/load_${TPCH_FILE_TYPE:-parquet}.sql
assert I
diff --git a/benchmarks/sql_benchmarks/tpch/init/set_config.sql b/benchmarks/sql_benchmarks/tpch/init/set_config.sql
deleted file mode 100644
index 00457e2bca..0000000000
--- a/benchmarks/sql_benchmarks/tpch/init/set_config.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-set datafusion.optimizer.prefer_hash_join=${PREFER_HASH_JOIN:-true};
-
-set datafusion.execution.hash_join_buffering_capacity=${HASH_JOIN_BUFFERING_CAPACITY:-0};
diff --git a/benchmarks/src/imdb/run.rs b/benchmarks/src/imdb/run.rs
index b6c998c383..d6fedf1265 100644
--- a/benchmarks/src/imdb/run.rs
+++ b/benchmarks/src/imdb/run.rs
@@ -9,7 +9,7 @@ use super::{
IMDB_QUERY_END_ID, IMDB_QUERY_START_ID, IMDB_TABLES, get_imdb_table_schema,
get_query_sql,
};
-use crate::util::{BenchmarkRun, CommonOpt, QueryResult, print_memory_stats};
+use crate::util::{BenchmarkRun, CommonOpt, QueryOpt, QueryResult, print_memory_stats};
use arrow::record_batch::RecordBatch;
use arrow::util::pretty::{self, pretty_format_batches};
@@ -31,9 +31,6 @@ use datafusion_common::{DEFAULT_CSV_EXTENSION, DEFAULT_PARQUET_EXTENSION};
use clap::Args;
use log::info;
-// hack to avoid `default_value is meaningless for bool` errors
-type BoolDefaultTrue = bool;
-
/// Run the imdb benchmark (a.k.a. JOB).
///
/// This benchmarks is derived from the [Join Order Benchmark / JOB] proposed in paper [How Good Are Query Optimizers, Really?][1].
@@ -71,18 +68,9 @@ pub struct RunOpt {
#[arg(short = 'o', long = "output")]
output_path: Option<PathBuf>,
- /// Whether to disable collection of statistics (and cost based optimizations) or not.
- #[arg(short = 'S', long = "disable-statistics")]
- disable_statistics: bool,
-
- /// If true then hash join used, if false then sort merge join
- /// True by default.
- #[arg(short = 'j', long = "prefer_hash_join", default_value = "true")]
- prefer_hash_join: BoolDefaultTrue,
-
- /// How many bytes to buffer on the probe side of hash joins.
- #[arg(long, default_value = "0")]
- hash_join_buffering_capacity: usize,
+ /// Session configuration overrides
+ #[command(flatten)]
+ query_options: QueryOpt,
}
fn map_query_id_to_str(query_id: usize) -> &'static str {
@@ -298,13 +286,7 @@ impl RunOpt {
query_id: usize,
benchmark_run: &mut BenchmarkRun,
) -> Result<Vec<QueryResult>> {
- let mut config = self
- .common
- .config()?
- .with_collect_statistics(!self.disable_statistics);
- config.options_mut().optimizer.prefer_hash_join = self.prefer_hash_join;
- config.options_mut().execution.hash_join_buffering_capacity =
- self.hash_join_buffering_capacity;
+ let config = self.query_options.config(&self.common)?;
let rt = self.common.build_runtime()?;
let ctx = SessionContext::new_with_config_rt(config, rt);
benchmark_run.set_memory_pool(&ctx.runtime_env().memory_pool);
@@ -525,9 +507,7 @@ mod tests {
file_format: "parquet".to_string(),
mem_table: false,
output_path: None,
- disable_statistics: false,
- prefer_hash_join: true,
- hash_join_buffering_capacity: 0,
+ query_options: QueryOpt::default(),
};
opt.register_tables(&ctx).await?;
let queries = get_query_sql(map_query_id_to_str(query))?;
@@ -563,9 +543,7 @@ mod tests {
file_format: "parquet".to_string(),
mem_table: false,
output_path: None,
- disable_statistics: false,
- prefer_hash_join: true,
- hash_join_buffering_capacity: 0,
+ query_options: QueryOpt::default(),
};
opt.register_tables(&ctx).await?;
let queries = get_query_sql(map_query_id_to_str(query))?;
diff --git a/benchmarks/src/sql_benchmark_runner.rs b/benchmarks/src/sql_benchmark_runner.rs
index d3caa54335..f167ba010a 100644
--- a/benchmarks/src/sql_benchmark_runner.rs
+++ b/benchmarks/src/sql_benchmark_runner.rs
@@ -812,6 +812,35 @@ mod tests {
}
}
+ #[tokio::test]
+ async fn tpch_init_preserves_session_settings() {
+ use crate::sql_benchmark::QueryDirective;
+ use datafusion::prelude::SessionConfig;
+
+ let mut config = SessionConfig::new();
+ config.options_mut().optimizer.prefer_hash_join = false;
+ config.options_mut().execution.hash_join_buffering_capacity = 4096;
+ let ctx = SessionContext::new_with_config(config);
+ let directory = default_sql_benchmark_directory();
+ // Exercise the suite's real init SQL without loading the TPC-H dataset.
+ for entry in fs::read_dir(directory.join("tpch/benchmarks")).unwrap() {
+ let benchmark = SqlBenchmark::new(&ctx, entry.unwrap().path(), &directory)
+ .await
+ .unwrap();
+ if let Some(queries) = benchmark.queries().get(&QueryDirective::Init) {
+ for query in queries {
+ ctx.sql(query).await.unwrap().collect().await.unwrap();
+ }
+ }
+ }
+ let config = ctx.copied_config();
+ assert!(!config.options().optimizer.prefer_hash_join);
+ assert_eq!(
+ config.options().execution.hash_join_buffering_capacity,
+ 4096
+ );
+ }
+
#[tokio::test]
async fn sql_memory_limit_keeps_the_peak_recorder() {
// The harness installs a recorder for its own limit; the SQL limit
diff --git a/benchmarks/src/tpcds/run.rs b/benchmarks/src/tpcds/run.rs
index 409f9afb74..0e719b8e13 100644
--- a/benchmarks/src/tpcds/run.rs
+++ b/benchmarks/src/tpcds/run.rs
@@ -6,7 +6,7 @@ use std::fs;
use std::path::PathBuf;
use std::sync::Arc;
-use crate::util::{BenchmarkRun, CommonOpt, QueryResult, print_memory_stats};
+use crate::util::{BenchmarkRun, CommonOpt, QueryOpt, QueryResult, print_memory_stats};
use arrow::datatypes::Schema;
use arrow::record_batch::RecordBatch;
@@ -27,8 +27,6 @@ use datafusion_common::{Constraint, Constraints, DEFAULT_PARQUET_EXTENSION, plan
use clap::Args;
use log::info;
-// hack to avoid `default_value is meaningless for bool` errors
-type BoolDefaultTrue = bool;
pub const TPCDS_QUERY_START_ID: usize = 1;
pub const TPCDS_QUERY_END_ID: usize = 99;
@@ -165,32 +163,14 @@ pub struct RunOpt {
#[arg(short = 'o', long = "output")]
output_path: Option<PathBuf>,
- /// Whether to disable collection of statistics (and cost based optimizations) or not.
- #[arg(short = 'S', long = "disable-statistics")]
- disable_statistics: bool,
-
- /// If true then hash join used, if false then sort merge join
- /// True by default.
- #[arg(short = 'j', long = "prefer_hash_join", default_value = "true")]
- prefer_hash_join: BoolDefaultTrue,
-
- /// If true then Piecewise Merge Join can be used, if false then it will opt for Nested Loop Join
- /// False by default.
- #[arg(
- short = 'w',
- long = "enable_piecewise_merge_join",
- default_value = "false"
- )]
- enable_piecewise_merge_join: BoolDefaultTrue,
+ /// Session configuration overrides
+ #[command(flatten)]
+ query_options: QueryOpt,
/// Mark the first column of each table as sorted in ascending order.
/// The tables should have been created with the `--sort` option for this to have any effect.
#[arg(short = 't', long = "sorted")]
sorted: bool,
-
- /// How many bytes to buffer on the probe side of hash joins.
- #[arg(long, default_value = "0")]
- hash_join_buffering_capacity: usize,
}
impl RunOpt {
@@ -202,15 +182,7 @@ impl RunOpt {
};
let mut benchmark_run = BenchmarkRun::new();
- let mut config = self
- .common
- .config()?
- .with_collect_statistics(!self.disable_statistics);
- config.options_mut().optimizer.prefer_hash_join = self.prefer_hash_join;
- config.options_mut().optimizer.enable_piecewise_merge_join =
- self.enable_piecewise_merge_join;
- config.options_mut().execution.hash_join_buffering_capacity =
- self.hash_join_buffering_capacity;
+ let config = self.query_options.config(&self.common)?;
let rt = self.common.build_runtime()?;
let ctx = SessionContext::new_with_config_rt(config, rt);
benchmark_run.set_memory_pool(&ctx.runtime_env().memory_pool);
diff --git a/benchmarks/src/tpch/run.rs b/benchmarks/src/tpch/run.rs
index 05f7d04cdc..dbd716014e 100644
--- a/benchmarks/src/tpch/run.rs
+++ b/benchmarks/src/tpch/run.rs
@@ -9,7 +9,7 @@ use super::{
TPCH_QUERY_END_ID, TPCH_QUERY_START_ID, TPCH_TABLES, get_query_sql_for_scale_factor,
get_tbl_tpch_table_schema, get_tpch_table_schema, table_constraints,
};
-use crate::util::{BenchmarkRun, CommonOpt, QueryResult, print_memory_stats};
+use crate::util::{BenchmarkRun, CommonOpt, QueryOpt, QueryResult, print_memory_stats};
use arrow::record_batch::RecordBatch;
use arrow::util::pretty::{self, pretty_format_batches};
@@ -32,9 +32,6 @@ use datafusion_common::{DEFAULT_CSV_EXTENSION, DEFAULT_PARQUET_EXTENSION};
use clap::Args;
use log::info;
-// hack to avoid `default_value is meaningless for bool` errors
-type BoolDefaultTrue = bool;
-
/// Run the tpch benchmark.
///
/// This benchmarks is derived from the [TPC-H][1] version
@@ -76,32 +73,14 @@ pub struct RunOpt {
#[arg(short = 'o', long = "output")]
output_path: Option<PathBuf>,
- /// Whether to disable collection of statistics (and cost based optimizations) or not.
- #[arg(short = 'S', long = "disable-statistics")]
- disable_statistics: bool,
-
- /// If true then hash join used, if false then sort merge join
- /// True by default.
- #[arg(short = 'j', long = "prefer_hash_join", default_value = "true")]
- prefer_hash_join: BoolDefaultTrue,
-
- /// If true then Piecewise Merge Join can be used, if false then it will opt for Nested Loop Join
- /// False by default.
- #[arg(
- short = 'w',
- long = "enable_piecewise_merge_join",
- default_value = "false"
- )]
- enable_piecewise_merge_join: BoolDefaultTrue,
+ /// Session configuration overrides
+ #[command(flatten)]
+ query_options: QueryOpt,
/// Mark the first column of each table as sorted in ascending order.
/// The tables should have been created with the `--sort` option for this to have any effect.
#[arg(short = 't', long = "sorted")]
sorted: bool,
-
- /// How many bytes to buffer on the probe side of hash joins.
- #[arg(long, default_value = "0")]
- hash_join_buffering_capacity: usize,
}
impl RunOpt {
@@ -113,15 +92,7 @@ impl RunOpt {
};
let mut benchmark_run = BenchmarkRun::new();
- let mut config = self
- .common
- .config()?
- .with_collect_statistics(!self.disable_statistics);
- config.options_mut().optimizer.prefer_hash_join = self.prefer_hash_join;
- config.options_mut().optimizer.enable_piecewise_merge_join =
- self.enable_piecewise_merge_join;
- config.options_mut().execution.hash_join_buffering_capacity =
- self.hash_join_buffering_capacity;
+ let config = self.query_options.config(&self.common)?;
let rt = self.common.build_runtime()?;
let ctx = SessionContext::new_with_config_rt(config, rt);
benchmark_run.set_memory_pool(&ctx.runtime_env().memory_pool);
@@ -471,11 +442,8 @@ mod tests {
file_format: "tbl".to_string(),
mem_table: false,
output_path: None,
- disable_statistics: false,
- prefer_hash_join: true,
- enable_piecewise_merge_join: false,
+ query_options: QueryOpt::default(),
sorted: false,
- hash_join_buffering_capacity: 0,
};
opt.register_tables(&ctx).await?;
let queries = crate::tpch::get_query_sql(query)?;
@@ -512,11 +480,8 @@ mod tests {
file_format: "tbl".to_string(),
mem_table: false,
output_path: None,
- disable_statistics: false,
- prefer_hash_join: true,
- enable_piecewise_merge_join: false,
+ query_options: QueryOpt::default(),
sorted: false,
- hash_join_buffering_capacity: 0,
};
opt.register_tables(&ctx).await?;
let queries = crate::tpch::get_query_sql(query)?;
diff --git a/benchmarks/src/util/mod.rs b/benchmarks/src/util/mod.rs
index e77ff30e6e..22b255c993 100644
--- a/benchmarks/src/util/mod.rs
+++ b/benchmarks/src/util/mod.rs
@@ -9,5 +9,5 @@ mod run;
pub mod simulated_object_store;
pub use memory::print_memory_stats;
-pub use options::CommonOpt;
+pub use options::{CommonOpt, QueryOpt};
pub use run::{BenchQuery, BenchmarkRun, QueryResult};
diff --git a/benchmarks/src/util/options.rs b/benchmarks/src/util/options.rs
index 95d1dd95c1..1d56d1cae9 100644
--- a/benchmarks/src/util/options.rs
+++ b/benchmarks/src/util/options.rs
@@ -33,11 +33,11 @@ pub struct CommonOpt {
pub iterations: usize,
/// Number of partitions to process in parallel. Defaults to number of available cores.
- #[arg(short = 'n', long = "partitions", env)]
+ #[arg(short = 'n', long = "partitions")]
pub partitions: Option<usize>,
/// Batch size when reading CSV or Parquet files
- #[arg(short = 's', long = "batch-size", env)]
+ #[arg(short = 's', long = "batch-size")]
pub batch_size: Option<usize>,
/// The memory pool type to use, should be one of "fair" or "greedy"
@@ -51,7 +51,7 @@ pub struct CommonOpt {
/// The amount of memory to reserve for sort spill operations. DataFusion's default value will be used
/// if not specified.
- #[arg(long = "sort-spill-reservation-bytes", value_parser = parse_capacity_limit, env)]
+ #[arg(long = "sort-spill-reservation-bytes", value_parser = parse_capacity_limit)]
pub sort_spill_reservation_bytes: Option<usize>,
/// Activate debug mode to see more details
@@ -66,6 +66,48 @@ pub struct CommonOpt {
pub simulate_latency: bool,
}
+/// Session configuration overrides shared by query benchmarks.
+///
+/// Only explicitly supplied CLI arguments override `SessionConfig::from_env()`.
+#[derive(Debug, Args, Clone, Default)]
+pub struct QueryOpt {
+ /// Disable collection of statistics (and cost based optimizations).
+ #[arg(short = 'S', long = "disable-statistics")]
+ disable_statistics: bool,
+
+ /// Prefer hash joins over sort merge joins.
+ #[arg(short = 'j', long = "prefer_hash_join")]
+ prefer_hash_join: Option<bool>,
+
+ /// Allow Piecewise Merge Join instead of Nested Loop Join.
+ #[arg(short = 'w', long = "enable_piecewise_merge_join")]
+ enable_piecewise_merge_join: Option<bool>,
+
+ /// How many bytes to buffer on the probe side of hash joins.
+ #[arg(long)]
+ hash_join_buffering_capacity: Option<usize>,
+}
+
+impl QueryOpt {
+ /// Read standard environment settings, then apply explicit CLI overrides.
+ pub fn config(&self, common: &CommonOpt) -> Result<SessionConfig> {
+ let mut config = common.config()?;
+ if self.disable_statistics {
+ config = config.with_collect_statistics(false);
+ }
+ if let Some(value) = self.prefer_hash_join {
+ config.options_mut().optimizer.prefer_hash_join = value;
+ }
+ if let Some(value) = self.enable_piecewise_merge_join {
+ config.options_mut().optimizer.enable_piecewise_merge_join = value;
+ }
+ if let Some(value) = self.hash_join_buffering_capacity {
+ config.options_mut().execution.hash_join_buffering_capacity = value;
+ }
+ Ok(config)
+ }
+}
+
impl CommonOpt {
/// Return an appropriately configured `SessionConfig`
pub fn config(&self) -> Result<SessionConfig> {
@@ -175,6 +217,125 @@ fn parse_capacity_limit(limit: &str) -> Result<usize, String> {
mod tests {
use super::*;
+ #[derive(clap::Parser)]
+ struct TestOptions {
+ #[command(flatten)]
+ common: CommonOpt,
+ #[command(flatten)]
+ query: QueryOpt,
+ }
+
+ #[test]
+ fn session_settings_from_env_and_cli() {
+ use clap::Parser;
+
+ const CHILD: &str = "DATAFUSION_BENCHMARK_SESSION_SETTINGS_TEST";
+ if let Ok(mode) = std::env::var(CHILD) {
+ let mut args = vec!["benchmark"];
+ if mode == "cli" {
+ args.extend([
+ "--partitions",
+ "3",
+ "--batch-size",
+ "512",
+ "--sort-spill-reservation-bytes",
+ "2M",
+ "--prefer_hash_join",
+ "true",
+ "--enable_piecewise_merge_join",
+ "false",
+ "--hash-join-buffering-capacity",
+ "0",
+ "--disable-statistics",
+ ]);
+ }
+ let options = TestOptions::try_parse_from(args).unwrap();
+ let config = options.query.config(&options.common).unwrap();
+ let settings = config.options();
+ let cli = mode == "cli";
+ assert_eq!(
+ settings.execution.target_partitions,
+ if cli { 3 } else { 2 }
+ );
+ assert_eq!(
+ settings.execution.batch_size.get(),
+ if cli { 512 } else { 256 }
+ );
+ assert_eq!(
+ settings.execution.sort_spill_reservation_bytes,
+ if cli { 2 * 1024 * 1024 } else { 1048576 }
+ );
+ assert_eq!(settings.optimizer.prefer_hash_join, cli);
+ assert_eq!(settings.optimizer.enable_piecewise_merge_join, !cli);
+ assert_eq!(
+ settings.execution.hash_join_buffering_capacity,
+ if cli { 0 } else { 4096 }
+ );
+ assert!(!settings.execution.collect_statistics);
+
+ // The SQL runner uses the same standard environment settings.
+ if !cli {
+ let ctx = crate::sql_benchmark_runner::make_ctx(&options.common).unwrap();
+ assert_eq!(ctx.copied_config().to_props(), config.to_props());
+ }
+ return;
+ }
+
+ // Isolate environment changes from parallel tests and inherited settings.
+ for mode in ["env", "cli"] {
+ let mut command =
+ std::process::Command::new(std::env::current_exe().unwrap());
+ for (key, _) in std::env::vars_os() {
+ if key.to_string_lossy().starts_with("DATAFUSION_") {
+ command.env_remove(key);
+ }
+ }
+ for key in [
+ "ITERATIONS",
+ "MEM_POOL_TYPE",
+ "MEMORY_LIMIT",
+ "DEBUG",
+ "SIMULATE_LATENCY",
+ ] {
+ command.env_remove(key);
+ }
+ let output = command
+ .args([
+ "--exact",
+ "util::options::tests::session_settings_from_env_and_cli",
+ "--nocapture",
+ ])
+ .env(CHILD, mode)
+ .env("DATAFUSION_EXECUTION_TARGET_PARTITIONS", "2")
+ .env("DATAFUSION_EXECUTION_BATCH_SIZE", "256")
+ .env(
+ "DATAFUSION_EXECUTION_SORT_SPILL_RESERVATION_BYTES",
+ "1048576",
+ )
+ .env("DATAFUSION_OPTIMIZER_PREFER_HASH_JOIN", "false")
+ .env("DATAFUSION_OPTIMIZER_ENABLE_PIECEWISE_MERGE_JOIN", "true")
+ .env("DATAFUSION_EXECUTION_HASH_JOIN_BUFFERING_CAPACITY", "4096")
+ .env(
+ "DATAFUSION_EXECUTION_COLLECT_STATISTICS",
+ if mode == "cli" { "true" } else { "false" },
+ )
+ // Obsolete aliases must not override the standard settings.
+ .env("PARTITIONS", "8")
+ .env("BATCH_SIZE", "1024")
+ .env("SORT_SPILL_RESERVATION_BYTES", "8M")
+ .env("PREFER_HASH_JOIN", "true")
+ .env("HASH_JOIN_BUFFERING_CAPACITY", "0")
+ .output()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "{mode} child failed:\n{}\n{}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+ }
+
#[test]
fn test_runtime_env_builder_reads_env_var() {
// Set the env var and verify runtime_env_builder picks it up