Last active
February 6, 2019 21:13
-
-
Save brachi-wernick/0230da7e17abdf41f26839b10ea593d3 to your computer and use it in GitHub Desktop.
simple transformation
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
@ProcessElement | |
public void processElement(@Element JsonNode> element, OutputReceiver<TableRowWithEvent> out) { | |
TableRow convertedRow = new TableRow(); | |
insertLong(element.get("server_time"), "server_time", convertedRow); | |
insertFloat(element.get("screen_dpi"), "screen_dpi", convertedRow); | |
// more transformation to come | |
context.output(output); | |
} | |
private void insertLong(JsonNode value, String key, TableRow convertedRow) { | |
String valueToInsert = value.asText(); | |
if (valueToInsert != null && !valueToInsert.isEmpty()) { | |
long longValue = Long.parseLong(valueToInsert); | |
convertedRow.set(key, longValue); | |
} | |
} | |
private void insertFloat(JsonNode value, String key, TableRow convertedRow) { | |
String valueToInsert = getStringValue(value); | |
if (valueToInsert != null ) { | |
float floatValue = Float.parseFloat(valueToInsert); | |
convertedRow.set(key, floatValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment