Skip to content

feat(parquet): evaluate RowFilter comparisons on ALP pages while decoding - #12469

Draft
sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:alp-page-view
Draft

sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:alp-page-view

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

A RowFilter predicate is opaque to the reader. To evaluate value > 21.5, the reader decodes the whole column into a Float64Array, calls the predicate, and uses the BooleanArray it 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() returns Option<&ColumnComparison> and defaults to None. A ColumnComparison is a ComparisonOp and an Arrow Scalar, with the semantics of Arrow's comparison kernels: floats compare in totalOrder, and null rows are not selected. ArrowPredicateFn::with_comparison declares one on a closure predicate. The declared comparison must select exactly the rows evaluate selects.

Reader wiring. ArrayReaderBuilder::build_predicate_reader checks whether a predicate qualifies: it declares a comparison, projects a single top-level, non-repeated column read as Float32 or Float64, 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 to ReadPlanBuilder::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. GenericRecordReader gains a small hook to configure each per-chunk value decoder with the operator and scalar.

Kernel (alp_decoder/compare.rs). AlpPage::compare_range appends one bit per value in a range. Crate-internal compare_range_with reuses 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 one unsafe block: it has a SAFETY comment 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). AlpPage validates a page's header and offsets once, and vector(idx) parses any vector through the offsets array, returning the existing AlpEncodedVectorView. 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 one Bytes slice, 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 to evaluate.
  • Kernel unit tests compare compare_range with Arrow's comparison kernels on synthetic pages and on alp_extended.zstd.parquet pages 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 small append_all test is sized for Miri.
  • Mutation checks: inverting the decided-vector result, breaking null padding, or resuming a vector at the wrong offset each fail the tests.

Benchmarked with the new arrow_reader_alp_filter: 1M two-decimal readings in an ALP column, value > threshold through ParquetRecordBatchReaderBuilder and 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:

data filter keeps sync, output id sync, output id, value push, output id, value
clustered 1% 3.22x 3.10x 4.18x
clustered 50% 1.64x 1.42x 1.64x
shuffled 1% 1.03x 0.95x 1.21x
shuffled 50% 0.95x 1.01x 1.07x

