use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class RuleProcessorRuntime method createGroovyScript.
private Script createGroovyScript(Rule rule) {
LOG.info("Creating groovy execution script for rule {} ", rule);
GroovyExpression groovyExpression = new GroovyExpression(rule.getCondition());
GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine();
GroovyScript<Boolean> groovyScript = createHelperGroovyScript(groovyExpression, groovyScriptEngine);
GroovyScript<Collection<StreamlineEvent>> wrapper = new GroovyScript<Collection<StreamlineEvent>>(groovyExpression.asString(), groovyScriptEngine) {
@Override
public Collection<StreamlineEvent> evaluate(StreamlineEvent event) throws ScriptException {
if (groovyScript.evaluate(event)) {
return Collections.singletonList(event);
} else {
return Collections.emptyList();
}
}
};
return wrapper;
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class MergeTransformRuntimeTest method testExecute.
@Test
public void testExecute() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "two");
Map<String, String> defaults = new HashMap<>();
defaults.put("2", "TWO");
defaults.put("3", "THREE");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
TransformRuntime transformRuntime = new MergeTransformRuntime(new MergeTransform(defaults));
List<StreamlineEvent> result = transformRuntime.execute(event);
System.out.println(result);
assertEquals(1, result.size());
assertEquals("two", result.get(0).get("2"));
assertEquals("THREE", result.get(0).get("3"));
}
Aggregations