Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading large SequenceFile, RCFile, or Avro files #18837

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import static io.airlift.slice.SizeOf.SIZE_OF_SHORT;
import static io.airlift.slice.SizeOf.instanceSize;
import static io.airlift.slice.SizeOf.sizeOf;
import static java.lang.Math.addExact;
import static java.lang.Math.toIntExact;
import static java.util.Objects.requireNonNull;

public final class TrinoDataInputStream
Expand Down Expand Up @@ -86,7 +88,7 @@ public long getReadBytes()
public long getPos()
throws IOException
{
return checkedCast(bufferOffset + bufferPosition);
return addExact(bufferOffset, bufferPosition);
}

public void seek(long newPos)
Expand Down Expand Up @@ -230,10 +232,14 @@ public int read()
public long skip(long length)
throws IOException
{
if (length <= 0) {
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for length == 0, it's obvious.
why also for length < 0? is it worth explanatory comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the behavior specified in the Javadoc and in the default implementation.

}

int availableBytes = availableBytes();
// is skip within the current buffer?
if (availableBytes >= length) {
bufferPosition = checkedCast(bufferPosition + length);
bufferPosition = addExact(bufferPosition, toIntExact(length));
return length;
}

Expand Down Expand Up @@ -398,13 +404,6 @@ private int fillBuffer()
return bufferFill;
}

private static int checkedCast(long value)
{
int result = (int) value;
checkArgument(result == value, "Size is greater than maximum int value");
return result;
}

//
// Unsupported operations
//
Expand Down