ScriptEngine engine = new ScriptEngineManager().getEngineByName("vtl");
Bindings bindings = new SimpleBindings();
InMemoryDataset dataset = new InMemoryDataset(
List.of(
Map.of("var1", "x", "var2", "y", "var3", 5),
Map.of("var1", "xx", "var2", "yy", "var3", 10)
),
Map.of("var1", String.class, "var2", String.class, "var3", Long.class),
Map.of("var1", Role.IDENTIFIER, "var2", Role.ATTRIBUTE, "var3", Role.MEASURE)
);
bindings.put("a", 1);
bindings.put("ds", dataset);
engine.setBindings(b, ScriptContext.ENGINE_SCOPE);
try {
engine.eval("b := a + 1; " +
"ds1 := ds;" +
"ds2 <- ds;");
} catch (VtlScriptException e) {
logger.warn("Eval failed: ", e);
}
Long result = (Long) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("b");
Dataset ds1 = (Dataset) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("ds1");
PersistentDataset result = (PersistentDataset) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("ds2");