[Java] Unexpected RecordBatch length when saving empty table to file with compression
- 主要言語
- Java
- スター
- 94
- フォーク
- 152
- 平均マージ
- 3日 16時間
- マージ済み PR(30日)
- 11
説明
### Describe the bug, including details regarding any error messages, version, and platform.
This might be more of a usage question since I couldn't find anything in the format docs on how to set the length field with compression.
The issue is that if I try to read an empty table with the [Julia extension](https://github.com/apache/arrow-julia) it just hangs. The reason for this seems to be that it [only checks](https://github.com/apache/arrow-julia/blob/e893c327f177f5a4d5efeab831df0fe93ab4ec5b/src/table.jl#L518-L529) the length field in the RecordBatch when deciding whether to attempt to decode and not the length read from the first 8 bytes of the data.
The file created by the code below is readable by both pyarrow and the java implementation, so chances are that the Julia implementation is doing it wrong (I will open an issue there as well). Is there some reference to how one shall interpret the length field in RecordBatch when using compression?
Code to create an empty table in case I'm doing something wrong
```java
public static void main(String[] args) {
try (BufferAllocator allocator = new RootAllocator()) {
Field name = new Field("name", FieldType.nullable(new ArrowType.Utf8()), null);
Field age = new Field("age", FieldType.nullable(new ArrowType.Int(32, true)), null);
Schema schemaPerson = new Schema(asList(name, age));
try(
VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.create(schemaPerson, allocator)
){
vectorSchemaRoot.allocateNew(); // Needed?
vectorSchemaRoot.setRowCount(0); // Needed?
File file = new File("randon_access_to_file.arrow");
try (
FileOutputStream fileOutputStream = new FileOutputStream(file);
ArrowFileWriter writer = new ArrowFileWriter(vectorSchemaRoot, null, fileOutputStream.getChannel(),
null, IpcOption.DEFAULT,
CommonsCompressionFactory.INSTANCE, CompressionUtil.CodecType.ZSTD)
) {
writer.start();
writer.writeBatch();
writer.end();
System.out.println("Record batches written: " + writer.getRecordBlocks().size() + ". Number of rows written: " + vectorSchemaRoot.getRowCount());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
```
When I tried saving a compressed empty table using pyarrow I got 0 as the length field and the Julia implementation could read the table without hanging.
Disclaimer: I don't have a working python installation so I did this though PythonCall. Hopefully I managed to remove all the Julia-isms so that it runs in python:
```python
schema = pa.schema([pa.field('nums', pa.int32())])
with pa.OSFile('bigfile.arrow', 'wb') as sink:
with pa.ipc.new_file(sink, schema, options=pa.ipc.IpcWriteOptions(compression='zstd'))) as writer:
batch = pa.record_batch([pa.array([], type=pa.int32())], schema)
writer.write(batch)
```
### Component(s)
Java
コントリビューションガイド
調査の方向性
まず Java の ArrowFileWriter と、例で使用されている IPC 圧縮処理を調べ、次にその空の圧縮 RecordBatch を pyarrow の出力および Julia reader の table.jl ロジックと比較します。length-field の想定される解釈を確認し、空の圧縮 batch を対象とする regression test を追加します。生成されたファイルが reader をハングさせることなく相互運用できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- data-engineering
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100