-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Support S3 Select on native readers #17522
Closed
+1,752
−287
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
766a546
Fix JSON S3 select queries with quote characters
alexjo2144 3e73bca
Disable S3 Select pushdown on decimal columns
alexjo2144 d5aea6b
Put S3 Select for CSV files behind an experimental flag
alexjo2144 c65d4ba
empty
alexjo2144 4b7197f
Support S3 Select on native readers
alexjo2144 0406c54
WIP
alexjo2144 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,15 @@ | |
import io.trino.filesystem.TrinoInputFile; | ||
import io.trino.filesystem.TrinoOutputFile; | ||
import software.amazon.awssdk.core.exception.SdkException; | ||
import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest; | ||
import software.amazon.awssdk.services.s3.model.DeleteObjectsResponse; | ||
import software.amazon.awssdk.services.s3.model.InputSerialization; | ||
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request; | ||
import software.amazon.awssdk.services.s3.model.ObjectIdentifier; | ||
import software.amazon.awssdk.services.s3.model.OutputSerialization; | ||
import software.amazon.awssdk.services.s3.model.RequestPayer; | ||
import software.amazon.awssdk.services.s3.model.S3Error; | ||
import software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable; | ||
|
@@ -44,16 +47,18 @@ | |
import static com.google.common.collect.Multimaps.toMultimap; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
final class S3FileSystem | ||
public final class S3FileSystem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to make the constructor package private with this change |
||
implements TrinoFileSystem | ||
{ | ||
private final S3Client client; | ||
private final S3AsyncClient asyncClient; | ||
private final S3Context context; | ||
private final RequestPayer requestPayer; | ||
|
||
public S3FileSystem(S3Client client, S3Context context) | ||
public S3FileSystem(S3Client client, S3AsyncClient asyncClient, S3Context context) | ||
{ | ||
this.client = requireNonNull(client, "client is null"); | ||
this.asyncClient = requireNonNull(asyncClient, "asyncClient is null"); | ||
this.context = requireNonNull(context, "context is null"); | ||
this.requestPayer = context.requestPayer(); | ||
} | ||
|
@@ -70,6 +75,11 @@ public TrinoInputFile newInputFile(Location location, long length) | |
return new S3InputFile(client, context, new S3Location(location), length); | ||
} | ||
|
||
public TrinoInputFile newS3SelectInputFile(Location location, String query, boolean enableScanRange, InputSerialization inputSerialization, OutputSerialization outputSerialization) | ||
{ | ||
return new S3SelectInputFile(client, asyncClient, context, new S3Location(location), query, enableScanRange, inputSerialization, outputSerialization); | ||
} | ||
|
||
@Override | ||
public TrinoOutputFile newOutputFile(Location location) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,15 @@ | |
import jakarta.annotation.PreDestroy; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.apache.ApacheHttpClient; | ||
import software.amazon.awssdk.http.apache.ProxyConfiguration; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
import software.amazon.awssdk.services.s3.S3AsyncClientBuilder; | ||
import software.amazon.awssdk.services.s3.S3BaseClientBuilder; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.S3ClientBuilder; | ||
import software.amazon.awssdk.services.sts.StsClient; | ||
|
@@ -38,13 +44,33 @@ public final class S3FileSystemFactory | |
implements TrinoFileSystemFactory | ||
{ | ||
private final S3Client client; | ||
private final S3AsyncClient asyncClient; | ||
private final S3Context context; | ||
|
||
@Inject | ||
public S3FileSystemFactory(S3FileSystemConfig config) | ||
{ | ||
S3ClientBuilder s3 = S3Client.builder(); | ||
applyS3Properties(s3, config); | ||
s3.httpClient(buildHttpClient(config)); | ||
|
||
S3AsyncClientBuilder asyncS3 = S3AsyncClient.builder(); | ||
applyS3Properties(asyncS3, config); | ||
asyncS3.httpClient(buildAsyncHttpClient(config)); | ||
|
||
this.client = s3.build(); | ||
this.asyncClient = asyncS3.build(); | ||
|
||
context = new S3Context( | ||
toIntExact(config.getStreamingPartSize().toBytes()), | ||
config.isRequesterPays(), | ||
config.getSseType(), | ||
config.getSseKmsKeyId()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing blank line |
||
} | ||
|
||
private static void applyS3Properties(S3BaseClientBuilder<?, ?> s3, S3FileSystemConfig config) | ||
{ | ||
if ((config.getAwsAccessKey() != null) && (config.getAwsSecretKey() != null)) { | ||
s3.credentialsProvider(StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create(config.getAwsAccessKey(), config.getAwsSecretKey()))); | ||
|
@@ -70,7 +96,10 @@ public S3FileSystemFactory(S3FileSystemConfig config) | |
.asyncCredentialUpdateEnabled(true) | ||
.build()); | ||
} | ||
} | ||
|
||
private static SdkHttpClient buildHttpClient(S3FileSystemConfig config) | ||
{ | ||
ApacheHttpClient.Builder httpClient = ApacheHttpClient.builder() | ||
.maxConnections(config.getMaxConnections()); | ||
|
||
|
@@ -83,26 +112,34 @@ public S3FileSystemFactory(S3FileSystemConfig config) | |
.build()); | ||
} | ||
|
||
s3.httpClientBuilder(httpClient); | ||
return httpClient.build(); | ||
} | ||
|
||
this.client = s3.build(); | ||
private static SdkAsyncHttpClient buildAsyncHttpClient(S3FileSystemConfig config) | ||
{ | ||
AwsCrtAsyncHttpClient.Builder httpClient = AwsCrtAsyncHttpClient.builder(); | ||
if (config.getHttpProxy() != null) { | ||
String scheme = config.isHttpProxySecure() ? "https" : "http"; | ||
httpClient.proxyConfiguration(software.amazon.awssdk.http.crt.ProxyConfiguration.builder() | ||
.scheme(scheme) | ||
.host(config.getHttpProxy().getHost()) | ||
.port(config.getHttpProxy().getPort()) | ||
.build()); | ||
} | ||
|
||
context = new S3Context( | ||
toIntExact(config.getStreamingPartSize().toBytes()), | ||
config.isRequesterPays(), | ||
config.getSseType(), | ||
config.getSseKmsKeyId()); | ||
return httpClient.build(); | ||
} | ||
|
||
@PreDestroy | ||
public void destroy() | ||
{ | ||
client.close(); | ||
asyncClient.close(); | ||
} | ||
|
||
@Override | ||
public TrinoFileSystem create(ConnectorIdentity identity) | ||
{ | ||
return new S3FileSystem(client, context); | ||
return new S3FileSystem(client, asyncClient, context); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to use AWS CRT since it's in C and thus goes through JNI