Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created January 10, 2020 11:18
Show Gist options
  • Save brachi-wernick/cdcadbead163422b2a1cee86c3c18e8b to your computer and use it in GitHub Desktop.
Save brachi-wernick/cdcadbead163422b2a1cee86c3c18e8b to your computer and use it in GitHub Desktop.
Using field config in the DOFN
@ProcessElement
public void processElement(@Element JsonNode jsonNode, ProcessContext context, PipelineOptions options) {
FieldConfigurationOptions fieldConfigurationOptions = options.as(FieldConfigurationOptions.class);
FieldConfigurationLoader fieldsConfigurationProvider = fieldConfigurationOptions.getFieldsConfigurationProvider();
FieldsConfiguration config = fieldsConfigurationProvider.getConfig();
TableRow tableRow = new TableRow();
for (FieldConfig fieldConfig : config.getFields()) {
setFieldByConfig(jsonNode, tableRow, fieldConfig);
}
context.output(tableRow);
}
private void setFieldByConfig(JsonNode jsonNode, TableRow tableRow, FieldConfig fieldConfig) {
JsonNode childNode = getNodeByPath(fieldConfig.getJsonpath(), jsonNode);
if( childNode != null ){
switch (fieldConfig.getType()) {
// converting the value by the type and set it in the tableRow by the fieldConfig.getColumnname()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment