Created
November 20, 2018 20:21
-
-
Save brachi-wernick/3a5bc50c27e2b861e0910ae279a4ba5d to your computer and use it in GitHub Desktop.
buildRecordWithSchema.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
private static GenericRecord buildRecord(LoginAttackCount loginAttackCount) throws IOException { | |
// avro schema avsc file path. | |
String schemaPath = "src/main/java/loginStream/login-attack-count.avsc"; | |
String schemaString; | |
try (FileInputStream inputStream = new FileInputStream(schemaPath)) { | |
schemaString = org.apache.commons.io.IOUtils.toString(inputStream); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
Schema schema = new Schema.Parser().parse(schemaString); | |
GenericData.Record record = new GenericData.Record(schema); | |
// put the elements according to the avro schema. | |
record.put("userName", loginAttackCount.userName); | |
record.put("counter", loginAttackCount.counter); | |
record.put("to", loginAttackCount.to); | |
record.put("start", loginAttackCount.start); | |
return record; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment