Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions java/core/src/java/org/apache/orc/impl/InStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ public void seek(long desired) throws IOException {
} else {
for (DiskRangeList curRange = bytes; curRange != null;
curRange = curRange.next) {
// Accept this stream's logical end when later ranges belong to other streams.
boolean isLogicalEnd =
desired == length && positionFile == curRange.getEnd();
if (curRange.getOffset() <= positionFile &&
(curRange.next == null ? positionFile <= curRange.getEnd() :
positionFile < curRange.getEnd())) {
(isLogicalEnd ||
(curRange.next == null ? positionFile <= curRange.getEnd() :
positionFile < curRange.getEnd()))) {
position = desired;
setCurrent(curRange, true);
return;
Expand Down
13 changes: 13 additions & 0 deletions java/core/src/test/org/apache/orc/impl/TestInStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,19 @@ public long getNext() {
}
}

@Test
public void testSeekToLogicalEndWithLaterDiskRange() throws IOException {
BufferChunk streamRange = new BufferChunk(ByteBuffer.allocate(10), 100);
streamRange.insertAfter(new BufferChunk(ByteBuffer.allocate(10), 120));
try (InStream.UncompressedStream stream =
new InStream.UncompressedStream("test", streamRange, 100, 10)) {
stream.seek(10);
assertSame(streamRange, stream.currentRange);
assertEquals(0, stream.available());
assertEquals(-1, stream.read());
}
}

private static byte[] input(int... data) {
byte[] result = new byte[data.length];
for(int i = 0; i < data.length; ++i) {
Expand Down