Skip to content

Commit 0406c54

Browse files
author
Alex Jo
committed
WIP
1 parent 4b7197f commit 0406c54

File tree

8 files changed

+561
-226
lines changed

8 files changed

+561
-226
lines changed

lib/trino-filesystem-s3/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
</exclusions>
7474
</dependency>
7575

76+
<dependency>
77+
<groupId>software.amazon.awssdk</groupId>
78+
<artifactId>aws-crt-client</artifactId>
79+
</dependency>
80+
7681
<dependency>
7782
<groupId>software.amazon.awssdk</groupId>
7883
<artifactId>auth</artifactId>

lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import io.trino.filesystem.TrinoInputFile;
2222
import io.trino.filesystem.TrinoOutputFile;
2323
import software.amazon.awssdk.core.exception.SdkException;
24+
import software.amazon.awssdk.services.s3.S3AsyncClient;
2425
import software.amazon.awssdk.services.s3.S3Client;
2526
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
2627
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
2728
import software.amazon.awssdk.services.s3.model.DeleteObjectsResponse;
29+
import software.amazon.awssdk.services.s3.model.InputSerialization;
2830
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
2931
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
32+
import software.amazon.awssdk.services.s3.model.OutputSerialization;
3033
import software.amazon.awssdk.services.s3.model.RequestPayer;
3134
import software.amazon.awssdk.services.s3.model.S3Error;
3235
import software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable;
@@ -44,16 +47,18 @@
4447
import static com.google.common.collect.Multimaps.toMultimap;
4548
import static java.util.Objects.requireNonNull;
4649

47-
final class S3FileSystem
50+
public final class S3FileSystem
4851
implements TrinoFileSystem
4952
{
5053
private final S3Client client;
54+
private final S3AsyncClient asyncClient;
5155
private final S3Context context;
5256
private final RequestPayer requestPayer;
5357

54-
public S3FileSystem(S3Client client, S3Context context)
58+
public S3FileSystem(S3Client client, S3AsyncClient asyncClient, S3Context context)
5559
{
5660
this.client = requireNonNull(client, "client is null");
61+
this.asyncClient = requireNonNull(asyncClient, "asyncClient is null");
5762
this.context = requireNonNull(context, "context is null");
5863
this.requestPayer = context.requestPayer();
5964
}
@@ -70,6 +75,11 @@ public TrinoInputFile newInputFile(Location location, long length)
7075
return new S3InputFile(client, context, new S3Location(location), length);
7176
}
7277

78+
public TrinoInputFile newS3SelectInputFile(Location location, String query, boolean enableScanRange, InputSerialization inputSerialization, OutputSerialization outputSerialization)
79+
{
80+
return new S3SelectInputFile(client, asyncClient, context, new S3Location(location), query, enableScanRange, inputSerialization, outputSerialization);
81+
}
82+
7383
@Override
7484
public TrinoOutputFile newOutputFile(Location location)
7585
{

lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystemFactory.java

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
import jakarta.annotation.PreDestroy;
2121
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
2222
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
23+
import software.amazon.awssdk.http.SdkHttpClient;
2324
import software.amazon.awssdk.http.apache.ApacheHttpClient;
2425
import software.amazon.awssdk.http.apache.ProxyConfiguration;
26+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
27+
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
2528
import software.amazon.awssdk.regions.Region;
29+
import software.amazon.awssdk.services.s3.S3AsyncClient;
30+
import software.amazon.awssdk.services.s3.S3AsyncClientBuilder;
31+
import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
2632
import software.amazon.awssdk.services.s3.S3Client;
2733
import software.amazon.awssdk.services.s3.S3ClientBuilder;
2834
import software.amazon.awssdk.services.sts.StsClient;
@@ -38,13 +44,33 @@ public final class S3FileSystemFactory
3844
implements TrinoFileSystemFactory
3945
{
4046
private final S3Client client;
47+
private final S3AsyncClient asyncClient;
4148
private final S3Context context;
4249

4350
@Inject
4451
public S3FileSystemFactory(S3FileSystemConfig config)
4552
{
4653
S3ClientBuilder s3 = S3Client.builder();
54+
applyS3Properties(s3, config);
55+
s3.httpClient(buildHttpClient(config));
4756

57+
S3AsyncClientBuilder asyncS3 = S3AsyncClient.builder();
58+
applyS3Properties(asyncS3, config);
59+
asyncS3.httpClient(buildAsyncHttpClient(config));
60+
61+
this.client = s3.build();
62+
this.asyncClient = asyncS3.build();
63+
64+
context = new S3Context(
65+
toIntExact(config.getStreamingPartSize().toBytes()),
66+
config.isRequesterPays(),
67+
config.getSseType(),
68+
config.getSseKmsKeyId());
69+
70+
}
71+
72+
private static void applyS3Properties(S3BaseClientBuilder<?, ?> s3, S3FileSystemConfig config)
73+
{
4874
if ((config.getAwsAccessKey() != null) && (config.getAwsSecretKey() != null)) {
4975
s3.credentialsProvider(StaticCredentialsProvider.create(
5076
AwsBasicCredentials.create(config.getAwsAccessKey(), config.getAwsSecretKey())));
@@ -70,7 +96,10 @@ public S3FileSystemFactory(S3FileSystemConfig config)
7096
.asyncCredentialUpdateEnabled(true)
7197
.build());
7298
}
99+
}
73100

101+
private static SdkHttpClient buildHttpClient(S3FileSystemConfig config)
102+
{
74103
ApacheHttpClient.Builder httpClient = ApacheHttpClient.builder()
75104
.maxConnections(config.getMaxConnections());
76105

@@ -83,26 +112,34 @@ public S3FileSystemFactory(S3FileSystemConfig config)
83112
.build());
84113
}
85114

86-
s3.httpClientBuilder(httpClient);
115+
return httpClient.build();
116+
}
87117

88-
this.client = s3.build();
118+
private static SdkAsyncHttpClient buildAsyncHttpClient(S3FileSystemConfig config)
119+
{
120+
AwsCrtAsyncHttpClient.Builder httpClient = AwsCrtAsyncHttpClient.builder();
121+
if (config.getHttpProxy() != null) {
122+
String scheme = config.isHttpProxySecure() ? "https" : "http";
123+
httpClient.proxyConfiguration(software.amazon.awssdk.http.crt.ProxyConfiguration.builder()
124+
.scheme(scheme)
125+
.host(config.getHttpProxy().getHost())
126+
.port(config.getHttpProxy().getPort())
127+
.build());
128+
}
89129

90-
context = new S3Context(
91-
toIntExact(config.getStreamingPartSize().toBytes()),
92-
config.isRequesterPays(),
93-
config.getSseType(),
94-
config.getSseKmsKeyId());
130+
return httpClient.build();
95131
}
96132

97133
@PreDestroy
98134
public void destroy()
99135
{
100136
client.close();
137+
asyncClient.close();
101138
}
102139

103140
@Override
104141
public TrinoFileSystem create(ConnectorIdentity identity)
105142
{
106-
return new S3FileSystem(client, context);
143+
return new S3FileSystem(client, asyncClient, context);
107144
}
108145
}

0 commit comments

Comments
 (0)