Search in sources :

Example 11 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class GeoEnrichmentFunctionsTest method run.

public Object run(String rule, Map<String, Object> variables) throws Exception {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) BeforeClass(org.junit.BeforeClass) ImmutableMap(com.google.common.collect.ImmutableMap) JSONParser(org.json.simple.parser.JSONParser) UnitTestHelper(org.apache.metron.test.utils.UnitTestHelper) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) File(java.io.File) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) Multiline(org.adrianwalker.multilinestring.Multiline) Map(java.util.Map) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) GeoLiteDatabase(org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase) Assert(org.junit.Assert) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 12 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class SimpleHBaseEnrichmentFunctionsTest method run.

public Object run(String rule, Map<String, Object> variables) throws Exception {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) EnrichmentHelper(org.apache.metron.enrichment.converter.EnrichmentHelper) ImmutableMap(com.google.common.collect.ImmutableMap) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) ArrayList(java.util.ArrayList) MockHTable(org.apache.metron.hbase.mock.MockHTable) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) List(java.util.List) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Map(java.util.Map) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) Assert(org.junit.Assert) ParseException(org.apache.metron.stellar.dsl.ParseException) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 13 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class DateFunctionsTest method run.

/**
 * Runs a Stellar expression.
 * @param expr The expression to run.
 */
private Object run(String expr) {
    StellarProcessor processor = new StellarProcessor();
    assertTrue(processor.validate(expr));
    return processor.parse(expr, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT());
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Calendar(java.util.Calendar) Map(java.util.Map) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) ParseException(org.apache.metron.stellar.dsl.ParseException) Assert.assertEquals(org.junit.Assert.assertEquals) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 14 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class MathFunctionsTest method run.

public static Object run(String rule, Map<String, Object> variables) {
    Context context = Context.EMPTY_CONTEXT();
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(v -> variables.get(v), v -> variables.containsKey(v)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) StellarProcessorUtils.runPredicate(org.apache.metron.stellar.common.utils.StellarProcessorUtils.runPredicate) Map(java.util.Map) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) Test(org.junit.Test) HashMap(java.util.HashMap) Assert(org.junit.Assert) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) ParseException(org.apache.metron.stellar.dsl.ParseException) Context(org.apache.metron.stellar.dsl.Context) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 15 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class Microbenchmark method run.

private static void run(int numTimes, StellarStatement statement, Consumer<Long> func) {
    StellarProcessor processor = new StellarProcessor();
    for (int i = 0; i < numTimes; ++i) {
        long start = System.nanoTime();
        processor.parse(statement.expression, statement.variableResolver, statement.functionResolver, statement.context);
        func.accept((System.nanoTime() - start) / 1000);
    }
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor)

Aggregations

StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)22 Context (org.apache.metron.stellar.dsl.Context)11 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)11 Map (java.util.Map)10 StellarFunctions (org.apache.metron.stellar.dsl.StellarFunctions)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Assert (org.junit.Assert)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 List (java.util.List)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 MapVariableResolver (org.apache.metron.stellar.dsl.MapVariableResolver)4 ParseException (org.apache.metron.stellar.dsl.ParseException)4 Before (org.junit.Before)4 StellarPredicateProcessor (org.apache.metron.stellar.common.StellarPredicateProcessor)3 VariableResolver (org.apache.metron.stellar.dsl.VariableResolver)3 JSONObject (org.json.simple.JSONObject)3 Collectors (java.util.stream.Collectors)2 GaussianRandomGenerator (org.apache.commons.math3.random.GaussianRandomGenerator)2