use of com.hortonworks.streamline.streams.layout.component.impl.normalization.FieldValueGenerator in project streamline by hortonworks.
the class NormalizationBoltTest method createFieldBasedNormalizationProcessor.
public static NormalizationProcessor createFieldBasedNormalizationProcessor(String outputStreamId) throws NormalizationException {
Map<String, NormalizationConfig> inputStreamsWithConfig = new HashMap<>();
Schema.Field tempField = new Schema.Field("temp", Schema.Type.INTEGER);
Schema inputSchema = Schema.of(tempField, new Schema.Field("foo", Schema.Type.STRING));
Transformer transformer = new Transformer(tempField, new Schema.Field("temperature", Schema.Type.FLOAT));
transformer.setConverterScript("new Float((temp-32)*5/9f)");
List<Transformer> transformers = Collections.singletonList(transformer);
List<String> filters = Collections.singletonList("foo");
List<FieldValueGenerator> fieldValueGenerators = Collections.singletonList(new FieldValueGenerator(new Schema.Field("new-field", Schema.Type.STRING), "new value"));
FieldBasedNormalizationConfig fieldBasedNormalizationConfig = new FieldBasedNormalizationConfig(inputSchema, transformers, filters, fieldValueGenerators);
inputStreamsWithConfig.put(INPUT_STREAM_ID, fieldBasedNormalizationConfig);
Stream declaredOutputStream = new Stream(outputStreamId, OUTPUT_SCHEMA_FIELDS);
NormalizationProcessor normalizationProcessor = new NormalizationProcessor(inputStreamsWithConfig, declaredOutputStream, NormalizationProcessor.Type.fineGrained);
normalizationProcessor.addOutputStream(declaredOutputStream);
return normalizationProcessor;
}
Aggregations