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/01/14 08:52:35 UTC
[I] [java] Is there a way to get the length of the data from bytes at a small system cost? [arrow]
zzzzming95 opened a new issue, #39596:
URL: https://github.com/apache/arrow/issues/39596
### 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
Re: [I] [java] Is there a way to get the length of the data from bytes at a small system cost? [arrow]
Posted by "vibhatha (via GitHub)" <gi...@apache.org>.
vibhatha commented on issue #39596:
URL: https://github.com/apache/arrow/issues/39596#issuecomment-1893016316
I would rather stick to high level representations to get the data length. In case of nested data structures, I am not exactly sure how we can get that information just by using bytes.
cc @lidavidm @davisusanibar is there a better way?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [java] Is there a way to get the length of the data from bytes at a small system cost? [arrow]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #39596:
URL: https://github.com/apache/arrow/issues/39596#issuecomment-1893776844
If you need the exact length, then I don't think there is a better way. But this will copy the data at least once. Alternatively, use VectorUnloader to create an ArrowRecordBatch, then sum the lengths of the backing buffers (this may underestimate as it does not include the metadata). You can get a more accurate estimate by reimplementing the logic in MessageSerializer (but skipping parts that actually copy/write data): https://github.com/apache/arrow/blob/d6a8305c3c52abd6c1ed65b6081dea323a4d0247/java/vector/src/main/java/org/apache/arrow/vector/ipc/message/MessageSerializer.java#L248-L281
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org