Search in sources :

Example 6 with Source

use of com.airhacks.enhydrator.in.Source 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)

Example 7 with Source

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

the class ReadJDKVersionsTest method readFromCSV.

@Test
public void readFromCSV() {
    Source input = new CSVFileSource("./src/test/files/jdk-dates.csv", ";", "UTF-8", true);
    VirtualSinkSource output = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(input).startWith(new SkipFirstRow()).startWith(new DatatypeNameMapper().addMapping("Year", Datatype.INTEGER)).filter("$ROW.getColumnValue('Year') > 2000").to(new LogSink()).to(output).build();
    Memory memory = pump.start();
    Assert.assertFalse(memory.areErrorsOccured());
    List<Row> rows = output.getRows();
    assertFalse(rows.isEmpty());
    Row first = rows.get(1);
    Object year = first.getColumnValue("Year");
    System.out.println("The year is: " + year);
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Example 8 with Source

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

the class CSVImportTest method getSource.

VirtualSinkSource getSource(final String fileName) {
    Source source = new CSVFileSource(fileName, ";", "UTF-8", true);
    VirtualSinkSource vss = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(source).to(vss).to(new LogSink()).build();
    pump.start();
    return vss;
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Source(com.airhacks.enhydrator.in.Source) Pump(com.airhacks.enhydrator.Pump)

Example 9 with Source

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

the class FromJsonToCSVTest method filterAndCastFromCSVFileToLog.

@Test
public void filterAndCastFromCSVFileToLog() {
    Source source = new CSVFileSource(INPUT + "/languages.csv", ";", "utf-8", true);
    VirtualSinkSource sink = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(source).filter("$ROW.getColumnValue('language') === 'java'").startWith(new DatatypeNameMapper().addMapping("rank", Datatype.INTEGER)).to(sink).to(new LogSink()).build();
    Memory memory = pump.start();
    assertFalse(memory.areErrorsOccured());
    assertThat(memory.getProcessedRowCount(), is(5l));
    //expecting only "java" language
    assertThat(sink.getNumberOfRows(), is(1));
    String languageValue = (String) sink.getRow(0).getColumnValue("language");
    assertThat(languageValue, is("java"));
    //expecting "java" having rank 1 as Integer
    Object rankValue = sink.getRow(0).getColumnValue("rank");
    assertTrue(rankValue instanceof Integer);
    assertThat((Integer) rankValue, is(1));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Aggregations

Source (com.airhacks.enhydrator.in.Source)9 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)9 LogSink (com.airhacks.enhydrator.out.LogSink)9 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)8 Pump (com.airhacks.enhydrator.Pump)6 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)6 Test (org.junit.Test)4 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)3 NamedSink (com.airhacks.enhydrator.out.NamedSink)3 DatatypeIndexMapper (com.airhacks.enhydrator.transform.DatatypeIndexMapper)3 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)3 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)3 TargetMapping (com.airhacks.enhydrator.transform.TargetMapping)3 Row (com.airhacks.enhydrator.in.Row)2 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)2 Memory (com.airhacks.enhydrator.transform.Memory)2 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)2 NonRecursiveTree (com.airhacks.enhydrator.functions.NonRecursiveTree)1 CSVFileSink (com.airhacks.enhydrator.out.CSVFileSink)1 ScriptableSink (com.airhacks.enhydrator.out.ScriptableSink)1