diff --git a/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3InputStream.java b/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3InputStream.java index d2d0cc0d2612..464e62dbfaf6 100644 --- a/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3InputStream.java +++ b/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3InputStream.java @@ -203,9 +203,17 @@ private void seekStream(boolean forceStreamReset) long skip = nextReadPosition - streamPosition; if (skip <= max(getAvailable(), MAX_SKIP_BYTES)) { // already buffered or seek is small enough - if (doSkip(skip) == skip) { - streamPosition = nextReadPosition; - return; + try { + if (in.skip(skip) == skip) { + streamPosition = nextReadPosition; + return; + } + } + catch (IOException _) { + // reopen the stream below at the requested position + } + catch (AbortedException e) { + throw new InterruptedIOException(); } } } @@ -221,11 +229,6 @@ private void seekStream(boolean forceStreamReset) rangeRequest = request.toBuilder().range(range).build(); } in = client.getObject(rangeRequest); - // a workaround for https://github.com/aws/aws-sdk-java-v2/issues/3538 - if (in.response().contentLength() != null && in.response().contentLength() == 0) { - in.close(); - in = new ResponseInputStream<>(in.response(), nullInputStream()); - } streamPosition = nextReadPosition; } catch (NoSuchKeyException e) { @@ -274,17 +277,6 @@ private int getAvailable() } } - private long doSkip(long n) - throws IOException - { - try { - return in.skip(n); - } - catch (AbortedException e) { - throw new InterruptedIOException(); - } - } - private int doRead() throws IOException {