Clustered 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 value also 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 (alp benchmark, 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::ComparisonOp
  • parquet::arrow::arrow_reader::ColumnComparison (new, op, scalar)
  • ArrowPredicate::comparison, a provided method returning None
  • ArrowPredicateFn::with_comparison
  • Behind experimental: 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.

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>
@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Nov 25, 2026
@sdf-jkl

sdf-jkl commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

run benchmark alp

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: alp

Sharding factor: 1 (1 workers).

Comparing alp-page-view (7f36641) to fb26b75 (merge-base) diff

Run configuration
run benchmark alp
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: alp

Comparing alp-page-view (7f36641) to fb26b75 (merge-base) diff

Run configuration
run benchmark alp
shards: 1
Details
group                                                base                                     changed
-----                                                ----                                     -------
alp/decode/page/f32/decimal_with_exceptions          1.00     95.5±0.08µs 1308.3 MElem/sec    1.05    100.2±0.18µs 1247.8 MElem/sec
alp/decode/page/f32/high_precision                   1.00    118.4±0.17µs 1055.8 MElem/sec    1.04    122.9±2.06µs 1017.2 MElem/sec
alp/decode/page/f64/decimal_with_exceptions          1.00     67.5±0.29µs 1851.4 MElem/sec    1.03     69.7±0.28µs 1793.2 MElem/sec
alp/decode/page/f64/high_precision                   1.00    180.2±0.49µs 693.8 MElem/sec     1.00    180.2±0.44µs 693.8 MElem/sec
alp/decode/random_100/f32/decimal_with_exceptions    1.00     36.6±0.64µs  2.6 MElem/sec      1.12     41.1±0.46µs  2.3 MElem/sec
alp/decode/random_100/f32/high_precision             1.00     45.7±0.09µs  2.1 MElem/sec      1.12     51.0±0.40µs 1915.6 KElem/sec
alp/decode/random_100/f64/decimal_with_exceptions    1.00     21.4±0.23µs  4.4 MElem/sec      1.16     24.8±0.27µs  3.8 MElem/sec
alp/decode/random_100/f64/high_precision             1.00     58.7±0.07µs 1663.3 KElem/sec    1.08     63.3±0.35µs 1543.8 KElem/sec
alp/encode/first_page/f32/decimal_with_exceptions    1.03   762.5±45.86µs 163.9 MElem/sec     1.00   736.8±43.04µs 169.7 MElem/sec
alp/encode/first_page/f32/high_precision             1.00   778.5±58.26µs 160.6 MElem/sec     1.04   807.2±73.88µs 154.9 MElem/sec
alp/encode/first_page/f64/decimal_with_exceptions    1.02   1218.1±5.63µs 102.6 MElem/sec     1.00  1196.8±19.73µs 104.4 MElem/sec
alp/encode/first_page/f64/high_precision             1.00      2.0±0.01ms 61.7 MElem/sec      1.00      2.0±0.01ms 61.9 MElem/sec
alp/encode/next_page/f32/decimal_with_exceptions     1.00    353.3±3.40µs 353.8 MElem/sec     1.00    353.2±0.22µs 353.9 MElem/sec
alp/encode/next_page/f32/high_precision              1.00    442.6±0.45µs 282.4 MElem/sec     1.00    443.0±0.83µs 282.2 MElem/sec
alp/encode/next_page/f64/decimal_with_exceptions     1.00    430.2±0.70µs 290.6 MElem/sec     1.00    430.6±0.32µs 290.3 MElem/sec
alp/encode/next_page/f64/high_precision              1.00   1307.1±2.17µs 95.6 MElem/sec      1.00   1313.2±2.77µs 95.2 MElem/sec

Per-runner information
alp — shard 1/1

Node: gk3-benchmark-cluster-nap-1gn6eqn3-d41f84c1-p4gm

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c7169877559-5737-tdq8j 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench alp
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 175.0s
Peak memory 111.4 MiB
Avg memory 16.3 MiB
CPU user 165.8s
CPU sys 4.1s
Peak spill 0 B

branch

Metric Value
Wall time 170.0s
Peak memory 116.3 MiB
Avg memory 14.9 MiB
CPU user 161.5s
CPU sys 4.7s
Peak spill 0 B

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>
@sdf-jkl

sdf-jkl commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

run benchmark alp

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: alp

Sharding factor: 1 (1 workers).

Comparing alp-page-view (c056e06) to fb26b75 (merge-base) diff

Run configuration
run benchmark alp
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: alp

Comparing alp-page-view (c056e06) to fb26b75 (merge-base) diff

Run configuration
run benchmark alp
shards: 1
Details
group                                                base                                     changed
-----                                                ----                                     -------
alp/decode/page/f32/decimal_with_exceptions          1.02     96.3±0.30µs 1298.0 MElem/sec    1.00     94.5±0.27µs 1322.2 MElem/sec
alp/decode/page/f32/high_precision                   1.04    119.3±0.19µs 1047.8 MElem/sec    1.00    115.1±0.29µs 1086.3 MElem/sec
alp/decode/page/f64/decimal_with_exceptions          1.02     67.2±0.11µs 1861.4 MElem/sec    1.00     65.5±0.36µs 1907.9 MElem/sec
alp/decode/page/f64/high_precision                   1.01    180.0±0.29µs 694.5 MElem/sec     1.00    177.4±2.08µs 704.6 MElem/sec
alp/decode/random_100/f32/decimal_with_exceptions    1.04     35.7±0.12µs  2.7 MElem/sec      1.00     34.5±0.19µs  2.8 MElem/sec
alp/decode/random_100/f32/high_precision             1.03     45.6±0.07µs  2.1 MElem/sec      1.00     44.4±0.26µs  2.1 MElem/sec
alp/decode/random_100/f64/decimal_with_exceptions    1.16     21.5±0.16µs  4.4 MElem/sec      1.00     18.5±0.14µs  5.1 MElem/sec
alp/decode/random_100/f64/high_precision             1.00     58.6±0.08µs 1666.9 KElem/sec    1.00     58.8±0.17µs 1661.6 KElem/sec
alp/encode/first_page/f32/decimal_with_exceptions    1.00   754.3±39.36µs 165.7 MElem/sec     1.02   765.8±34.69µs 163.2 MElem/sec
alp/encode/first_page/f32/high_precision             1.00   784.8±45.14µs 159.3 MElem/sec     1.03   811.6±71.73µs 154.0 MElem/sec
alp/encode/first_page/f64/decimal_with_exceptions    1.03  1222.7±15.18µs 102.2 MElem/sec     1.00  1187.6±24.23µs 105.3 MElem/sec
alp/encode/first_page/f64/high_precision             1.00      2.1±0.01ms 60.2 MElem/sec      1.14      2.4±0.00ms 52.8 MElem/sec
alp/encode/next_page/f32/decimal_with_exceptions     1.00    352.7±0.33µs 354.4 MElem/sec     1.00    353.4±0.63µs 353.7 MElem/sec
alp/encode/next_page/f32/high_precision              1.00    444.4±1.21µs 281.3 MElem/sec     1.00    442.9±0.92µs 282.2 MElem/sec
alp/encode/next_page/f64/decimal_with_exceptions     1.00    430.1±0.67µs 290.6 MElem/sec     1.00    430.1±0.78µs 290.6 MElem/sec
alp/encode/next_page/f64/high_precision              1.00   1312.5±9.47µs 95.2 MElem/sec      1.00   1315.7±3.73µs 95.0 MElem/sec

Per-runner information
alp — shard 1/1

Node: gk3-benchmark-cluster-nap-71w3ckme-05705914-7q86

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c7174501590-5752-f28mq 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench alp
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 175.0s
Peak memory 71.8 MiB
Avg memory 14.5 MiB
CPU user 166.0s
CPU sys 3.7s
Peak spill 0 B

branch

Metric Value
Wall time 175.0s
Peak memory 113.5 MiB
Avg memory 14.9 MiB
CPU user 163.8s
CPU sys 5.4s
Peak spill 0 B

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>
@sdf-jkl sdf-jkl changed the title refactor(parquet): parse ALP vectors through a reusable page view feat(parquet): evaluate RowFilter comparisons on ALP pages while decoding Nov 27, 2026
@sdf-jkl

sdf-jkl commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. there are semantics that are engine dependent (e.g. is 0.0 == +0.0?)
  2. 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 
  }

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would effectively move the

parquet/tests/arrow_reader/comparison_pushdown.rs

INto datafusion I think

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants