apache / apache/arrow-java

[java] Is there a way to get the length of the data from bytes at a small system cost?

Open
#138 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
94
Forks
152
Avg merge
3d 16h
Merged PRs (30d)
11

Description

### 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 fields = Arrays.asList(encodedVector.getField());
List 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

Contributor guide

Open the contributing guide

Research direction

Start with the Java IPC documentation linked in the issue and inspect the shown ArrowStreamWriter, VectorSchemaRoot, MessageSerializer, ReadChannel, and RecordBatch APIs. Compare the serialized byte[] length with RecordBatch.length() and determine whether an existing low-overhead API or a documentation clarification is needed; done means the supported approach and its cost are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.