-
Notifications
You must be signed in to change notification settings - Fork 3k
AWS: Integrate S3 analytics accelerator library #12299
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
jackye1995
merged 4 commits into
apache:main
from
SanjayMarreddi:feat/integrate-analytics-accelerator
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ff2394
AWS: Integrate S3 analytics accelerator library into iceberg-aws
SanjayMarreddi 3316e08
Update aws/src/integration/java/org/apache/iceberg/aws/s3/TestS3FileI…
067a9e4
Update aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java
d0929ee
Update aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
aws/src/main/java/org/apache/iceberg/aws/s3/AnalyticsAcceleratorInputStreamWrapper.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg.aws.s3; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.iceberg.io.SeekableInputStream; | ||
| import software.amazon.s3.analyticsaccelerator.S3SeekableInputStream; | ||
|
|
||
| /** A wrapper to convert {@link S3SeekableInputStream} to Iceberg {@link SeekableInputStream} */ | ||
| class AnalyticsAcceleratorInputStreamWrapper extends SeekableInputStream { | ||
|
|
||
| private final S3SeekableInputStream delegate; | ||
|
|
||
| AnalyticsAcceleratorInputStreamWrapper(S3SeekableInputStream stream) { | ||
| this.delegate = stream; | ||
| } | ||
|
|
||
| @Override | ||
| public int read() throws IOException { | ||
| return this.delegate.read(); | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b) throws IOException { | ||
| return this.delegate.read(b, 0, b.length); | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b, int off, int len) throws IOException { | ||
| return this.delegate.read(b, off, len); | ||
| } | ||
|
|
||
| @Override | ||
| public void seek(long l) throws IOException { | ||
| this.delegate.seek(l); | ||
| } | ||
|
|
||
| @Override | ||
| public long getPos() { | ||
| return this.delegate.getPos(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| this.delegate.close(); | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
aws/src/main/java/org/apache/iceberg/aws/s3/AnalyticsAcceleratorUtil.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg.aws.s3; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
| import java.io.IOException; | ||
| import org.apache.iceberg.exceptions.RuntimeIOException; | ||
| import org.apache.iceberg.io.SeekableInputStream; | ||
| import org.apache.iceberg.util.Pair; | ||
| import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
| import software.amazon.awssdk.services.s3.model.HeadObjectResponse; | ||
| import software.amazon.s3.analyticsaccelerator.ObjectClientConfiguration; | ||
| import software.amazon.s3.analyticsaccelerator.S3SdkObjectClient; | ||
| import software.amazon.s3.analyticsaccelerator.S3SeekableInputStream; | ||
| import software.amazon.s3.analyticsaccelerator.S3SeekableInputStreamConfiguration; | ||
| import software.amazon.s3.analyticsaccelerator.S3SeekableInputStreamFactory; | ||
| import software.amazon.s3.analyticsaccelerator.common.ConnectorConfiguration; | ||
| import software.amazon.s3.analyticsaccelerator.request.ObjectClient; | ||
| import software.amazon.s3.analyticsaccelerator.request.ObjectMetadata; | ||
| import software.amazon.s3.analyticsaccelerator.util.OpenStreamInformation; | ||
| import software.amazon.s3.analyticsaccelerator.util.S3URI; | ||
|
|
||
| class AnalyticsAcceleratorUtil { | ||
|
|
||
| private static final Cache<Pair<S3AsyncClient, S3FileIOProperties>, S3SeekableInputStreamFactory> | ||
| STREAM_FACTORY_CACHE = Caffeine.newBuilder().maximumSize(100).build(); | ||
|
|
||
| private AnalyticsAcceleratorUtil() {} | ||
|
|
||
| public static SeekableInputStream newStream(S3InputFile inputFile) { | ||
| S3URI uri = S3URI.of(inputFile.uri().bucket(), inputFile.uri().key()); | ||
| HeadObjectResponse metadata = inputFile.getObjectMetadata(); | ||
| OpenStreamInformation openStreamInfo = | ||
| OpenStreamInformation.builder() | ||
| .objectMetadata( | ||
| ObjectMetadata.builder() | ||
| .contentLength(metadata.contentLength()) | ||
| .etag(metadata.eTag()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| S3SeekableInputStreamFactory factory = | ||
| STREAM_FACTORY_CACHE.get( | ||
| Pair.of(inputFile.asyncClient(), inputFile.s3FileIOProperties()), | ||
| AnalyticsAcceleratorUtil::createNewFactory); | ||
|
|
||
| try { | ||
| S3SeekableInputStream seekableInputStream = factory.createStream(uri, openStreamInfo); | ||
| return new AnalyticsAcceleratorInputStreamWrapper(seekableInputStream); | ||
| } catch (IOException e) { | ||
| throw new RuntimeIOException( | ||
| e, "Failed to create S3 analytics accelerator input stream for: %s", inputFile.uri()); | ||
| } | ||
| } | ||
|
|
||
| private static S3SeekableInputStreamFactory createNewFactory( | ||
| Pair<S3AsyncClient, S3FileIOProperties> cacheKey) { | ||
| ConnectorConfiguration connectorConfiguration = | ||
| new ConnectorConfiguration(cacheKey.second().s3AnalyticsacceleratorProperties()); | ||
| S3SeekableInputStreamConfiguration streamConfiguration = | ||
| S3SeekableInputStreamConfiguration.fromConfiguration(connectorConfiguration); | ||
| ObjectClientConfiguration objectClientConfiguration = | ||
| ObjectClientConfiguration.fromConfiguration(connectorConfiguration); | ||
|
|
||
| ObjectClient objectClient = new S3SdkObjectClient(cacheKey.first(), objectClientConfiguration); | ||
| return new S3SeekableInputStreamFactory(objectClient, streamConfiguration); | ||
| } | ||
|
|
||
| public static void cleanupCache( | ||
| S3AsyncClient asyncClient, S3FileIOProperties s3FileIOProperties) { | ||
| STREAM_FACTORY_CACHE.invalidate(Pair.of(asyncClient, s3FileIOProperties)); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.