perf: optimize `array_distinct` with batched row conversion (#20364) ## 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 <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> This PR optimizes the `array_distinct` function by batching value conversions and utilizing a `HashSet` for deduplication. It is a follow-up to https://github.com/apache/datafusion/pull/20243. ## What changes are included in this PR? This PR optimizes `array_distinct` by: 1. Converting all values to rows in a single batch rather than individually. 2. Using a HashSet to deduplicate values for each list. ### Benchmark ``` group main optimized ----- ---- --------- array_distinct/high_duplicate/10 2.66 855.1±28.18µs ? ?/sec 1.00 321.9±8.70µs ? ?/sec array_distinct/high_duplicate/100 2.21 6.4±0.13ms ? ?/sec 1.00 2.9±0.09ms ? ?/sec array_distinct/high_duplicate/50 2.14 3.2±0.05ms ? ?/sec 1.00 1478.3±41.90µs ? ?/sec array_distinct/low_duplicate/10 2.73 1017.3±44.67µs ? ?/sec 1.00 372.5±17.33µs ? ?/sec array_distinct/low_duplicate/100 1.32 4.4±0.13ms ? ?/sec 1.00 3.3±0.15ms ? ?/sec array_distinct/low_duplicate/50 1.55 2.6±0.06ms ? ?/sec 1.00 1689.0±94.15µs ? ?/sec ``` <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes, unit tests exist and pass. ## Are there any user-facing changes? Yes, there is a slight change in the output order. This new behavior is consistent with `array_union` and `array_intersect`, where the output order is more intuitive as it preserves the original order of elements in the array. <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: lyne7-sc <lilinfeng0310@gmail.com>
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:
“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:
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.
Please see the contributor guide and communication pages for more information.
This crate has several features which can be specified in your Cargo.toml.
Default features:
nested_expressions: functions for working with nested types such as array_to_stringcompression: reading files compressed with xz2, bzip2, flate2, and zstdcrypto_expressions: cryptographic functions such as md5 and sha256datetime_expressions: date and time functions such as to_timestampencoding_expressions: encode and decode functionsparquet: support for reading the Apache Parquet formatsql: support for SQL parsing and planningregex_expressions: regular expression functions, such as regexp_matchunicode_expressions: include Unicode-aware functions such as character_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's serde featurePublic 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.
Cargo.lockFollowing 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.