[Java][IPC] AbstractCompressionCodec.compress() writes prefix=0 for empty buffers, incompatible with C++/Python readers
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- java
調査の方向性
vector/src/main/java/org/apache/arrow/vector/compression/AbstractCompressionCodec.java の空バッファ分岐から始め、プレフィックスの処理を文書化されている -1 sentinel と比較します。LZ4_FRAME または ZSTD を使用して、空文字列のみの string 列でこのケースを再現し、その後、C++ と Python の reader が結果の IPC ストリームを展開エラーなしで読み取れることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
When a buffer has writerIndex == 0 (e.g., a string column where all values
are empty string ""), AbstractCompressionCodec.compress() writes an 8-byte
buffer with uncompressed_length = 0 as a "shortcut for empty buffer":
if (uncompressedBuffer.writerIndex() == 0L) {
// shortcut for empty buffer
compressedBuffer.setLong(0, 0); // prefix = 0
...
}
This has been present since the initial implementation (ARROW-11899, 2021).
The Java decompress() handles this correctly (if size==0 return empty),
but C++ and Python Arrow readers do not recognize prefix=0. They attempt
to decompress 0 bytes of data, which fails:
- C++ (Arrow 1.0.0 ~ latest):
IOError: Lz4 compressed input contains less than one frame - PyArrow 21.0: same error
Reproduction
Write an Arrow IPC stream with LZ4_FRAME (or ZSTD) compression where one
string column has all values = "" (empty string, not null). The string data
buffer has writerIndex = 0, triggering the empty buffer path.
// Writer
ArrowStreamWriter writer = new ArrowStreamWriter(root, null, channel,
IpcOption.DEFAULT, CommonsCompressionFactory.INSTANCE, CodecType.LZ4_FRAME);
// All rows: stringVector.setSafe(i, "".getBytes());
Reading with C++ or Python fails at the first RecordBatch.
Root cause
The Arrow IPC compression format defines:
prefix > 0: compressed data follows, decompress toprefixbytesprefix = -1: buffer stored uncompressed (sentinel)prefix = 0: undefined — not in spec, not handled by C++/Python
Java writes prefix=0 for empty buffers, but only Java itself knows how to
read it back. C++/Python treat it as "0 bytes to decompress" → fail.
Suggested fix
Change the empty buffer path to use -1 sentinel (which all readers support):
if (uncompressedBuffer.writerIndex() == 0L) {
ArrowBuf compressedBuffer = allocator.buffer(SIZE_OF_UNCOMPRESSED_LENGTH);
compressedBuffer.setLong(0, -1L); // Use -1 instead of 0
compressedBuffer.writerIndex(SIZE_OF_UNCOMPRESSED_LENGTH);
uncompressedBuffer.close();
return compressedBuffer;
}
When a reader sees prefix=-1, it returns an empty/zero-length slice — which
is correct for an originally empty buffer.
Environment
- Affected: All Arrow Java versions with IPC compression (1.0.0+)
- Readers that fail: Arrow C++ (all versions), PyArrow (all versions)
- Codec: Both LZ4_FRAME and ZSTD
Related
- #1116 — similar symptom (prefix=0) but different root cause (race condition
in vector reuse, not the intentional empty buffer path) - apache/arrow#15102 — C++ DecompressBuffer fix for prefix=-1 (does not
handle prefix=0)
- 主要言語
- Java
- スター
- 95
- フォーク
- 154
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 11
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/arrow-java のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
apache/arrow-java#1261 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1236 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1230 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
apache/arrow-java#1205 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
apache/arrow-java#1158 ·
apache/arrow-java の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 オープンbug frontend maui-pilot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/eo-graphs#74 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100