Repository navigation
Add higher-order array functions to pack bits. - #50053
Eridanus117 wants to merge 39 commits into
Conversation
|
This is an automatic comment. The PR descriptions does not match the template. Please, edit it accordingly. The error is: More than one changelog category specified: 'New Feature', 'Improvement' |
|
This is an automatic comment. The PR descriptions does not match the template. Please, edit it accordingly. The error is: Changelog entry required for category 'New Feature' |
|
This is an automatic comment. The PR descriptions does not match the template. Please, edit it accordingly. The error is: Changelog entry required for category 'New Feature' |
|
@alexey-milovidov |
… truncating
Address review: the `n` (FixedString size) and `g` (group size) fixed
parameters were accepted for any integer type via `isInt`/`isUInt`, then
read through the 64-bit `getInt`/`getUInt` accessors. A 128/256-bit
constant was therefore silently truncated to its low 64 bits, so
`arrayPackBitGroupsToUInt64(x -> x, toUInt128('18446744073709551620'), ...)`
(the value is 2^64 + 4) behaved as `g = 4` instead of being rejected as a
group size greater than 64; the same truncation could shrink an oversized
`FixedString` size.
Restrict these fixed parameters to native integers with
`WhichDataType::isNativeInteger`, mirroring how `arrayTopK` validates its
`K` argument. This throws `ILLEGAL_TYPE_OF_ARGUMENT` for wide constants
before any range check, so an out-of-range value can no longer slip
through by truncation. Added focused rejection tests for `UInt128`/
`UInt256` constants passed as the group size and the `FixedString` size,
and updated the documented argument types to the native-integer subset.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…args Update the embedded `FunctionDocumentation` argument types for `n` and `g` from `(U)Int*` to `(U)Int8/16/32/64` to reflect that these fixed parameters are now restricted to native integers, matching `arrayTopK`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e with current APIs The branch for the `arrayPackBits*` / `arrayPackBitGroups*` higher-order array functions (PR ClickHouse#50053, issue ClickHouse#48830) was ~45000 commits behind `master`, so a plain merge produced conflicts across unrelated subsystems. This commit brings the branch up to the current `master` while keeping the feature exactly as reviewed: the net change against `master` is still only `src/Functions/array/arrayPackBits.cpp`, the `return_fixed_string` hook in `src/Functions/array/FunctionArrayMapped.h`, and the `02769_array_pack_bits` test. The feature already targets the current documentation API (`FunctionDocumentation` with `IntroducedIn`/`Category`, matching `arrayTopK`), so no source changes were needed beyond the merge. Verified against current `master`: `clickhouse` links, `arrayPackBits.cpp` compiles without warnings, all 24 value queries of `02769_array_pack_bits` match the reference, and all 10 error cases throw the expected `BAD_ARGUMENTS` / `ILLEGAL_TYPE_OF_ARGUMENT` codes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The AI review flagged that the lambda-type gate accepts `Int128`/`UInt128`/ `Int256`/`UInt256` while `execute` reads the result via `IColumn::getUInt` / `getBool`, claiming those accessors throw for `wide::integer` columns. Verified against current `master` that they do not: `getBool` evaluates the full wide value (so `2^64` is truthy even though its low 64 bits are zero) and `getUInt` returns the low 64 bits, of which only the low `g` bits are used for groups. The functions therefore handle wide-integer lambda results correctly. These regression tests lock in that behavior for the `UInt128` / `UInt256` cases. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Brought this branch up to current Verified locally against current Addressed the AI review:
The previous red checks were the known-flaky One open item remains for @alexey-milovidov: the byte order of the |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 191/195 (97.95%) · Uncovered code |
The `arrayPackBitsToUInt64` and `arrayPackBitGroupsToUInt64` variants previously accumulated the packed bits as a big-endian bitstream integer, while issue ClickHouse#48830 explicitly asks for little-endian byte order. Now the `UInt64` variants produce exactly the same byte stream as the `String` / `FixedString` variants (most-significant-bit first within each byte) and interpret it in little-endian byte order, so: arrayPackBitsToUInt64(f, arr) == reinterpretAsUInt64(arrayPackBitsToString(f, arr)) arrayPackBitGroupsToUInt64(f, g, arr) == reinterpretAsUInt64(arrayPackBitGroupsToString(f, g, arr)) Updated the embedded documentation, the stateless test references, and added explicit equivalence tests with `reinterpretAsUInt64`. Addresses the AI review blocker: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=50053&sha=latest&name_0=PR Co-Authored-By: Claude Fable 5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayPackBits.cpp.o |
new | 896.79 KiB | +896.79 KiB |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
24 translation units recompiled, 105 s compile time in total, 23 of them have a recent master baseline.
The bit-packing higher-order array functions set `needOneArray` to `true`, which rejected calls like `arrayPackBitsToUInt64((x, y) -> x > y, lhs, rhs)` even though the implementation only needs the lambda result and the offsets of the first array. All sibling `FunctionArrayMapped` functions accept parallel arrays, so the restriction is dropped and regression tests are added, including one for the `SIZES_OF_ARRAYS_DONT_MATCH` case. Also bump `FunctionDocumentation::IntroducedIn` from `26.7` to `26.8`, because `26.7` was already cut without these functions.
…ixedString` variants Address review: `arrayPackBitGroupsToUInt64` is documented as `reinterpretAsUInt64(arrayPackBitGroupsToString(...))`, but it kept only the leading whole groups that fit into 64 bits (`max_groups = 64 / g`), so for a group size that does not divide 64 (e.g. `g = 3` with 22 groups = 66 bits) the group straddling bit 64 was dropped and zero-padded instead of contributing its leading bits. The `FixedString(n)` variants had the same whole-group truncation. Both now share one packing routine with a bit limit (64 for `UInt64`, `n * 8` for `FixedString`, unlimited for `String`), so a shorter result is always a prefix of the byte stream of the `String` variant. The embedded documentation describes the new rule, and `02769_array_pack_bits` gets regressions with `g = 3` for both the `UInt64` and the `FixedString` variants. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Superseded by #123478. The source fork is archived and can no longer be pushed to. The new PR keeps @Eridanus117's commits (authorship preserved), merges current master, and addresses the remaining review comment ( |
Closes: #48830
Adds higher-order array functions that apply a lambda to each element of an array and pack the resulting bits into a compact representation. Useful for compression and quantization in vector-search workloads, where a single bit (or a small group of bits) is derived per dimension and packed into a fixed-width value.
Six functions are added:
arrayPackBitsToUInt64(f, arr)— pack one bit per element into aUInt64(only the first 64 bits are used).arrayPackBitsToString(f, arr)— pack one bit per element into aStringofceil(size / 8)bytes.arrayPackBitsToFixedString(f, n, arr)— pack one bit per element into aFixedString(n).arrayPackBitGroupsToUInt64(f, g, arr)— the same, but the lambda returns an integer whose lowgbits form a group, and the groups are packed contiguously (N·gbits).arrayPackBitGroupsToString(f, g, arr)arrayPackBitGroupsToFixedString(f, n, g, arr)Like the other higher-order array functions, several arrays of equal size can be passed, in which case the lambda takes one argument per array (
arrayPackBitsToUInt64((x, y) -> x > y, lhs, rhs)).Bits are packed most-significant-bit first within each byte and groups are packed contiguously, one after another (a group does not occupy a whole byte). The
*ToUInt64variants interpret the packed byte stream in little-endian byte order, as requested in the issue, soarrayPackBitsToUInt64(f, arr) = reinterpretAsUInt64(arrayPackBitsToString(f, arr))and likewise for the group variants. TheUInt64andFixedString(n)results are always a prefix of theStringbyte stream: the stream is cut at 64 orn * 8bits, so a group that straddles the boundary contributes only its leading bits. The implementation is a singleArrayPackBitsImpltemplate parameterized by the result column type and aPackGroupsflag.FunctionArrayMappedis extended with areturn_fixed_stringtrait so that an implementation returning aFixedStringcan forward the constant size argument togetReturnType.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added higher-order array functions to pack bits:
arrayPackBitsToUInt64,arrayPackBitsToString,arrayPackBitsToFixedString,arrayPackBitGroupsToUInt64,arrayPackBitGroupsToString,arrayPackBitGroupsToFixedString.Documentation entry for user-facing changes
The functions carry embedded
FunctionDocumentation(description, syntax, arguments, returned value, examples), from which the user-facing documentation is generated.Workflow [PR]
Sync PR [sync-upstream/pr/50053]