Search in sources :

Example 6 with CSVFileSource

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

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

CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)7 LogSink (com.airhacks.enhydrator.out.LogSink)6 Pump (com.airhacks.enhydrator.Pump)5 Source (com.airhacks.enhydrator.in.Source)5 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)5 Test (org.junit.Test)5 Row (com.airhacks.enhydrator.in.Row)3 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)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 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)1 CSVFileSink (com.airhacks.enhydrator.out.CSVFileSink)1 NamedSink (com.airhacks.enhydrator.out.NamedSink)1 DatatypeIndexMapper (com.airhacks.enhydrator.transform.DatatypeIndexMapper)1 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)1 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)1 TargetMapping (com.airhacks.enhydrator.transform.TargetMapping)1