Skip to content

Support the Parquet ALP encoding - #125135

Merged
alexey-milovidov merged 20 commits into
masterfrom
parquet-alp-encoding
Oct 21, 2026
Merged

alexey-milovidov merged 20 commits into
masterfrom
parquet-alp-encoding

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Support the Parquet ALP (Adaptive Lossless floating-Point) encoding of FLOAT and DOUBLE columns (https://github.com/apache/parquet-format/blob/master/AlpEncoding.md) in the native Parquet reader and writer.

The first commits update contrib/arrow to have the ALP encoding in the generated Thrift code (sync of parquet.thrift with apache/parquet-format master).

Reading: ALP pages are decoded with full validation of the page and vector headers (malformed data throws INCORRECT_DATA); bit-unpacking uses Arrow's SIMD unpack; skipped vectors are not decoded.

Writing: the new setting output_format_parquet_use_alp_encoding (disabled by default, as the specification recommends for this encoding in Preview) writes FLOAT/DOUBLE columns with ALP. The encoder does the two-level (exponent, factor) search from the paper. A page that would be larger than PLAIN is written as PLAIN. Unlike parquet-java / Arrow / arrow-rs, which use ALP only as a fallback after dictionary encoding, with this setting float columns are written with ALP directly: in ClickHouse dictionary encoding falls back only when the dictionary exceeds output_format_parquet_max_dictionary_size, so most column chunks would never get ALP.

ParquetMetadata now shows ALP in encodings (Arrow's enum doesn't have it).

On 50M rows of decimal-like doubles with zstd, the file is 118 MB with ALP vs. 209 MB with PLAIN, and reading is slightly faster.

Interoperability: tests decode alp_extended.zstd.parquet from apache/parquet-testing (written by Arrow C++) and a file written by arrow-rs bit-exactly; arrow-rs also reads files written by ClickHouse bit-exactly. Only compression mode 0 is supported (as defined by the specification).

Related: ClickHouse/arrow#87

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Support the ALP encoding of floating-point columns in Parquet: such files can be read, and can be written with the new setting output_format_parquet_use_alp_encoding.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125135]

Version info

  • Merged into: 26.11.1.451-master (included in 26.11 and later)

alexey-milovidov and others added 4 commits October 11, 2026 00:48
…ormat master

This brings the `ALP` encoding and the `FILE` logical type into the generated
Thrift code used by the native Parquet reader and writer.

Related: ClickHouse/arrow#87

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tree is identical; this points the submodule at the commit on the
`ClickHouse/apache-arrow-25.0.0` branch.

Related: ClickHouse/arrow#87

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The native Parquet reader decodes data pages with the `ALP` (Adaptive Lossless
floating-Point, encoding 10) encoding, as specified in
https://github.com/apache/parquet-format/blob/master/AlpEncoding.md
Every field of the page is validated, so malformed pages throw `INCORRECT_DATA`.
Skipping values doesn't touch the skipped vectors, thanks to the offset array.

The writer encodes `Float32` and `Float64` columns with `ALP` when the new
setting `output_format_parquet_use_alp_encoding` is enabled (it is disabled by
default, as the specification recommends for now). The parameters are chosen
with the two-level sampling from the paper. Such columns are written without
a dictionary, and a page for which `ALP` would be bigger than `PLAIN` is
written as `PLAIN`.

`ParquetMetadata` shows `ALP` instead of `UNDEFINED`, which Arrow reports for
all the encodings it doesn't know.

The tests read `alp_extended.zstd.parquet` from apache/parquet-testing
(written by the Arrow C++ implementation) and a file written by arrow-rs with
data pages v2, and compare the values bit-exactly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [690d72f]

Summary: ✅


AI Review

Summary

