Search in sources :

Example 36 with Row

use of com.airhacks.enhydrator.in.Row in project enhydrator by AdamBien.

the class PumpTest method getIntRow.

Row getIntRow() {
    Row row = new Row();
    row.useMemory(new Memory());
    row.addColumn(0, "a", "1");
    row.addColumn(1, "b", "2");
    return row;
}
Also used : Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row)

Example 37 with Row

use of com.airhacks.enhydrator.in.Row in project enhydrator by AdamBien.

the class PumpTest method stopOnError.

@Test(expected = NumberFormatException.class)
public void stopOnError() {
    List<Row> inputRows = new ArrayList<>();
    inputRows.add(getStringRow());
    inputRows.add(getIntRow());
    VirtualSinkSource in = new VirtualSinkSource("in", inputRows);
    VirtualSinkSource out = new VirtualSinkSource();
    Pump cut = new Pump.Engine().from(in).startWith(t -> {
        t.getColumnByName("a").convertToInteger();
        return t;
    }).to(out).build();
    cut.start();
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) ArrayList(java.util.ArrayList) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 38 with Row

use of com.airhacks.enhydrator.in.Row in project enhydrator by AdamBien.

the class Expression method execute.

public Row execute(Row input, String expression) {
    Bindings bindings = ScriptingEnvironmentProvider.create(manager, this.scriptEngineBindings, input);
    try {
        this.expressionListener.accept("Executing: " + expression);
        Object result = this.engine.eval(expression, bindings);
        this.expressionListener.accept("Got result: " + result);
        if (!(result instanceof Row)) {
            return input;
        } else {
            return (Row) result;
        }
    } catch (ScriptException ex) {
        throw new IllegalStateException(ex.getMessage(), ex);
    }
}
Also used : ScriptException(javax.script.ScriptException) Row(com.airhacks.enhydrator.in.Row) Bindings(javax.script.Bindings)

Example 39 with Row

use of com.airhacks.enhydrator.in.Row in project enhydrator by AdamBien.

the class ScriptingEnvironmentProvider method create.

public static Bindings create(ScriptEngineManager scriptEngineManager, Map<String, Object> scriptEngineBindings, Row input) {
    Bindings bindings = scriptEngineManager.getBindings();
    bindings.put("$ROW", input);
    final Row emptyRow = new Row();
    bindings.put("$EMPTY", emptyRow);
    bindings.put("$MEMORY", input.getMemory());
    input.getColumns().forEach(c -> bindings.put(c.getName(), c));
    if (scriptEngineBindings != null) {
        bindings.putAll(scriptEngineBindings);
    }
    return bindings;
}
Also used : Row(com.airhacks.enhydrator.in.Row) Bindings(javax.script.Bindings)

Example 40 with Row

use of com.airhacks.enhydrator.in.Row in project enhydrator by AdamBien.

the class PumpIT method getEntries.

Row getEntries() {
    Row row = new Row();
    row.addColumn(0, "a", "java");
    row.addColumn(1, "b", "tengah");
    return row;
}
Also used : Row(com.airhacks.enhydrator.in.Row)

Aggregations

Row (com.airhacks.enhydrator.in.Row)68 Test (org.junit.Test)54 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)10 Column (com.airhacks.enhydrator.in.Column)8 Memory (com.airhacks.enhydrator.transform.Memory)8 ArrayList (java.util.ArrayList)5 LogSink (com.airhacks.enhydrator.out.LogSink)4 HashMap (java.util.HashMap)4 PipelineTest (com.airhacks.enhydrator.flexpipe.PipelineTest)3 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)3 Source (com.airhacks.enhydrator.in.Source)3 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)3 List (java.util.List)3 Map (java.util.Map)3 Bindings (javax.script.Bindings)3 Pump (com.airhacks.enhydrator.Pump)2 NamedSink (com.airhacks.enhydrator.out.NamedSink)2 RowTransformer (com.airhacks.enhydrator.transform.RowTransformer)2 Date (java.util.Date)2 Function (java.util.function.Function)2