-
Notifications
You must be signed in to change notification settings - Fork 202
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
Correctly add compression extensions to the generated S3 sink keys #3196
Merged
dlvenable
merged 1 commit into
opensearch-project:main
from
dlvenable:3158-compression-extension
Aug 21, 2023
Merged
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
...s/s3-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/ExtensionProvider.java
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
public interface ExtensionProvider { | ||
String getExtension(); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...k/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/StandardExtensionProvider.java
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.opensearch.dataprepper.model.codec.OutputCodec; | ||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionOption; | ||
|
||
class StandardExtensionProvider implements ExtensionProvider { | ||
private final String extension; | ||
|
||
static ExtensionProvider create(OutputCodec outputCodec, CompressionOption compressionOption) { | ||
|
||
String codecExtension = outputCodec.getExtension(); | ||
|
||
if(outputCodec.isCompressionInternal()) { | ||
return new StandardExtensionProvider(codecExtension); | ||
} | ||
|
||
String extension = compressionOption.getExtension() | ||
.map(compressionExtension -> codecExtension + "." + compressionExtension) | ||
.orElse(codecExtension); | ||
|
||
|
||
return new StandardExtensionProvider(extension); | ||
} | ||
|
||
private StandardExtensionProvider(String extension) { | ||
this.extension = extension; | ||
} | ||
|
||
@Override | ||
public String getExtension() { | ||
return extension; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...c/test/java/org/opensearch/dataprepper/plugins/sink/s3/StandardExtensionProviderTest.java
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.dataprepper.model.codec.OutputCodec; | ||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionOption; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class StandardExtensionProviderTest { | ||
|
||
@Mock | ||
private OutputCodec outputCodec; | ||
|
||
@Mock | ||
private CompressionOption compressionOption; | ||
|
||
private String codecExtension; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
codecExtension = UUID.randomUUID().toString(); | ||
} | ||
|
||
@Test | ||
void getExtension_returns_extension_of_codec_when_compression_internal() { | ||
when(outputCodec.getExtension()).thenReturn(codecExtension); | ||
when(outputCodec.isCompressionInternal()).thenReturn(true); | ||
|
||
ExtensionProvider extensionProvider = StandardExtensionProvider.create(outputCodec, compressionOption); | ||
assertThat(extensionProvider, notNullValue()); | ||
assertThat(extensionProvider.getExtension(), equalTo(codecExtension)); | ||
|
||
verify(compressionOption, never()).getExtension(); | ||
} | ||
|
||
@Test | ||
void getExtension_returns_extension_of_codec_compression_has_no_extension() { | ||
when(outputCodec.getExtension()).thenReturn(codecExtension); | ||
when(compressionOption.getExtension()).thenReturn(Optional.empty()); | ||
|
||
ExtensionProvider extensionProvider = StandardExtensionProvider.create(outputCodec, compressionOption); | ||
assertThat(extensionProvider, notNullValue()); | ||
assertThat(extensionProvider.getExtension(), equalTo(codecExtension)); | ||
|
||
verify(compressionOption).getExtension(); | ||
} | ||
|
||
@Test | ||
void getExtension_returns_extension_of_codec_compression_has_extension() { | ||
String compressionExtension = UUID.randomUUID().toString(); | ||
when(outputCodec.getExtension()).thenReturn(codecExtension); | ||
when(compressionOption.getExtension()).thenReturn(Optional.of(compressionExtension)); | ||
|
||
ExtensionProvider extensionProvider = StandardExtensionProvider.create(outputCodec, compressionOption); | ||
assertThat(extensionProvider, notNullValue()); | ||
assertThat(extensionProvider.getExtension(), equalTo(codecExtension + "." + compressionExtension)); | ||
} | ||
|
||
} |
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
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.
Will the configured extension be ignored if there is a internal compression?
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.
Yes, it will be ignored.
With internal compression the file itself is not compressed. Different parts are independently compressed. A user should not try to run it through GZip/Snappy decompression.
With Parquet specifically, the compression is stored as metadata inside the file. And compressed files retain the
.parquet
extension.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.
This test verifies that exact behavior:
getExtension_returns_extension_of_codec_when_compression_internal
.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.
Thanks for the clarity