Search in sources :

Example 6 with VirtualSinkSource

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

the class PumpTest method scriptEngineBindings.

@Test
public void scriptEngineBindings() {
    List<Row> inputRows = new ArrayList<>();
    inputRows.add(getStringRow());
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("date", new Date());
    VirtualSinkSource in = new VirtualSinkSource("in", inputRows);
    VirtualSinkSource out = new VirtualSinkSource();
    Pump cut = new Pump.Engine().homeScriptFolder(EXISTING_HOME_FOLDER, bindings).from(in).startWith("date_should_exist").to(out).build();
    Memory memory = cut.start();
    assertNotNull(memory.get("date"));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) HashMap(java.util.HashMap) Memory(com.airhacks.enhydrator.transform.Memory) ArrayList(java.util.ArrayList) Row(com.airhacks.enhydrator.in.Row) Date(java.util.Date) Test(org.junit.Test)

Example 7 with VirtualSinkSource

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

the class PumpTest method columnExpressionTransformer.

@Test
public void columnExpressionTransformer() {
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("prefix", "java");
    Row row = new Row();
    row.addColumn(0, "developer", "duke");
    VirtualSinkSource input = new VirtualSinkSource();
    input.addRow(row);
    VirtualSinkSource output = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(input).homeScriptFolder(EXISTING_HOME_FOLDER, bindings).withColumnExpression("developer", "function execute(column){return prefix + ' ' + column}").to(output).build();
    Memory memory = pump.start();
    assertThat(memory.areErrorsOccured(), is(false));
    Row first = output.getRow(0);
    Object expected = "java duke";
    Object actual = first.getColumnValue("developer");
    assertThat(expected, is(actual.toString()));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) HashMap(java.util.HashMap) Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 8 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource 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 9 with VirtualSinkSource

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

the class PipelineTest method getJSONPipeline.

public static Pipeline getJSONPipeline() {
    DestinationMapper targetMapper = new DestinationMapper();
    targetMapper.addMapping(0, new TargetMapping("*", "*"));
    DatatypeIndexMapper datatypeMapper = new DatatypeIndexMapper();
    datatypeMapper.addMapping(1, Datatype.INTEGER);
    Source source = new ScriptableSource("./src/test/files/languages.json", "./src/test/files/converter.js", "UTF-8");
    NamedSink logSink = new LogSink();
    NamedSink virtualSink = new VirtualSinkSource();
    Pipeline origin = new Pipeline("json", "src/test/scripts", null, source);
    origin.addSink(logSink);
    origin.addSink(virtualSink);
    origin.addPreRowTransformation(targetMapper);
    origin.addPreRowTransformation(datatypeMapper);
    origin.addPreRowTransformation(new NashornRowTransformer("src/test/scripts", "encrypt"));
    origin.addPostRowTransformation(new NashornRowTransformer("src/test/scripts", "compress"));
    origin.addFilter("true");
    origin.addExpression("print($ROW); $ROW");
    return origin;
}
Also used : DestinationMapper(com.airhacks.enhydrator.transform.DestinationMapper) LogSink(com.airhacks.enhydrator.out.LogSink) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) TargetMapping(com.airhacks.enhydrator.transform.TargetMapping) NashornRowTransformer(com.airhacks.enhydrator.transform.NashornRowTransformer) NamedSink(com.airhacks.enhydrator.out.NamedSink) DatatypeIndexMapper(com.airhacks.enhydrator.transform.DatatypeIndexMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource)

Example 10 with VirtualSinkSource

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

the class PipelineTest method getCSVPipeline.

public static Pipeline getCSVPipeline() {
    DestinationMapper targetMapper = new DestinationMapper();
    targetMapper.addMapping(0, new TargetMapping("*", "*"));
    DatatypeIndexMapper datatypeMapper = new DatatypeIndexMapper();
    datatypeMapper.addMapping(0, Datatype.DOUBLE);
    Source source = new CSVFileSource("./src/test/files/pyramid.csv", ";", "UTF-8", true);
    NamedSink logSink = new LogSink();
    NamedSink jdbcSink = new VirtualSinkSource();
    ColumnTransformation e1 = new ColumnTransformation("name", "convert", true);
    ColumnTransformation e2 = new ColumnTransformation(42, "compress", true);
    Pipeline origin = new Pipeline("csv", "src/test/scripts", "select * from Coffee where name like ? and strength = ?", source);
    origin.addSink(logSink);
    origin.addSink(jdbcSink);
    origin.addQueryParam("arabica");
    origin.addQueryParam(2);
    origin.addEntryTransformation(e1);
    origin.addEntryTransformation(e2);
    origin.addPreRowTransformation(targetMapper);
    origin.addPreRowTransformation(datatypeMapper);
    origin.addEntryTransformation(new ColumnTransformation("1", "function execute(i){return 42;}", false));
    origin.addPreRowTransformation(new NashornRowTransformer("src/test/scripts", "encrypt"));
    origin.addPostRowTransformation(new NashornRowTransformer("src/test/scripts", "compress"));
    origin.addFilter("true");
    origin.addExpression("print($ROW); $ROW");
    return origin;
}
Also used : DestinationMapper(com.airhacks.enhydrator.transform.DestinationMapper) LogSink(com.airhacks.enhydrator.out.LogSink) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) TargetMapping(com.airhacks.enhydrator.transform.TargetMapping) NashornRowTransformer(com.airhacks.enhydrator.transform.NashornRowTransformer) NamedSink(com.airhacks.enhydrator.out.NamedSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) DatatypeIndexMapper(com.airhacks.enhydrator.transform.DatatypeIndexMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource)

Aggregations

VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)16 Test (org.junit.Test)12 Row (com.airhacks.enhydrator.in.Row)11 LogSink (com.airhacks.enhydrator.out.LogSink)9 Source (com.airhacks.enhydrator.in.Source)7 Pump (com.airhacks.enhydrator.Pump)6 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)6 Memory (com.airhacks.enhydrator.transform.Memory)6 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)4 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)3 NamedSink (com.airhacks.enhydrator.out.NamedSink)3 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Assert.assertThat (org.junit.Assert.assertThat)3 DatatypeIndexMapper (com.airhacks.enhydrator.transform.DatatypeIndexMapper)2 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)2 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)2 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)2