apache / apache/paimon-cpp

[Feature] Unpack predicate boolean kernel bitmaps a byte at a time

已关闭
#335 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
C++
星标
65
派生
25
平均合并
2 天 12 小时
30 天内合并 PR
80

描述

## Search before asking

- [x] I searched in the [issues](https://github.com/apache/paimon-cpp/issues) and found nothing similar.

## Motivation

Two predicate leaf functions evaluate a batch by running an `arrow::compute` kernel and reading back the `arrow::BooleanArray` it writes: `MultiLiteralsLeafFunction` (`IN` / `NOT IN`, via `IsIn`) and `NullFalseLeafBinaryFunction` (the comparison functions). A kernel returns a bitmap, one bit per row, but `LeafFunction::Test` returns `std::vector`, one byte per row, so both call sites spread the bits over bytes with the same per-row loop: test `IsNull`, read `Value`, apply the negation `NOT IN` needs, store a byte. That is a shift, a mask and a byte store per row, duplicated across the two call sites, on the selection path every filtered batch goes through.

## Solution

Extract the spread into one helper, `ArrowUtils::UnpackBooleansToBytes(array, negate)`, and read the bitmap a byte at a time instead of a bit at a time:

- A compile-time table maps each of the 256 bitmap bytes to the eight bytes it expands to, so the aligned body produces eight rows per iteration with one lookup and one 8-byte store.
- A scalar head and tail cover the rows sharing a partial leading or trailing byte, which is where the array offset is not byte-aligned; a batch a kernel has just written is aligned, so it takes the fast body throughout.
- The offset and the validity bitmap are honoured exactly as `BooleanArray::Value()` and `Array::IsValid()` honour them, and a null row unpacks to 0 whatever the value bitmap holds for it, which is what both `IN` / `NOT IN` and every `NullFalseLeafBinaryFunction` require.

`MultiLiteralsLeafFunction` passes its `negate` through; `NullFalseLeafBinaryFunction` passes `negate=false`. The bytes each returns are unchanged.

## Anything else?

A property test that asserts the helper equals a row-by-row reference through the very accessors it replaces, over every `(offset, length)` slice of a bitmap whose value and null periods are not multiples of eight and both negate values, pins the offset, validity and negate handling against the definitions it optimizes. No change to any header under `include/paimon/`, the storage format, or the protocol: `ArrowUtils` is an internal utility under `src/paimon/common/utils/arrow/`.

## Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

贡献指南

打开贡献指南

调研方向

从 src/paimon/common/utils/arrow/ 开始,找到 MultiLiteralsLeafFunction 和 NullFalseLeafBinaryFunction,然后通过 LeafFunction::Test 跟踪它们现有的 bitmap-to-byte 循环。添加共享 helper 和一个 property test,覆盖每个 offset 和 length、两种 negate 值,以及未按字节对齐的 validity 区间。当 helper 与逐行 accessor reference 匹配,并且两个 caller 都返回未改变的 bytes 时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
cpp
领域
data
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
74/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。