[Java][IPC] AbstractCompressionCodec.compress() writes prefix=0 for empty buffers, incompatible with C++/Python readers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- java
- Ambito
- data-engineering
Direzione di ricerca
Inizia in vector/src/main/java/org/apache/arrow/vector/compression/AbstractCompressionCodec.java, nel ramo del buffer vuoto, e confronta la gestione del prefisso con il sentinel -1 documentato. Riproduci il caso con una colonna di stringhe contenente esclusivamente stringhe vuote usando LZ4_FRAME o ZSTD, quindi verifica che i reader C++ e Python possano consumare lo stream IPC risultante senza errori di decompressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- Java
- Stelle
- 95
- Fork
- 154
- Merge medio
- 2g 16h
- PR unite (30g)
- 9
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/arrow-java
-
Type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1300 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
apache/arrow-java#1261 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1236 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1230 ·
-
Type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
apache/arrow-java#1205 ·
Tutte le issue di apache/arrow-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100