use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class BulkLoadMapper method map.
@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
for (LookupKV results : extractor.extract(value.toString())) {
if (results != null) {
Put put = converter.toPut(columnFamily, results.getKey(), results.getValue());
write(new ImmutableBytesWritable(results.getKey().toBytes()), put, context);
}
}
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class LocalImporter method toPut.
public List<Put> toPut(String line, Extractor extractor, String cf, HbaseConverter converter) throws IOException {
List<Put> ret = new ArrayList<>();
Iterable<LookupKV> kvs = extractor.extract(line);
for (LookupKV kv : kvs) {
Put put = converter.toPut(cf, kv.getKey(), kv.getValue());
ret.add(put);
}
return ret;
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class ExtractorTest method testDummyExtractor.
@Test
public void testDummyExtractor() throws IllegalAccessException, InstantiationException, ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException {
Extractor extractor = Extractors.create(DummyExtractor.class.getName());
LookupKV results = Iterables.getFirst(extractor.extract(null), null);
EnrichmentKey key = (EnrichmentKey) results.getKey();
EnrichmentValue value = (EnrichmentValue) results.getValue();
Assert.assertEquals("dummy", key.indicator);
Assert.assertEquals("type", key.type);
Assert.assertEquals("dummy", value.getMetadata().get("indicator"));
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class ExtractorTest method testExtractionLoading.
@Test
public void testExtractionLoading() throws Exception {
/**
* config:
* {
* "config" : {}
* ,"extractor" : "org.apache.metron.dataloads.extractor.ExtractorTest$DummyExtractor"
* }
*/
String config = "{\n" + " \"config\" : {}\n" + " ,\"extractor\" : \"org.apache.metron.dataloads.extractor.ExtractorTest$DummyExtractor\"\n" + " }";
ExtractorHandler handler = ExtractorHandler.load(config);
LookupKV results = Iterables.getFirst(handler.getExtractor().extract(null), null);
EnrichmentKey key = (EnrichmentKey) results.getKey();
EnrichmentValue value = (EnrichmentValue) results.getValue();
Assert.assertEquals("dummy", key.indicator);
Assert.assertEquals("type", key.type);
Assert.assertEquals("dummy", value.getMetadata().get("indicator"));
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class TransformFilterExtractorDecoratorTest method transforms_values_and_indicators.
@Test
public void transforms_values_and_indicators() throws IOException {
final String indicatorVal = "val2";
EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", indicatorVal);
EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {
{
put("foo", "val1");
put("bar", indicatorVal);
put("baz", "val3");
}
});
LookupKV lkv = new LookupKV<>(lookupKey, lookupValue);
List<LookupKV> extractedLkvs = new ArrayList<>();
extractedLkvs.add(lkv);
Mockito.when(extractor.extract("val1,val2,val3")).thenReturn(extractedLkvs);
Iterable<LookupKV> extracted = decorator.extract("val1,val2,val3");
EnrichmentKey expectedLookupKey = new EnrichmentKey("testenrichment", "VAL2");
EnrichmentValue expectedLookupValue = new EnrichmentValue(new HashMap<String, Object>() {
{
put("foo", "VAL1");
put("bar", "val2");
put("baz", "val3");
put("newvar", "VAL1");
put("lowernewvar", "val1");
}
});
LookupKV expectedLkv = new LookupKV<>(expectedLookupKey, expectedLookupValue);
List<LookupKV> expectedLkvs = new ArrayList<>();
expectedLkvs.add(expectedLkv);
Assert.assertThat(extracted, CoreMatchers.equalTo(expectedLkvs));
}
Aggregations