Skip to content

Respect range parameter for getObject in presign aware S3 clients #197

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

Merged
merged 1 commit into from
May 15, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ public S3Object getObject(GetObjectRequest getObjectRequest)
return getPresignedUrl("GET", getObjectRequest.getBucketName(), getObjectRequest.getKey())
.map(presigned -> {
PresignedUrlDownloadRequest presignedUrlDownloadRequest = new PresignedUrlDownloadRequest(presigned.url);
Optional.ofNullable(getObjectRequest.getRange())
.ifPresent(range -> presignedUrlDownloadRequest.withRange(range[0], range[1]));
return delegate.download(presignedUrlDownloadRequest).getS3Object();
})
.orElseGet(() -> delegate.getObject(getObjectRequest));
Expand All @@ -638,6 +640,8 @@ public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File destinat
return getPresignedUrl("GET", getObjectRequest.getBucketName(), getObjectRequest.getKey())
.map(presigned -> {
PresignedUrlDownloadRequest presignedUrlDownloadRequest = new PresignedUrlDownloadRequest(presigned.url);
Optional.ofNullable(getObjectRequest.getRange())
.ifPresent(range -> presignedUrlDownloadRequest.withRange(range[0], range[1]));
delegate.download(presignedUrlDownloadRequest, destinationFile);
return presigned.objectMetadata;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public TestDatabaseSecurity(S3Client s3Client, PySparkContainer pySparkContainer
public void testDatabaseSecurity()
throws Exception
{
// create the test bucket
s3Client.createBucket(r -> r.bucket("test"));

createDatabaseAndTable(s3Client, pySparkContainer);

clearInputStreamAndClose(inputToContainerStdin(pySparkContainer.containerId(), "spark.sql(\"select * from %s.%s\").show()".formatted(DATABASE_NAME, TABLE_NAME)), line -> line.equals("| John Galt| 28|"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.trino.aws.proxy.server.testing.containers.PySparkContainer;
import io.trino.aws.proxy.server.testing.harness.BuilderFilter;
import io.trino.aws.proxy.server.testing.harness.TrinoAwsProxyTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.S3Client;

Expand Down Expand Up @@ -54,6 +55,13 @@ public TestPySparkSql(S3Client s3Client, PySparkContainer pySparkContainer)
this.pySparkContainer = requireNonNull(pySparkContainer, "pySparkContainer is null");
}

@BeforeAll
public void setupBucket()
{
// create the test bucket
s3Client.createBucket(r -> r.bucket("test"));
}

@Test
public void testSql()
throws Exception
Expand All @@ -75,12 +83,29 @@ public void testSql()
"spark.sql(\"select * from %s.%s\").show()".formatted(DATABASE_NAME, TABLE_NAME)), line -> line.equals("| c| 30|"));
}

public static void createDatabaseAndTable(S3Client s3Client, PySparkContainer container)
@Test
public void testParquet()
throws Exception
{
// create the test bucket
s3Client.createBucket(r -> r.bucket("test"));
// upload a CSV file
s3Client.putObject(r -> r.bucket("test").key("test_parquet/file.csv"), Path.of(Resources.getResource("test.csv").toURI()));

// read the CSV file and write it as Parquet
clearInputStreamAndClose(inputToContainerStdin(pySparkContainer.containerId(), """
df = spark.read.csv("s3a://test/test_parquet/file.csv")
df.write.parquet("s3a://test/test_parquet/file.parquet")
"""), line -> line.equals(">>> ") || line.matches(".*Write Job [\\w-]+ committed.*"));

// read the Parquet file
clearInputStreamAndClose(inputToContainerStdin(pySparkContainer.containerId(), """
parquetDF = spark.read.parquet("s3a://test/test_parquet/file.parquet")
parquetDF.show()
"""), line -> line.equals("| John Galt| 28|"));
}

public static void createDatabaseAndTable(S3Client s3Client, PySparkContainer container)
throws Exception
{
// upload a CSV file as a potential table
s3Client.putObject(r -> r.bucket("test").key("table/file.csv"), Path.of(Resources.getResource("test.csv").toURI()));

Expand Down