Skip to content
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

Add include_keys and exclude_keys to S3 sink #3122

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add OutputCodecContext for output codecs.
Signed-off-by: Aiden Dai <daixb@amazon.com>
  • Loading branch information
daixba committed Aug 9, 2023
commit 4a2fa2af75cfe8e6d56525479ad4131a7481ede7
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.dataprepper.model.sink;

import java.util.Collections;
import java.util.List;

/**
* Data Prepper Output Codec Context class.
* The context contains information that are shared and may be used among {@link org.opensearch.dataprepper.model.codec.OutputCodec}
*/
public class OutputCodecContext {

private final String tagsTargetKey;

private final List<String> includeKeys;
private final List<String> excludeKeys;

public OutputCodecContext() {
this(null, Collections.emptyList(), Collections.emptyList());
}


public OutputCodecContext(String tagsTargetKey, List<String> includeKeys, List<String> excludeKeys) {
this.tagsTargetKey = tagsTargetKey;
this.includeKeys = includeKeys;
this.excludeKeys = excludeKeys;
}


public static OutputCodecContext fromSinkContext(SinkContext sinkContext) {
if (sinkContext == null) {
return new OutputCodecContext();
}
return new OutputCodecContext(sinkContext.getTagsTargetKey(), sinkContext.getIncludeKeys(), sinkContext.getExcludeKeys());
}

public String getTagsTargetKey() {
return tagsTargetKey;
}

public List<String> getIncludeKeys() {
return includeKeys;
}

public List<String> getExcludeKeys() {
return excludeKeys;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.dataprepper.model.sink;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertNull;

public class OutputCodecContextTest {


@Test
public void testOutputCodecContextBasic() {
final String testTagsTargetKey = RandomStringUtils.randomAlphabetic(6);
final List<String> testIncludeKeys = Collections.emptyList();
final List<String> testExcludeKeys = Collections.emptyList();
OutputCodecContext codecContext = new OutputCodecContext(testTagsTargetKey, testIncludeKeys, testExcludeKeys);
assertThat(codecContext.getTagsTargetKey(), equalTo(testTagsTargetKey));
assertThat(codecContext.getIncludeKeys(), equalTo(testIncludeKeys));
assertThat(codecContext.getExcludeKeys(), equalTo(testExcludeKeys));

OutputCodecContext emptyContext = new OutputCodecContext();
assertNull(emptyContext.getTagsTargetKey());
assertThat(emptyContext.getIncludeKeys(), equalTo(testIncludeKeys));
assertThat(emptyContext.getExcludeKeys(), equalTo(testExcludeKeys));


}

@Test
public void testOutputCodecContextAdapter() {
final String testTagsTargetKey = RandomStringUtils.randomAlphabetic(6);
final List<String> testIncludeKeys = Collections.emptyList();
final List<String> testExcludeKeys = Collections.emptyList();

SinkContext sinkContext = new SinkContext(testTagsTargetKey, null, testIncludeKeys, testExcludeKeys);

OutputCodecContext codecContext = OutputCodecContext.fromSinkContext(sinkContext);
assertThat(codecContext.getTagsTargetKey(), equalTo(testTagsTargetKey));
assertThat(codecContext.getIncludeKeys(), equalTo(testIncludeKeys));
assertThat(codecContext.getExcludeKeys(), equalTo(testExcludeKeys));

OutputCodecContext emptyContext = OutputCodecContext.fromSinkContext(null);
assertNull(emptyContext.getTagsTargetKey());
assertThat(emptyContext.getIncludeKeys(), equalTo(testIncludeKeys));
assertThat(emptyContext.getExcludeKeys(), equalTo(testExcludeKeys));


}
}
Loading