Repository navigation
Conversation
Extract AlpPage (validated header and offsets, vectors parsed on demand through the offset array) and AlpVector (one parsed vector) from AlpDecoder, which becomes a cursor over the page. Contiguity is checked per vector instead of through a running expected offset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
run benchmark alp |
|
🤖 Benchmark starting (GKE) | trigger Target: alp Sharding factor: 1 (1 workers). Comparing alp-page-view (7f36641) to fb26b75 (merge-base) diff Run configurationrun benchmark alp
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: alp Comparing alp-page-view (7f36641) to fb26b75 (merge-base) diff Run configurationrun benchmark alp
shards: 1
DetailsPer-runner informationalp — shard 1/1Node: gk3-benchmark-cluster-nap-1gn6eqn3-d41f84c1-p4gm Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench alpCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
AlpVector held its packed values and exception sections as Bytes slices, and CurrentVector cloned the packed slice again for its BitReader. That is four refcounted handles per vector, one more than before the refactor, and refcounting is about a third of a single-value read. Store the sections as byte ranges into the page body instead. Only the BitReader takes a Bytes slice, and decode_range reads exceptions from the body it is passed. Also return an error from AlpPage::vector for an out-of-range index rather than relying on a debug assertion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
run benchmark alp |
|
🤖 Benchmark starting (GKE) | trigger Target: alp Sharding factor: 1 (1 workers). Comparing alp-page-view (c056e06) to fb26b75 (merge-base) diff Run configurationrun benchmark alp
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: alp Comparing alp-page-view (c056e06) to fb26b75 (merge-base) diff Run configurationrun benchmark alp
shards: 1
DetailsPer-runner informationalp — shard 1/1Node: gk3-benchmark-cluster-nap-71w3ckme-05705914-7q86 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench alpCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
…ding A predicate can now declare that it computes `column <op> scalar` through `ArrowPredicate::comparison()`. When it projects one top-level FLOAT or DOUBLE column read as Float32 or Float64 and compares it with a non-null scalar of the same type, the reader builds a comparison reader instead of decoding the column and calling the predicate. On ALP pages the comparison reader decides whole vectors from their frame of reference and bit width, compares only the exceptions, and decodes the vectors whose bounds straddle the scalar. Other encodings are decoded and compared, per page, so a dictionary chunk that falls back to ALP works. - Public: `ComparisonOp`, `ColumnComparison`, `ArrowPredicate::comparison` (default None), `ArrowPredicateFn::with_comparison`. `AlpPage` and `AlpPage::compare_range` behind `experimental`. - Both the sync reader and the push decoder use it. The push decoder's predicate cache skips predicates that declare a comparison. - `AlpPage::vector` returns the existing `AlpEncodedVectorView`, so the separate `AlpVector` type is gone. - Parity tests compare declared and undeclared predicates across ALP, PLAIN, dictionary and dictionary-then-ALP pages, both reader paths, and three row selections. The declared predicate fails if the reader calls it. - New `arrow_reader_alp_filter` benchmark through the public reader API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@alamb check out the idea 🤓 |
| /// * `false` or `null`: the row should not be returned | ||
| fn evaluate(&mut self, batch: RecordBatch) -> Result<BooleanArray, ArrowError>; | ||
|
|
||
| /// Describes this predicate as a comparison of its only projected column |
There was a problem hiding this comment.
Yeah, this is the key API change -- basically we have to change the Predicate API to allow processing on (parquet) encoded data. I think in general this is a promising idea.
There are other types this could help with too (like dictionary encoded arrays, or potentially evaluating directly on string bytes, etc)
I actually think trying to evaluate predicates directly in the parquet crate may get complicated quickly because:
- there are semantics that are engine dependent (e.g. is
0.0==+0.0?) - There may be functions (like string match, etc) that have engine specific meanings
What would you think about implementing an API that kept that out of the parquet crate (and we would define it in datafusion or other engines?
Something like this maybe
trait ArrowPredicate {
...
/// Evaluate this predicate directly on ALP encoded data if possible
/// the default returns None in which case the parqute reader will convert to arrow
/// and then call `evaluate`
fn evalute_alp(&mut self, header: &..., data: ...) -> Result<Option<BooleanArray>>> {
return None; // default implementation
}
/// Evaluate this predicate directly on byte stream split data
fn evalute_bss(&mut self, header: &..., data: ...) -> Result<Option<BooleanArray>>> {
return None; // default implementation
}
}There was a problem hiding this comment.
This would effectively move the
parquet/tests/arrow_reader/comparison_pushdown.rs
INto datafusion I think
Which issue does this PR close?
Rationale for this change
A
RowFilterpredicate is opaque to the reader. To evaluatevalue > 21.5, the reader decodes the whole column into aFloat64Array, calls the predicate, and uses theBooleanArrayit returns.ALP pages can answer most of that without decoding. Each ALP vector stores a frame of reference, the exact minimum of its packed integers, and a bit width, so every packed slot decodes into
[decode(FOR), decode(FOR + 2^bit_width - 1)], and decoding is monotonic. If that range lies entirely on one side of the scalar, the whole vector has one answer, and only its exceptions, which are stored separately as raw values, need comparing. Vectors whose range straddles the scalar are decoded as before.The reader can only use that if it knows what the predicate computes. This PR lets a predicate say so.
What changes are included in this PR?
Predicate declaration (public, additive).
ArrowPredicate::comparison()returnsOption<&ColumnComparison>and defaults toNone. AColumnComparisonis aComparisonOpand an ArrowScalar, with the semantics of Arrow's comparison kernels: floats compare in totalOrder, and null rows are not selected.ArrowPredicateFn::with_comparisondeclares one on a closure predicate. The declared comparison must select exactly the rowsevaluateselects.Reader wiring.
ArrayReaderBuilder::build_predicate_readerchecks whether a predicate qualifies: it declares a comparison, projects a single top-level, non-repeated column read asFloat32orFloat64, and compares it with a non-null scalar of the same type. The single-column check reuses the one predicate fusion already used. A qualifying predicate gets a comparison reader whose only output column is the result, and a crate-private adapter passes that column toReadPlanBuilder::with_predicate_options, so limits, padding and selection building are unchanged. Anything else takes today's path. Both the sync reader and the push decoder use it. The push decoder's predicate cache skips predicates that declare a comparison, since their filter step produces no decoded column to cache.Comparison decoder (
array_reader/comparison.rs). Chooses per page: ALP pages go through the kernel, other encodings are decoded and compared, so a dictionary chunk that falls back to ALP works. Results go into a bit-packed values buffer with its own null padding.GenericRecordReadergains a small hook to configure each per-chunk value decoder with the operator and scalar.Kernel (
alp_decoder/compare.rs).AlpPage::compare_rangeappends one bit per value in a range. Crate-internalcompare_range_withreuses buffers across reads and resumes a vector that a previous read stopped in, when the next read starts at the same value. Decoded vectors are compared with unchecked reads, the pattern Arrow's own comparison kernels use, which is this PR's oneunsafeblock: it has aSAFETYcomment and a debug assertion, and its test runs clean under Miri. A safe chunked version was 5-19% slower in the kernel benchmark.Page view (the original scope of this PR).
AlpPagevalidates a page's header and offsets once, andvector(idx)parses any vector through the offsets array, returning the existingAlpEncodedVectorView. Vectors are checked to fill[offset, next offset)exactly, so they are contiguous without parsing their neighbours. The view keeps byte offsets into the page body, so loading a vector refcounts oneBytesslice, for the bit reader, instead of three. An out-of-range index returns an error.Are these changes tested?
tests/arrow_reader/comparison_pushdown.rs: a predicate that declares its comparison selects the same rows as the same closure without it, for files with ALP, PLAIN, dictionary, and dictionary-then-ALP pages, f32 and f64 columns with nulls, NaN, ±0 and ±infinity, all six operators against 13 scalars, no selection, a selection skipping whole pages, and a fragmented selection skipping within pages, through both the sync reader and the push decoder. The declared predicate's closure panics if the reader calls it, so a silent fallback fails the test. A second test checks that a comparison whose scalar type does not match the column falls back toevaluate.compare_rangewith Arrow's comparison kernels on synthetic pages and onalp_extended.zstd.parquetpages written by another implementation (vector sizes 32, 1024 and 4096), including uneven walks that stop and resume inside vectors and leave gaps, bound overflow, and vectors made only of exceptions. A smallappend_alltest is sized for Miri.Benchmarked with the new
arrow_reader_alp_filter: 1M two-decimal readings in an ALP column,value > thresholdthroughParquetRecordBatchReaderBuilderand the push decoder, with the plain closure (decode) and with the declared comparison (pushdown). It compares both modes in one binary, so it does not need a baseline commit. Speedup of pushdown over decode, locally on one pinned core:idid, valueid, valueClustered values drift slowly, so most vectors lie on one side of the threshold. That is the well-predicted case, and the gain comes from not unpacking those vectors. Shuffled holds the same values in random order, so almost every vector straddles the threshold and is decoded: that is the poorly-predicted case, and the best it can reach is parity. Results land within about 5% of it, against a baseline that varies about 3% between runs. With
valuealso in the output, the push decoder gains more because the output step decodes only the selected rows instead of reading the predicate cache.Plain decoding (
alpbenchmark,alp/decode/*) is 0.87-1.07x of main.Are there any significant user-facing changes?
New public items, all additive:
parquet::arrow::arrow_reader::ComparisonOpparquet::arrow::arrow_reader::ColumnComparison(new,op,scalar)ArrowPredicate::comparison, a provided method returningNoneArrowPredicateFn::with_comparisonexperimental:parquet::decoding::AlpPage(try_new,num_values,compare_range)Predicates that do not declare a comparison are evaluated exactly as before. Predicates fused by the push decoder do not expose a comparison and take the existing path.
AI usage disclosure
The code, tests, benchmark and this description were drafted with Claude Code. This stays a draft until I have reviewed it.