Adds native Parquet ALP decoding and opt-in Float32/Float64 encoding, with PLAIN fallback and encoding metadata reporting. Reviewed head 690d72f379b53d255d9c99dee018c653defd318d and all prior discussion. The previous offset-validation and sampling findings are addressed; no actionable findings remain.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build is available, so the functional tests were not rerun locally. Runtime evidence comes from the included regression/interoperability tests and the available CI reports.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR. comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Oct 11, 2026
alexey-milovidov and others added 3 commits October 11, 2026 22:49
Validate that the `ALP` vectors are stored back to back after the offset array
(the first offset must be `num_vectors * 4` and each vector must end where the
next one begins), skip choosing the candidate parameters for pages without
values, and initialize `Candidate::wins` (`cppcoreguidelines-pro-type-member-init`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the message of the first-offset check as `Invalid offset of ALP vector 0`
and cover a gap before the first vector and a wrong offset of the second vector.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Observation, not fixed in this pass: the evenly-spaced sampling in findCandidates can alias with the data. For example, SELECT round(number * 0.25 - 3, 2) FROM numbers(1000) is written as PLAIN: with a stride of 4 every sampled value is an integer, so the only candidate is {e = 0, f = 0}, three quarters of the values become exceptions, and the page falls back to PLAIN. round(number * 0.01, 2) is fine. A sampling offset or a stride that is not a multiple of small numbers, or a retry of the full search on the page when it fails with the candidates, would avoid that.

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 690d72f37 with master a7f48537e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: compile time of recompiled translation units.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

458 object files changed (+362.75 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/ALPEncoding.cpp.o new 219.65 KiB +219.65 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/Write.cpp.o 1.31 MiB 1.39 MiB +82.11 KiB (+6.12%)

719 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 ⚠️

3325 translation units recompiled, 18426 s compile time in total, 2951 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Core/SettingsEnums.cpp: 21.2 s
  • programs/keeper/Keeper.cpp (clickhouse-keeper): 8.2 s
  • src/Processors/Formats/Impl/Parquet/ALPEncoding.cpp: 7.7 s
  • src/Examples/__/Common/examples/integer_hash_tables_benchmark.cpp: 6.4 s
  • src/Parsers/ASTSystemQuery.cpp: 6.2 s
  • src/Parsers/Access/ASTUserNameWithHost.cpp: 5.6 s
  • src/Examples/__/Common/examples/radix_sort.cpp: 5.5 s
  • src/Parsers/ASTDictionaryAttributeDeclaration.cpp: 5.3 s
  • src/Common/FieldAccurateComparison.cpp: 5.1 s
  • src/IO/S3/getObjectInfo.cpp: 5.1 s
  • src/Parsers/ASTExplainQuery.cpp: 5.0 s

Job report

alexey-milovidov and others added 2 commits October 12, 2026 16:49
`takeSample` took the values at a fixed stride, so the sample aliased with
periodic data: for values with a step of 0.25 the 64-value sample of a vector
(stride 16) and the 256-value sample for the candidates (stride 4) contained
only the integers. The parameters chosen on such a sample made 3/4 of a vector
exceptions, and the pages were written as `PLAIN`. Now one value is taken from
each block of `stride` values at a pseudo-random position inside the block.

This also lets `ALP` encode the `d_large` column of the round trip test, and
makes `f_decimal` slightly smaller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125135&sha=6d49a80de76afda458caae72b4243f7439f92763&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 (Cannot call function and because is has 3 arguments but 2 columns were captured with indexHint on file) and provide a fix in a separate PR. If the fix is already in progress, link it here. It looks like #125126 may cover it.

@groeneai

Copy link
Copy Markdown
Collaborator

#125126 is the fix. This is the same reduced and in VirtualColumnUtils::splitFilterNodeForAllowedInputs, reached through indexHint in the file() path filter: u8 <= 2147483647 is dropped because u8 is not a virtual column, and the copy keeps the 3-argument and for its 2 remaining children.

I checked it with the fuzzer's repro (02841.parquet and the failing query): master debug 371b23a aborts with this message (stack through getFilterByPathAndFileIndexes), and the #125126 amd_debug build returns normally. #125150 (merged) only changes KeyCondition.cpp, which is not on this stack.

…constructor

The check that each vector ends where the next one begins was done in
`decodeVector`, so it did not run for vectors that were skipped, and the end of
the last vector was not compared with the end of the page. Now `AlpPage` walks
the vector headers when it is constructed: each offset must be exactly the end
of the previous vector, the bit width and the number of exceptions are
validated there, and the last vector must end exactly at the end of the page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 4 commits October 13, 2026 19:47
…ed vectors

On ties the encoder preferred the bigger exponent and factor, as in the paper.
The ties are mostly between combinations with the same difference of the
exponent and the factor, which give the same integers, but the extra
multiplications by inexact powers of ten add rounding errors: for `Float32`
values with a step of 0.25, (2, 0) makes no exceptions while (6, 4) makes
them for 5% of the values, and a sample may not contain them. This made
`05366_parquet_alp_encoding_periodic_values` flaky depending on the
randomized `max_block_size`. Prefer the smaller exponent and factor instead.

Address review: the sampled vectors of a page are now chosen at a
pseudo-random position inside each block of vectors, like the values in
`takeSample`, and a page that does not compress with the candidates of the
previous pages is tried again with the candidates chosen from itself.

Give the size check of the test some margin for the small randomized blocks.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125135&sha=be0f0a5f841d2afc33dc3c4b4216d8c3e966cd3b&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29
#125135

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125135&sha=df119dd7b8557cd3906c09630cdd45ac47cdf73b&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20sequential%29 (02968_file_log_multiple_read: the output stops at 18 instead of 20; it also failed on 2026-10-13 in #125433 and on 2026-10-06 in #124210, and the earlier fix #103602 did not cover it) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I'm investigating 02968_file_log_multiple_read and will follow up here with a separate PR.

So far: the waits in the test only require 1 row and then 11 rows (inherited from the original count -gt 0 / count -gt 10 loops), i.e. one FileLog batch per round. The 20 lines are appended one echo at a time, so FileLog can read them in two batches, and the final SELECT runs before the second one lands (18 rows here, 19 in #125433). No fix for this is in flight.

The 2026-10-06 failure in #124210 has a different signature (INFINITE_LOOP from the self-referencing Alias that 04946_storage_alias_attach_stored_definition creates, which was running concurrently); 663dae91bdc4c restored no-parallel on 04946 on 2026-10-11.

@groeneai

Copy link
Copy Markdown
Collaborator

Fix: #126074. The waits now require all 10 and 20 rows; with lines 19 and 20 written late, the old thresholds reproduce the truncated output 5/5 and the new ones pass.

The release branch for 26.10 was created in #126122

Co-Authored-By: Claude Opus 5.5 <[email protected]>
qiuyanjun888 pushed a commit to qiuyanjun888/ClickHouse that referenced this pull request Oct 16, 2026
…ing them

The waits before the two SELECTs required `count() >= 1` and `count() >= 11`,
which only proves that one FileLog batch was committed. The second round
appends lines 1..20 with separate writes, so a batch can start in the middle
of the loop and read a prefix, with the rest arriving in the next batch. On
`Stateless tests (arm_binary, s3 storage, DBReplicated, sequential)` the
SELECT then ran between the part with 11..18 and the part with 19, 20, and
printed 1..18 (PR ClickHouse#125135) or 1..19 (PR ClickHouse#125433).

Wait for every row the following SELECT prints instead (10 and 20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master. Remaining failures on 15fd6d05 are unrelated to this PR:

The ALP tests (05353–05355, 05366), 05359_parquet_testing_corpus and 00900_long_parquet_load_2 pass locally on the merged tree.

alexey-milovidov and others added 2 commits October 21, 2026 03:48
…names

Rename `AlpEncoding.{h,cpp}` to `ALPEncoding.{h,cpp}`, and `AlpTraits`,
`AlpPage`, `AlpDecoder`, `AlpPageEncoder`, `AlpEncoder`, `makeAlpDecoder`,
`makeAlpFloatEncoder`, `makeAlpDoubleEncoder` accordingly. The names from
the specification (`AlpEncoding.md`, `AlpInfo`) are kept as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Oct 21, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now all good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit f1c2aa5 Oct 21, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the parquet-alp-encoding branch October 21, 2026 19:31
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
alexey-milovidov added a commit that referenced this pull request Oct 24, 2026
…out-arrow

Master added the `ALP` encoding of Parquet (#125135),
whose writer was an adapter to `parquet::TypedEncoder` and whose reader used
`arrow::internal::unpack`. Reconcile it with the native writer of this branch:
- `ALPEncoder` now has the same interface as `PlainEncoder` and `DictionaryEncoder`
  (`put`, `estimatedDataEncodedSize`, `flush`), and `lastPageEncoding` instead of `encoding`.
- The `ALP` decoder uses the native `unpackBits`, which is now declared in `Decoding.h`.
- Test `04708_functions_to_subcolumns_file_storages`: keep both the removal of the
  `no-fasttest` tag (this branch) and of `SET enable_analyzer` (master).
mosya415 pushed a commit to mosya415/ClickHouse that referenced this pull request Nov 15, 2026
…Metadata` format

Thrift stores the footer's raw `i32` values of `ColumnMetaData.encodings`
into `std::vector<parquet::format::Encoding::type>`. Arrow's `encodings()`
maps unknown values to `UNDEFINED` (`LoadEnumSafe`), and for those the
fallback added by ClickHouse#125135 looks the Thrift value up in
`_Encoding_VALUES_TO_NAMES`. `find` takes `const int &`, so the enum element
is loaded; a value outside the enum's range is undefined behavior, and
ASan/UBSan builds abort:

    ParquetMetadataInputFormat.cpp:361:85: runtime error: load of value
    4294967295, which is not a valid value for type
    'const parquet::format::Encoding::type'

Look up the raw integer with `thriftEnumToInt`, the memcpy-based helper
the native reader already uses to validate footer and page-header enums.
It moves unchanged from `Reader.cpp` into `Parquet/ThriftUtil.h` so both
can use it. The output is the same for every input: unknown values still
show as `UNDEFINED`, and `ALP` still resolves through the fallback.

The test patches the `encodings` list of a file written by ClickHouse.
The native writer stores each `ColumnChunk` twice (after the chunk's data
and in the footer), and Arrow reads only the footer, so every patch uses
`replaceAll` and the test checks that the unpatched bytes are gone.

Closes ClickHouse#131694

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants