Search in sources :

Example 1 with LookupKey

use of org.apache.metron.enrichment.lookup.LookupKey in project metron by apache.

the class CSVExtractor method extract.

@Override
public Iterable<LookupKV> extract(String line) throws IOException {
    if (ignore(line)) {
        return Collections.emptyList();
    }
    String[] tokens = parser.parseLine(line);
    LookupKey key = converter.toKey(getType(tokens), tokens[indicatorColumn]);
    Map<String, Object> values = new HashMap<>();
    for (Map.Entry<String, Integer> kv : columnMap.entrySet()) {
        values.put(kv.getKey(), tokens[kv.getValue()]);
    }
    return Arrays.asList(new LookupKV(key, converter.toValue(values)));
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) LookupKey(org.apache.metron.enrichment.lookup.LookupKey)

Example 2 with LookupKey

use of org.apache.metron.enrichment.lookup.LookupKey in project metron by apache.

the class LeastRecentlyUsedPrunerIntegrationTest method test.

@Test
public void test() throws Exception {
    long ts = System.currentTimeMillis();
    BloomAccessTracker bat = new BloomAccessTracker("tracker1", 100, 0.03);
    PersistentAccessTracker pat = new PersistentAccessTracker(tableName, "0", atTable, atCF, bat, 0L);
    EnrichmentLookup lookup = new EnrichmentLookup(testTable, cf, pat);
    List<LookupKey> goodKeysHalf = getKeys(0, 5);
    List<LookupKey> goodKeysOtherHalf = getKeys(5, 10);
    Iterable<LookupKey> goodKeys = Iterables.concat(goodKeysHalf, goodKeysOtherHalf);
    List<LookupKey> badKey = getKeys(10, 11);
    EnrichmentConverter converter = new EnrichmentConverter();
    for (LookupKey k : goodKeysHalf) {
        testTable.put(converter.toPut(cf, (EnrichmentKey) k, new EnrichmentValue(new HashMap<String, Object>() {

            {
                put("k", "dummy");
            }
        })));
        Assert.assertTrue(lookup.exists((EnrichmentKey) k, new EnrichmentLookup.HBaseContext(testTable, cf), true));
    }
    pat.persist(true);
    for (LookupKey k : goodKeysOtherHalf) {
        testTable.put(converter.toPut(cf, (EnrichmentKey) k, new EnrichmentValue(new HashMap<String, Object>() {

            {
                put("k", "dummy");
            }
        })));
        Assert.assertTrue(lookup.exists((EnrichmentKey) k, new EnrichmentLookup.HBaseContext(testTable, cf), true));
    }
    testUtil.flush();
    Assert.assertFalse(lookup.getAccessTracker().hasSeen(goodKeysHalf.get(0)));
    for (LookupKey k : goodKeysOtherHalf) {
        Assert.assertTrue(lookup.getAccessTracker().hasSeen(k));
    }
    pat.persist(true);
    {
        testTable.put(converter.toPut(cf, (EnrichmentKey) badKey.get(0), new EnrichmentValue(new HashMap<String, Object>() {

            {
                put("k", "dummy");
            }
        })));
    }
    testUtil.flush();
    Assert.assertFalse(lookup.getAccessTracker().hasSeen(badKey.get(0)));
    Job job = LeastRecentlyUsedPruner.createJob(config, tableName, cf, atTableName, atCF, ts);
    Assert.assertTrue(job.waitForCompletion(true));
    for (LookupKey k : goodKeys) {
        Assert.assertTrue(lookup.exists((EnrichmentKey) k, new EnrichmentLookup.HBaseContext(testTable, cf), true));
    }
    for (LookupKey k : badKey) {
        Assert.assertFalse(lookup.exists((EnrichmentKey) k, new EnrichmentLookup.HBaseContext(testTable, cf), true));
    }
}
Also used : HashMap(java.util.HashMap) BloomAccessTracker(org.apache.metron.enrichment.lookup.accesstracker.BloomAccessTracker) LookupKey(org.apache.metron.enrichment.lookup.LookupKey) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentLookup(org.apache.metron.enrichment.lookup.EnrichmentLookup) EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) PersistentAccessTracker(org.apache.metron.enrichment.lookup.accesstracker.PersistentAccessTracker) Job(org.apache.hadoop.mapreduce.Job) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue)

Aggregations

LookupKey (org.apache.metron.enrichment.lookup.LookupKey)2 HashMap (java.util.HashMap)1 Job (org.apache.hadoop.mapreduce.Job)1 EnrichmentConverter (org.apache.metron.enrichment.converter.EnrichmentConverter)1 EnrichmentKey (org.apache.metron.enrichment.converter.EnrichmentKey)1 EnrichmentValue (org.apache.metron.enrichment.converter.EnrichmentValue)1 EnrichmentLookup (org.apache.metron.enrichment.lookup.EnrichmentLookup)1 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)1 BloomAccessTracker (org.apache.metron.enrichment.lookup.accesstracker.BloomAccessTracker)1 PersistentAccessTracker (org.apache.metron.enrichment.lookup.accesstracker.PersistentAccessTracker)1