mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
Write record batch size prefix in Java
Change-Id: I057c329090faa0c2eb5fb65f8566c17130dd2a69
This commit is contained in:
1 parent
72ea42c28c
commit
6a66fc892e
2 files changed
+18
-6
No files matched your search
@@ -123,7 +123,11 @@ public class ArrowReader implements AutoCloseable {
|
||||
if (n != l) {
|
||||
throw new IllegalStateException(n + " != " + l);
|
||||
}
|
||||
RecordBatch recordBatchFB = RecordBatch.getRootAsRecordBatch(buffer.nioBuffer().asReadOnlyBuffer());
|
||||
|
||||
// Record batch flatbuffer is prefixed by its size as int32le
|
||||
final ArrowBuf metadata = buffer.slice(4, recordBatchBlock.getMetadataLength() - 4);
|
||||
RecordBatch recordBatchFB = RecordBatch.getRootAsRecordBatch(metadata.nioBuffer().asReadOnlyBuffer());
|
||||
|
||||
int nodesLength = recordBatchFB.nodesLength();
|
||||
final ArrowBuf body = buffer.slice(recordBatchBlock.getMetadataLength(), (int)recordBatchBlock.getBodyLength());
|
||||
List<ArrowFieldNode> nodes = new ArrayList<>();
|
||||
|
||||
@@ -99,9 +99,10 @@ public class ArrowWriter implements AutoCloseable {
|
||||
public void writeRecordBatch(ArrowRecordBatch recordBatch) throws IOException {
|
||||
checkStarted();
|
||||
align();
|
||||
// write metadata header
|
||||
|
||||
// write metadata header with int32 size prefix
|
||||
long offset = currentPosition;
|
||||
write(recordBatch);
|
||||
write(recordBatch, true);
|
||||
align();
|
||||
// write body
|
||||
long bodyOffset = currentPosition;
|
||||
@@ -166,14 +167,21 @@ public class ArrowWriter implements AutoCloseable {
|
||||
|
||||
private void writeFooter() throws IOException {
|
||||
// TODO: dictionaries
|
||||
write(new ArrowFooter(schema, Collections.<ArrowBlock>emptyList(), recordBatches));
|
||||
write(new ArrowFooter(schema, Collections.<ArrowBlock>emptyList(), recordBatches), false);
|
||||
}
|
||||
|
||||
private long write(FBSerializable writer) throws IOException {
|
||||
private long write(FBSerializable writer, boolean withSizePrefix) throws IOException {
|
||||
FlatBufferBuilder builder = new FlatBufferBuilder();
|
||||
int root = writer.writeTo(builder);
|
||||
builder.finish(root);
|
||||
return write(builder.dataBuffer());
|
||||
|
||||
ByteBuffer buffer = builder.dataBuffer();
|
||||
|
||||
if (withSizePrefix) {
|
||||
writeIntLittleEndian(buffer.remaining());
|
||||
}
|
||||
|
||||
return write(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user