-
Notifications
You must be signed in to change notification settings - Fork 190
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 for Sink Codecs - Follow up PR to 2881 #2898
Closed
Closed
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1ae457e
-Support for Sink Codecs
umairofficial cad24ed
-Support for Sink Codecs
umairofficial 3f61c27
-Support for Sink Codecs
umairofficial 4eed69e
-Support for Sink Codecs
umairofficial d4d5750
-Support for Sink Codecs
umairofficial 3e8c687
-Support for Sink Codecs
umairofficial 8e2f0c1
-Support for Sink Codecs
umairofficial 7992721
-Support for Sink Codecs
umairofficial 6db256c
-Support for Sink Codecs
umairofficial fe0a435
-Support for Sink Codecs
umairofficial 2a0ba3d
-Support for Sink Codecs
umairofficial 5128915
-Support for Sink Codecs
umairofficial 77aba5e
-Support for Sink Codecs
umairofficial 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,32 @@ | |
package org.opensearch.dataprepper.plugins.codec.avro; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Configuration class for {@link AvroOutputCodec}. | ||
*/ | ||
public class AvroOutputCodecConfig { | ||
|
||
@JsonProperty("schema") | ||
private final String schema; | ||
private String schema; | ||
|
||
public AvroOutputCodecConfig(String schema) { | ||
this.schema = schema; | ||
} | ||
@JsonProperty("schema_file_location") | ||
private String fileLocation; | ||
|
||
@JsonProperty("exclude_keys") | ||
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. Fix indentation 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. done |
||
private List<String> excludeKeys; | ||
|
||
public List<String> getExcludeKeys() { | ||
return excludeKeys; | ||
} | ||
public String getSchema() { | ||
return schema; | ||
} | ||
public String getFileLocation() { | ||
return fileLocation; | ||
} | ||
public void setSchema(String schema) { | ||
this.schema = schema; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...-codecs/src/main/java/org/opensearch/dataprepper/plugins/codec/avro/AvroSchemaParser.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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.dataprepper.plugins.codec.avro; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.avro.Schema; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class AvroSchemaParser { | ||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
private static final Logger LOG = LoggerFactory.getLogger(AvroOutputCodec.class); | ||
|
||
public static Schema parseSchemaFromJsonFile(final String location) throws IOException { | ||
final Map<?, ?> jsonMap; | ||
try { | ||
jsonMap = mapper.readValue(Paths.get(location).toFile(), Map.class); | ||
} catch (FileNotFoundException e) { | ||
LOG.error("Schema file not found, Error: {}", e.getMessage()); | ||
throw new IOException("Can't proceed without schema."); | ||
} | ||
final Map<Object,Object> schemaMap = new HashMap<Object,Object>(); | ||
for (Map.Entry<?, ?> entry : jsonMap.entrySet()) { | ||
schemaMap.put(entry.getKey(), entry.getValue()); | ||
} | ||
try{ | ||
return new Schema.Parser().parse(mapper.writeValueAsString(schemaMap)); | ||
}catch(Exception e) { | ||
LOG.error("Unable to parse schema from the provided schema file, Error: {}", e.getMessage()); | ||
throw new IOException("Can't proceed without schema."); | ||
} | ||
} | ||
} |
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.
There is an implicit assumption here that the schema is always provided as a local file. What if the schema is provided as a file in S3?
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.
Fetching Schema from a file present in S3 or elsewhere wasn't a part of the initial requirements.