-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARROW-474: [Java] Add initial version of streaming serialized format.
This patch proposes a serialized container format for streaming producer and consumers. The goal is to allow readers and writers to produce/consume arrow data without requiring intermediate buffering. This is similar to the File format but reorganizes the pieces. In particular: - No magic header. It's likely a reader connects to a 'random' stream to read it. - Move footer to header. This includes similar information, including the schema. - ArrowRecordBatches follow one by one. Each is prefixed with an i32 length. The serialization is identical as the File version. - See Stream.fbs for more details. This patch also implements the Java reader/writer. Author: Nong Li <[email protected]> Closes #288 from nongli/streaming and squashes the following commits: 554cc18 [Nong Li] Redo serialization format. 03bee58 [Nong Li] Updates from wes' comments. 7257031 [Nong Li] ARROW-474: [Java] Add initial version of streaming serialized format.
- Loading branch information
1 parent
9b1b397
commit 6811d3f
Showing
13 changed files
with
1,100 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
java/vector/src/main/java/org/apache/arrow/vector/file/ReadChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.arrow.vector.file; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ReadableByteChannel; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.netty.buffer.ArrowBuf; | ||
|
||
public class ReadChannel implements AutoCloseable { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ReadChannel.class); | ||
|
||
private ReadableByteChannel in; | ||
private long bytesRead = 0; | ||
|
||
public ReadChannel(ReadableByteChannel in) { | ||
this.in = in; | ||
} | ||
|
||
public long bytesRead() { return bytesRead; } | ||
|
||
/** | ||
* Reads bytes into buffer until it is full (buffer.remaining() == 0). Returns the | ||
* number of bytes read which can be less than full if there are no more. | ||
*/ | ||
public int readFully(ByteBuffer buffer) throws IOException { | ||
LOGGER.debug("Reading buffer with size: " + buffer.remaining()); | ||
int totalRead = 0; | ||
while (buffer.remaining() != 0) { | ||
int read = in.read(buffer); | ||
if (read < 0) return totalRead; | ||
totalRead += read; | ||
if (read == 0) break; | ||
} | ||
this.bytesRead += totalRead; | ||
return totalRead; | ||
} | ||
|
||
/** | ||
* Reads up to len into buffer. Returns bytes read. | ||
*/ | ||
public int readFully(ArrowBuf buffer, int l) throws IOException { | ||
int n = readFully(buffer.nioBuffer(buffer.writerIndex(), l)); | ||
buffer.writerIndex(n); | ||
return n; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (this.in != null) { | ||
in.close(); | ||
in = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.