Created
January 10, 2020 11:18
-
-
Save brachi-wernick/cdcadbead163422b2a1cee86c3c18e8b to your computer and use it in GitHub Desktop.
Using field config in the DOFN
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 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