Skip to content

Support the bzip2 and xz codecs in the Avro format - #127774

Merged
alexey-milovidov merged 8 commits into
masterfrom
avro-bzip2-xz
Oct 31, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
avro-bzip2-xz

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

The Avro specification lists bzip2 and xz as optional codecs. ClickHouse could not read Avro files that use them (Unknown codec in data file: bzip2), although it already links both libraries. Now they are supported for reading, and can also be used for writing with output_format_avro_codec.

The codecs are implemented in the avro fork (ClickHouse/avro#45) with the Boost.Iostreams bzip2 and lzma filters. These filters are compiled into the avro library, because Boost is added to the build before bzip2 and xz. The xz filter is built without its multithreaded encoder, so writing does not spawn threads.

The test reads the alltypes_plain files from apache/arrow-testing, written by another implementation, does a round trip with several blocks, and checks that a truncated compressed block is rejected (ClickHouse/avro#46 propagates decompressor errors instead of treating them as the end of data). I also checked that files written by ClickHouse with both codecs are read correctly by fastavro.

Closes: #125147
Related: ClickHouse/avro#45
Related: ClickHouse/avro#46
Related: #125134

Changelog category (leave one):

  • Improvement

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

Support the bzip2 and xz codecs in the Avro format, both for reading and for writing (output_format_avro_codec).

🤖 Generated with Claude Code


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

Version info

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

The Avro specification lists them as optional codecs. Reading such files failed
with `Unknown codec in data file`. They can also be written now with
`output_format_avro_codec`. The Boost.Iostreams filters for them are compiled
into the `avro` library, because Boost is added before `bzip2` and `xz`.

The test data files are from `apache/arrow-testing`.

Closes: #125147
Related: ClickHouse/avro#45

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

clickhouse-gh Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [17c15e1]

Summary: ✅


AI Review

Summary

Adds bzip2 and xz compression support for reading and writing Avro files. The previous truncated-stream finding is fixed in the current Avro submodule and covered by a regression test. No unresolved findings.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements submodule changed At least one submodule changed in this PR. labels Oct 25, 2026
Comment thread contrib/avro Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Oct 25, 2026
alexey-milovidov and others added 2 commits October 26, 2026 13:00
Update the `avro` submodule, which now propagates decompressor errors instead of treating them as
the end of data. Previously, a truncated `bzip2` or `xz` block was read successfully when the
decoded records filled the input buffer exactly.

Address review: #127774
Related: ClickHouse/avro#46

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to ClickHouse/avro that referenced this pull request Oct 27, 2026
With `badbit` in the exception mask of the decompressing stream, its read rethrows the error of
the decompressor, e.g. `boost::iostreams::zlib_error`, which is not an `avro::Exception`, so
ClickHouse reported a corrupted `deflate` block as `STD_EXCEPTION` instead of `AVRO_EXCEPTION`.
Wrap it in `IStreamBufferCopyIn`.

Related: ClickHouse/ClickHouse#127774

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits October 27, 2026 11:58
Update the `avro` submodule: after the previous change, a decompressor error of a corrupted
`deflate` block propagated as `boost::iostreams::zlib_error` and was reported as `STD_EXCEPTION`,
which broke `04947_avro_count_from_files_forward_progress`. The decompressor errors are now
wrapped in `avro::Exception`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127774&sha=latest&name_0=PR&name_1=Stateless%20tests%20(amd_debug%2C%20parallel)
Related: ClickHouse/avro#46

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=127774&sha=latest&name_0=PR&name_1=Integration%20tests%20(arm_binary%2C%203%2F4) (test_storage_iceberg_with_spark/test_writes_split_offsets.py::test_writes_split_offsets_read_by_spark, assert len(expected) == 10 got 9; it also fails on master on 2026-10-25 and 2026-10-26) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The other failure, 04947_avro_count_from_files_forward_progress, was caused by this PR (a deflate decompressor error was reported as STD_EXCEPTION instead of AVRO_EXCEPTION). It is fixed in ClickHouse/avro#46 and the submodule is updated.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is in #127787 (open, test-only). The integration harness randomizes max_block_size ([8000, 100000]), and for a value in [8001, 8999] the numbers(10000) insert reaches the Parquet writer as two chunks, which gives 9 row groups instead of 10. The offsets in this failure ([4, 5102, 9629, 14176, 18737, 23311, ...]) match a clickhouse local run with max_block_size in 8065..8072 byte for byte. The PR relaxes the row-group-count precondition to > 1 and keeps the split_offsets check strict. Its CI has not started yet: it needs the can be tested label.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai: the test_writes_split_offsets_read_by_spark failure is tracked by #127787.

The only remaining red check on 56da59a3 is Build profile diff. It failed with LogClusterNotReady: the endpoint never became ready because the CI logs cluster was unavailable, which is an infrastructure problem unrelated to this PR (related: #126200). I re-ran that job. No code changes are needed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The re-run of Build profile diff failed again with LogClusterNotReady: the endpoint never became ready. #128067 has since been merged into master; it reports that job as green when the CI logs cluster is not available. I merged master into this branch to pick up that fix. The merge was clean, and master has not touched the Avro sources or contrib/avro-cmake since the merge base. The groeneai comment above, about the test_writes_split_offsets_read_by_spark failure, is tracked in #127787.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 On af134d26 the Fast test failed in 03536_ch_as_client_and_local with Cannot lock file .../clickhouse-local/status. Another server instance in same directory is already running, and the rest of the workflow was dropped because of it. This PR didn't cause it: the new Avro tests are no-fasttest. 03536_ch_as_client_and_local and 03134_positional_arguments both run clickhouse in local mode without --path or --tmp, so they compete for the shared default data directory. The fix is in #128197. I re-ran the failed jobs of this workflow.

@clickhouse-gh

clickhouse-gh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 17c15e141 with master a018bd2bb (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of dcccc2b59; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

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

33 object files changed (+241.90 KiB total), 2 added.

Object file Master PR Δ
contrib/avro-cmake/CMakeFiles/_avrocpp.dir/__/avro/lang/c++/impl/DataFile.cc.o 521.23 KiB 680.39 KiB +159.16 KiB (+30.54%)
contrib/avro-cmake/CMakeFiles/_avrocpp.dir/__/boost/libs/iostreams/src/bzip2.cpp.o new 41.00 KiB +41.00 KiB
contrib/avro-cmake/CMakeFiles/_avrocpp.dir/__/boost/libs/iostreams/src/lzma.cpp.o new 39.87 KiB +39.87 KiB

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

2474 translation units recompiled, 12660 s compile time in total, 2471 of them have a recent master baseline.

Job report

zoomxi pushed a commit to zoomxi/ClickHouse that referenced this pull request Oct 30, 2026
…house-local`

Tests `03536_ch_as_client_and_local` and `03134_positional_arguments` invoke
the `clickhouse` binary in local mode without `--path` or `--tmp`, so it locks
the persistent data directory `~/.local/share/clickhouse-local`. When two such
invocations run concurrently, one of them fails with `Cannot lock file
.../clickhouse-local/status. Another server instance in same directory is
already running`. Point `HOME` and `XDG_DATA_HOME` at a per-test directory,
as tests `05038_clickhouse_local_default_path` and others already do.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127774&sha=af134d26ecffd69a4d3aea84773369f50b35be87&name_0=PR&name_1=Fast%20test
ClickHouse#127774

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

Copy link
Copy Markdown
Member Author

🕵 On af134d26 two checks were red, and neither is caused by this PR:

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 31, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 31, 2026
Merged via the queue into master with commit 0efaea5 Oct 31, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the avro-bzip2-xz branch October 31, 2026 21:49
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 31, 2026
alexey-milovidov added a commit that referenced this pull request Nov 2, 2026
…`xz` in `Avro`

#127774 added support for the `bzip2` and `xz` codecs
in the `Avro` format, so `data/avro/alltypes_plain.bzip2.avro` and `data/avro/alltypes_plain.xz.avro`
are now read, with the same contents as `data/avro/alltypes_plain.avro`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125134&sha=59dd252d208615c700b477812e3bbb00194d6499&name_0=PR
PR: #125134

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zoomxi pushed a commit to zoomxi/ClickHouse that referenced this pull request Nov 19, 2026
…a home of their own

Since ClickHouse#116042, clickhouse-local without --tmp or --path works in a
designated directory in the home ($XDG_DATA_HOME/clickhouse-local or
~/.local/share/clickhouse-local; ~/Library/Application Support on macOS)
and holds a lock on its `status` file for the whole run. That change gave
$CLICKHOUSE_LOCAL a --tmp, but these three tests start clickhouse-local
through the bare ${CLICKHOUSE_BINARY}, so all their local-mode runs in a
CI job share the job's one default directory. When two of them overlap
(two of these tests at the same time in a parallel job, or two copies of
one test in the flaky check), the second fails with
"Code: 76 ... Cannot lock file .../clickhouse-local/status".
Seen on PR ClickHouse#124882 (03267, Stateless tests (amd_debug, parallel)) and
PR ClickHouse#127774 (03536, Fast test).

Prefix each local-mode line with a per-test HOME under CLICKHOUSE_TMP and
an empty XDG_DATA_HOME (an absolute one wins over HOME on Linux), the same
form ClickHouse#116042 uses in its own default-directory tests. The argv of every
invocation is unchanged, so the dispatch rules of programs/main.cpp that
these tests pin stay covered, including the no-argument rule that only
03267 exercises (`clickhouse < file`); --tmp would have turned that line
into the dash-option rule. Client-mode lines and $CLICKHOUSE_LOCAL lines
are untouched.

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-improvement Pull request with some product improvements 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.

Avro: the bzip2 and xz codecs are not supported

3 participants