use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class ParserConfigFunctions method pruneEmptyStellarTransformers.
private static void pruneEmptyStellarTransformers(SensorParserConfig config) {
List<FieldTransformer> toRemove = new ArrayList<>();
List<FieldTransformer> fieldTransformations = config.getFieldTransformations();
for (FieldTransformer transformer : fieldTransformations) {
if (transformer.getFieldTransformation().getClass().getName().equals(FieldTransformations.STELLAR.getMappingClass().getName()) && transformer.getConfig().isEmpty()) {
toRemove.add(transformer);
}
}
for (FieldTransformer t : toRemove) {
fieldTransformations.remove(t);
}
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class StellarServiceImplTest method applyTransformationsShouldProperlyTransformData.
@Test
public void applyTransformationsShouldProperlyTransformData() {
SensorParserConfig sensorParserConfig = new SensorParserConfig();
FieldTransformer fieldTransformater = new FieldTransformer();
fieldTransformater.setOutput("url_host");
fieldTransformater.setTransformation("STELLAR");
fieldTransformater.setConfig(new LinkedHashMap<String, Object>() {
{
put("url_host", "TO_LOWER(URL_TO_HOST(url))");
}
});
sensorParserConfig.setFieldTransformations(ImmutableList.of(fieldTransformater));
SensorParserContext sensorParserContext = new SensorParserContext();
sensorParserContext.setSensorParserConfig(sensorParserConfig);
sensorParserContext.setSampleData(new HashMap<String, Object>() {
{
put("url", "https://caseystella.com/blog");
}
});
Map<String, Object> results = stellarService.applyTransformations(sensorParserContext);
assertEquals(2, results.size());
assertEquals("https://caseystella.com/blog", results.get("url"));
assertEquals("caseystella.com", results.get("url_host"));
}
Aggregations