-
Notifications
You must be signed in to change notification settings - Fork 647
feat: add an arrow-stats crate with the ability to calculate basic stats on arrays #5967
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b7935b
Add an arrow-stats crate with the ability to calculate basic stats on…
westonpace 81f530c
Address clippy suggestions
westonpace 5a571a1
Add README for lance-arrow-stats crate
westonpace d9b018f
Support nested list types in StatisticsAccumulator
westonpace 2b1586f
Fix old reference to arrow-scalar which is now lance-arrow-scalar
westonpace 21473c4
Fix clippy errors for Rust 2024 match ergonomics
westonpace 8110632
Fix doctest import to use renamed crate name
westonpace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [package] | ||
| name = "lance-arrow-stats" | ||
| version = "57.0.0" | ||
| edition.workspace = true | ||
| authors.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| description = "Statistics accumulator for Arrow arrays (min, max, null_count, nan_count)" | ||
| keywords.workspace = true | ||
| categories.workspace = true | ||
| rust-version.workspace = true | ||
| readme = "README.md" | ||
|
HaochengLIU marked this conversation as resolved.
|
||
|
|
||
| [dependencies] | ||
| arrow-array = { workspace = true } | ||
| arrow-schema = { workspace = true } | ||
| lance-arrow-scalar = { workspace = true } | ||
| half = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| arrow-select = { workspace = true } | ||
| proptest = { workspace = true } | ||
| rstest = { workspace = true } | ||
|
|
||
| [lints] | ||
| workspace = true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # lance-arrow-stats | ||
|
|
||
| Statistics accumulator for [Apache Arrow](https://arrow.apache.org/) arrays. | ||
|
|
||
| Computes min, max, null count, NaN count, and buffer memory usage over one or | ||
| more batches of Arrow data. Designed for use in Lance's columnar storage layer | ||
| where page-level statistics drive predicate pushdown and query planning. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```rust | ||
| use arrow_array::{Int32Array, ArrayRef}; | ||
| use lance_arrow_stats::StatisticsAccumulator; | ||
| use arrow_schema::DataType; | ||
| use std::sync::Arc; | ||
|
|
||
| let mut acc = StatisticsAccumulator::new(&DataType::Int32); | ||
|
|
||
| let batch: ArrayRef = Arc::new(Int32Array::from(vec![Some(3), None, Some(1), Some(4)])); | ||
| acc.update(&batch).unwrap(); | ||
|
|
||
| let stats = acc.finish(); | ||
| assert_eq!(stats.null_count, 1); | ||
| ``` | ||
|
|
||
| ## Tracked Statistics | ||
|
|
||
| | Statistic | Description | | ||
| | --------------- | -------------------------------------------------------- | | ||
| | `min` | Minimum non-null, non-NaN value (`ArrowScalar`) | | ||
| | `max` | Maximum non-null, non-NaN value (`ArrowScalar`) | | ||
| | `null_count` | Total number of null values | | ||
| | `nan_count` | Total NaN values (float and float-list types only) | | ||
| | `item_nulls` | Null items inside list entries (list types only) | | ||
| | `buffer_memory` | Total Arrow buffer memory in bytes | | ||
|
|
||
| ## Supported Types | ||
|
|
||
| - **Numeric** — Int8–Int64, UInt8–UInt64, Float16/32/64 | ||
| - **Temporal** — Date32/64, Time32/64, Timestamp, Duration | ||
| - **Boolean** | ||
| - **String** — Utf8, LargeUtf8 | ||
| - **Binary** — Binary, LargeBinary | ||
| - **List** — List, LargeList, FixedSizeList (computes stats over items) | ||
|
|
||
| Dictionary, run-end encoded, and view types are accepted but min/max will be | ||
| `None`. | ||
|
|
||
| ## Merging | ||
|
|
||
| Accumulators of the same data type can be merged, which is useful for combining | ||
| statistics computed in parallel across different pages or files: | ||
|
|
||
| ```rust | ||
| use lance_arrow_stats::StatisticsAccumulator; | ||
| use arrow_schema::DataType; | ||
|
|
||
| let mut a = StatisticsAccumulator::new(&DataType::Float32); | ||
| let mut b = StatisticsAccumulator::new(&DataType::Float32); | ||
| // ... update each with different batches ... | ||
| a.merge(&b).unwrap(); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Seeds for failure cases proptest has generated in the past. It is | ||
| # automatically read and these particular cases re-run before any | ||
| # novel cases are generated. | ||
| # | ||
| # It is recommended to check this file in to source control so that | ||
| # everyone who runs the test benefits from these saved cases. | ||
| cc 81b0445f36fa8f491c1fb3162f51b61c8be140d5b2a1e792c42b4bdb7f1b6a62 # shrinks to values = [0.0, -0.0] | ||
| cc 8651fce939497f33c6dafd842937d95965af97833bfbbd10df30d5ea00dbd07d # shrinks to values = [Some(0.0), Some(-0.0)] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.