Skip to content

Commit a52854e

Browse files
authored
Merge branch 'main' into issue-16453-nullary-udaf
2 parents a83f8e9 + efc7b3e commit a52854e

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

benchmarks/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,15 @@ Test performance of end-to-end sort SQL queries. (While the `Sort` benchmark foc
558558

559559
Sort integration benchmark runs whole table sort queries on TPCH `lineitem` table, with different characteristics. For example, different number of sort keys, different sort key cardinality, different number of payload columns, etc.
560560

561-
If the TPCH tables have been converted as sorted on their first column (see [Sorted Conversion](#sorted-conversion)), you can use the `--sorted` flag to indicate that the input data is pre-sorted, allowing DataFusion to leverage that order during query execution.
561+
The `--sorted` flag does not sort or rewrite the input files. It declares that the `lineitem` Parquet input is already sorted ascending by its first column (`l_orderkey`). DataFusion can then leverage that ordering during query execution.
562+
563+
To generate the expected TPC-H SF=1 Parquet input for this benchmark, run:
564+
565+
```bash
566+
./bench.sh data tpch
567+
```
568+
569+
For the `lineitem` table used by `sort-tpch`, this uses `tpchgen-cli` to generate Parquet data that is already ordered by `l_orderkey`. If you use a different input directory, only pass `--sorted` when the `lineitem` files already have that ordering.
562570

563571
Additionally, an optional `--limit` flag is available for the sort benchmark. When specified, this flag appends a `LIMIT n` clause to the SQL query, effectively converting the query into a TopK query. Combining the `--sorted` and `--limit` options enables benchmarking of TopK queries on pre-sorted inputs.
564572

@@ -578,7 +586,7 @@ See [`sort_tpch.rs`](src/sort_tpch.rs) for more details.
578586
cargo run --release --bin dfbench -- sort-tpch -p './datafusion/benchmarks/data/tpch_sf1' -o '/tmp/sort_tpch.json' --query 2
579587
```
580588

581-
3. Run all queries as TopK queries on presorted data:
589+
3. Run all queries as TopK queries on already sorted data:
582590

583591
```bash
584592
cargo run --release --bin dfbench -- sort-tpch --sorted --limit 10 -p './datafusion/benchmarks/data/tpch_sf1' -o '/tmp/sort_tpch.json'
@@ -598,6 +606,14 @@ In addition, topk_tpch is available from the bench.sh script:
598606
./bench.sh run topk_tpch
599607
```
600608

609+
To benchmark TopK queries on TPC-H `lineitem` input ordered by `l_orderkey`, use:
610+
611+
```bash
612+
./bench.sh run topk_sorted_tpch
613+
```
614+
615+
This runs `dfbench sort-tpch --sorted --limit 100` through the benchmark script, using `--sorted` to declare the existing `l_orderkey` ordering.
616+
601617
## IMDB
602618

603619
Run Join Order Benchmark (JOB) on IMDB dataset.

benchmarks/bench.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ tpcds: TPCDS inspired benchmark on Scale Factor (SF) 1 (~1GB),
9999
sort_tpch: Benchmark of sorting speed for end-to-end sort queries on TPC-H dataset (SF=1)
100100
sort_tpch10: Benchmark of sorting speed for end-to-end sort queries on TPC-H dataset (SF=10)
101101
topk_tpch: Benchmark of top-k (sorting with limit) queries on TPC-H dataset (SF=1)
102+
topk_sorted_tpch: Benchmark of top-k queries on TPC-H lineitem ordered by l_orderkey (SF=1)
102103
push_down_topk: Benchmark of ORDER BY ... LIMIT over outer joins on TPC-H dataset (SF=1) — exercises pushing TopK through a join
103104
external_aggr: External aggregation benchmark on TPC-H dataset (SF=1)
104105
wide_schema: Small-projection queries on a wide synthetic dataset (1024 cols × 256 files) — measures per-file metadata overhead
@@ -346,7 +347,7 @@ main() {
346347
# same data as for tpch10
347348
data_tpch "10" "parquet"
348349
;;
349-
topk_tpch)
350+
topk_tpch|topk_sorted_tpch)
350351
# same data as for tpch
351352
data_tpch "1" "parquet"
352353
;;
@@ -577,6 +578,9 @@ main() {
577578
topk_tpch)
578579
run_topk_tpch
579580
;;
581+
topk_sorted_tpch)
582+
run_topk_sorted_tpch
583+
;;
580584
push_down_topk)
581585
run_push_down_topk
582586
;;
@@ -1506,6 +1510,16 @@ run_topk_tpch() {
15061510
$CARGO_COMMAND --bin dfbench -- sort-tpch --iterations 5 --path "${TPCH_DIR}" -o "${RESULTS_FILE}" --limit 100 ${QUERY_ARG} ${LATENCY_ARG}
15071511
}
15081512

1513+
# Runs the sorted sort tpch integration benchmark with limit 100 (topk)
1514+
run_topk_sorted_tpch() {
1515+
TPCH_DIR="${DATA_DIR}/tpch_sf1"
1516+
RESULTS_FILE="${RESULTS_DIR}/run_topk_sorted_tpch.json"
1517+
echo "RESULTS_FILE: ${RESULTS_FILE}"
1518+
echo "Running sorted topk tpch benchmark..."
1519+
1520+
$CARGO_COMMAND --bin dfbench -- sort-tpch --iterations 5 --path "${TPCH_DIR}" -o "${RESULTS_FILE}" --sorted --limit 100 ${QUERY_ARG} ${LATENCY_ARG}
1521+
}
1522+
15091523
# Runs the nlj benchmark
15101524
run_nlj() {
15111525
RESULTS_FILE="${RESULTS_DIR}/nlj.json"

benchmarks/src/sort_tpch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub struct RunOpt {
6464
#[arg(short = 'm', long = "mem-table")]
6565
mem_table: bool,
6666

67-
/// Mark the first column of each table as sorted in ascending order.
68-
/// The tables should have been created with the `--sort` option for this to have any effect.
67+
/// Declare that the first column of the input table is already sorted in ascending order.
68+
/// This flag only attaches ordering metadata; it does not sort the input files.
6969
#[arg(short = 't', long = "sorted")]
7070
sorted: bool,
7171

datafusion/common/src/hash_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,7 @@ mod tests {
18551855
// Tests actual values of hashes, which are different if forcing collisions
18561856
#[cfg(not(feature = "force_hash_collisions"))]
18571857
#[test]
1858+
#[cfg(not(feature = "force_hash_collisions"))]
18581859
fn test_create_hashes_with_quality_hash_state() {
18591860
let int_array: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4]));
18601861
let str_array: ArrayRef = Arc::new(StringArray::from(vec!["a", "b", "c", "d"]));

datafusion/common/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ mod tests {
14861486
buffer::NullBuffer,
14871487
datatypes::Int32Type,
14881488
};
1489+
#[cfg(feature = "sql")]
14891490
use sqlparser::ast::Ident;
14901491

14911492
#[test]

0 commit comments

Comments
 (0)