Search in sources :

Example 6 with Pump

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

the class CsvCharsetTest method fromJSONToCSVWithCharset.

@Test
public void fromJSONToCSVWithCharset() throws FileNotFoundException {
    CSVFileSource source = new CSVFileSource(INPUT + "utf8-characters.csv", sourceDelimiter, sourceCharsetName, sourceContainsHeaders);
    String fileName = getFileName();
    final CSVFileSink csvFileSink = new CSVFileSink(sinkName, fileName, sinkDelimiter, sinkUseNamesAsHeaders, sinkAppend, "UTF-8");
    // do the test
    Pump pumpOut = new Pump.Engine().from(source).to(new LogSink()).to(csvFileSink).build();
    pumpOut.start();
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Pump(com.airhacks.enhydrator.Pump) CSVFileSink(com.airhacks.enhydrator.out.CSVFileSink) Test(org.junit.Test)

Example 7 with Pump

use of com.airhacks.enhydrator.Pump 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

Pump (com.airhacks.enhydrator.Pump)7 LogSink (com.airhacks.enhydrator.out.LogSink)7 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)6 Source (com.airhacks.enhydrator.in.Source)6 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)6 Test (org.junit.Test)5 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)3 Row (com.airhacks.enhydrator.in.Row)2 CSVFileSink (com.airhacks.enhydrator.out.CSVFileSink)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 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1 Path (java.nio.file.Path)1