You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "zzzzming95 (via GitHub)" <gi...@apache.org> on 2024/11/26 19:15:28 UTC
[I] [java] Is there a way to get the length of the data from bytes at a small system cost? [arrow-java]
zzzzming95 opened a new issue, #138:
URL: https://github.com/apache/arrow-java/issues/138
### Describe the usage question you have. Please include as many useful details as possible.
[java] Is there a way to get the length of the data from bytes at a small system cost?
Like the arrow doc example, https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format
We generate the arrow data to bytes[] and transfer it.
```
ByteArrayOutputStream out = new ByteArrayOutputStream();
// create VectorSchemaRoot
List<Field> fields = Arrays.asList(encodedVector.getField());
List<FieldVector> vectors = Arrays.asList(encodedVector);
try (VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors)) {
// write data
ArrowStreamWriter writer = new ArrowStreamWriter(root, provider, Channels.newChannel(out));
writer.start();
writer.writeBatch();
writer.end();
}
// gen arrow data as bytep[]
out.toByteArray()
```
I want to get the data length with a small system load(cpu mem).
Now i using this way to get data lengeh:
```
ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray());
ReadChannel readChannel = new ReadChannel(Channels.newChannel(input));
MessageMetadataResult messageMeta = MessageSerializer.readMessage(readChannel);
RecordBatch recordBatch =
(RecordBatch) messageMeta.getMessage().header(new RecordBatch());
input.close();
readChannel.close();
// get data length
recordBatch.length()
```
Is there documentation to guide me on what to do? thanks~
### Component(s)
Java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org