apache / apache/arrow-java

[Java] Unexpected RecordBatch length when saving empty table to file with compression

未关闭
#194 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: bug
主要语言
Java
星标
94
派生
152
平均合并
3 天 16 小时
30 天内合并 PR
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 逻辑进行比较。确认预期的长度字段解释,并添加一个覆盖空压缩 batch 的回归测试;当生成的文件能够互操作且 reader 不会挂起时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
data-engineering
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。