Search in sources :

Example 6 with DefaultVariableResolver

use of org.apache.metron.stellar.dsl.DefaultVariableResolver 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 7 with DefaultVariableResolver

use of org.apache.metron.stellar.dsl.DefaultVariableResolver 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 8 with DefaultVariableResolver

use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.

the class StellarComparisonExpressionWithOperatorTest method differentTypesShouldThrowErrorWhenUsingGTE.

@Test(expected = ParseException.class)
public void differentTypesShouldThrowErrorWhenUsingGTE() throws Exception {
    final Map<String, Object> variableMap = new HashMap<>();
    runPredicate("'1' >= 1", new DefaultVariableResolver(variableMap::get, variableMap::containsKey));
}
Also used : HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) Test(org.junit.Test)

Example 9 with DefaultVariableResolver

use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.

the class StellarComparisonExpressionWithOperatorTest method differentTypesShouldThrowErrorWhenUsingLTE.

@Test(expected = ParseException.class)
public void differentTypesShouldThrowErrorWhenUsingLTE() throws Exception {
    final Map<String, Object> variableMap = new HashMap<>();
    runPredicate("'1' <= 1", new DefaultVariableResolver(variableMap::get, variableMap::containsKey));
}
Also used : HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) Test(org.junit.Test)

Example 10 with DefaultVariableResolver

use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.

the class StellarComparisonExpressionWithOperatorTest method differentTypesShouldThrowErrorWhenUsingGT.

@Test(expected = ParseException.class)
public void differentTypesShouldThrowErrorWhenUsingGT() throws Exception {
    final Map<String, Object> variableMap = new HashMap<>();
    runPredicate("1 > '1'", new DefaultVariableResolver(variableMap::get, variableMap::containsKey));
}
Also used : HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) Test(org.junit.Test)

Aggregations

DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)21 Test (org.junit.Test)18 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)14 HashMap (java.util.HashMap)12 Context (org.apache.metron.stellar.dsl.Context)12 Assert (org.junit.Assert)11 Map (java.util.Map)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 StellarFunctions (org.apache.metron.stellar.dsl.StellarFunctions)8 ParseException (org.apache.metron.stellar.dsl.ParseException)7 StellarProcessorUtils.runPredicate (org.apache.metron.stellar.common.utils.StellarProcessorUtils.runPredicate)5 Joiner (com.google.common.base.Joiner)4 ImmutableList (com.google.common.collect.ImmutableList)4 java.util (java.util)4 List (java.util.List)4 Before (org.junit.Before)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ArrayList (java.util.ArrayList)3 StringUtils (org.apache.commons.lang3.StringUtils)3 GaussianRandomGenerator (org.apache.commons.math3.random.GaussianRandomGenerator)2