use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class BinFunctionsTest 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(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class MedianAbsoluteDeviationTest 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(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class WindowLookbackTest method testSpecifyingOnlySelector.
@Test
public void testSpecifyingOnlySelector() {
String stellarStatement = "PROFILE_WINDOW('1 hour')";
Map<String, Object> variables = new HashMap<>();
StellarProcessor stellar = new StellarProcessor();
List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
Assert.assertEquals(TimeUnit.HOURS.toMillis(1) / getDurationMs(), periods.size());
}
use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class WindowLookbackTest method test.
public State test(String windowSelector, Date now, Optional<Map<String, Object>> config, Assertions... assertions) {
List<Range<Long>> windowIntervals = WindowProcessor.process(windowSelector).toIntervals(now.getTime());
String stellarStatement = "PROFILE_WINDOW('" + windowSelector + "', now" + (config.isPresent() ? ", config" : "") + ")";
Map<String, Object> variables = new HashMap<>();
variables.put("now", now.getTime());
if (config.isPresent()) {
variables.put("config", config.get());
}
StellarProcessor stellar = new StellarProcessor();
List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
State state = new State(windowIntervals, periods);
for (Assertions assertion : assertions) {
Assert.assertTrue(assertion.name(), assertion.test(state));
}
return state;
}
use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class KafkaFunctionsIntegrationTest method run.
/**
* Runs a Stellar expression.
* @param expr The expression to run.
*/
private Object run(String expr) {
// make the global properties available to the function
Context context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build();
FunctionResolver functionResolver = new SimpleFunctionResolver().withClass(KafkaFunctions.KafkaGet.class).withClass(KafkaFunctions.KafkaPut.class).withClass(KafkaFunctions.KafkaProps.class).withClass(KafkaFunctions.KafkaTail.class);
StellarProcessor processor = new StellarProcessor();
return processor.parse(expr, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), functionResolver, context);
}
Aggregations