## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change This change to make a significant performance impact in the `TopK` operator, which is a commonly used operator. ## What changes are included in this PR? Instead of doing two operations on the inner heap (pop than push), we use `Binary::peek_mut`, which allows us to replace the heap item in-place and then sift it to its proper location in the heap. Some SLT results seem to change, the only explanation I can find for it is that pop/push vs the sift_down that `PeekMut` uses have some subtle differences that resolve ties in a different way, ending up with a slightly different result. On my macbook, running the `topk_aggregate` benchmark, most benchmarks are not changed significantly, aside from the following: ``` distinct 10000000 rows desc [no TopK] time: [554.69 ms 903.25 ms 1.3318 s] change: [−82.888% −69.587% −47.591%] (p = 0.00 < 0.05) Performance has improved. Found 17 outliers among 100 measurements (17.00%) 5 (5.00%) high mild 12 (12.00%) high severe Benchmarking distinct 10000000 rows asc [no TopK]: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 113.7s, or reduce sample count to 10. distinct 10000000 rows asc [no TopK] time: [405.87 ms 702.47 ms 1.0583 s] change: [−86.490% −75.215% −51.486%] (p = 0.00 < 0.05) Performance has improved. Found 17 outliers among 100 measurements (17.00%) 3 (3.00%) high mild 14 (14.00%) high severe distinct 10000000 rows desc [TopK] time: [6.8372 ms 6.9933 ms 7.1523 ms] change: [−0.5254% +2.2409% +5.0920%] (p = 0.13 > 0.05) No change in performance detected. Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high mild distinct 10000000 rows asc [TopK] time: [6.8731 ms 6.9952 ms 7.1226 ms] change: [+3.3252% +5.3824% +7.5131%] (p = 0.00 < 0.05) Performance has regressed. Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high mild ``` ## Are these changes tested? Existing test suite. ## Are there any user-facing changes? No API changes, seems like some ordering might change in queries that use the `TopK` operator, but in a way that seems correct.
Apache DataFusion
DataFusion is an extensible query engine written in Rust that uses Apache Arrow as its in-memory format.
This crate provides libraries and binaries for developers building fast and feature-rich database and analytic systems, customized for particular workloads. See use cases for examples. The following related subprojects target end users:
- DataFusion Python offers a Python interface for SQL and DataFrame queries.
- DataFusion Comet is an accelerator for Apache Spark based on DataFusion.
"Out of the box," DataFusion offers SQL and DataFrame APIs, excellent performance, built-in support for CSV, Parquet, JSON, and Avro, extensive customization, and a great community.
DataFusion features a full query planner, a columnar, streaming, multi-threaded, vectorized execution engine, and partitioned data sources. You can customize DataFusion at almost all points including additional data sources, query languages, functions, custom operators and more. See the Architecture section for more details.
Here are links to important resources:
- Project Site
- Installation
- Rust Getting Started
- Rust DataFrame API
- Rust API docs
- Rust Examples
- Python DataFrame API
- Architecture
What can you do with this crate?
DataFusion is great for building projects such as domain-specific query engines, new database platforms and data pipelines, query languages and more. It lets you start quickly from a fully working engine, and then customize those features specific to your needs. See the list of known users.
Contributing to DataFusion
Please see the contributor guide and communication pages for more information.
Crate features
This crate has several features which can be specified in your Cargo.toml.
Default features:
nested_expressions: functions for working with nested types such asarray_to_stringcompression: reading files compressed withxz2,bzip2,flate2, andzstdcrypto_expressions: cryptographic functions such asmd5andsha256datetime_expressions: date and time functions such asto_timestampencoding_expressions:encodeanddecodefunctionsparquet: support for reading the Apache Parquet formatsql: support for SQL parsing and planningregex_expressions: regular expression functions, such asregexp_matchunicode_expressions: include Unicode-aware functions such ascharacter_lengthunparser: enables support to reverse LogicalPlans back into SQLrecursive_protection: uses recursive for stack overflow protection.
Optional features:
avro: support for reading the Apache Avro formatbacktrace: include backtrace information in error messagesparquet_encryption: support for using Parquet Modular Encryptionserde: enable arrow-schema'sserdefeature
DataFusion API Evolution and Deprecation Guidelines
Public methods in Apache DataFusion evolve over time: while we try to maintain a stable API, we also improve the API over time. As a result, we typically deprecate methods before removing them, according to the deprecation guidelines.
Dependencies and Cargo.lock
Following the guidance on committing Cargo.lock files, this project commits
its Cargo.lock file.
CI uses the committed Cargo.lock file, and dependencies are updated regularly
using Dependabot PRs.