Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Last active February 6, 2019 21:13
Show Gist options
  • Save brachi-wernick/0230da7e17abdf41f26839b10ea593d3 to your computer and use it in GitHub Desktop.
Save brachi-wernick/0230da7e17abdf41f26839b10ea593d3 to your computer and use it in GitHub Desktop.
simple transformation
@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