Search in sources :

Example 6 with Memory

use of com.airhacks.enhydrator.transform.Memory in project enhydrator by AdamBien.

the class ConvertToIntAndCopyTest method scenario.

@Test
public void scenario() {
    Row row = new Row();
    row.addColumn(new Column(0, "question", "21"));
    this.input.getRows().add(row);
    Memory result = this.pump.start();
    assertThat(result.getErroneousRowCount(), is(0l));
    assertThat(result.getProcessedRowCount(), is(1l));
    Row first = this.output.getRow(0);
    assertThat(first.getColumns().size(), is(3));
    Column answerColumn = first.getColumnByName("answer");
    assertThat(answerColumn.getValue(), is(42));
    Column originColumn = first.getColumnByName("origin");
    assertThat(originColumn.getValue(), is("21"));
    Column questionColumn = first.getColumnByName("question");
    assertThat(questionColumn.getValue(), is("21"));
}
Also used : Column(com.airhacks.enhydrator.in.Column) Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 7 with Memory

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

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

Memory (com.airhacks.enhydrator.transform.Memory)8 Row (com.airhacks.enhydrator.in.Row)7 Test (org.junit.Test)6 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)5 HashMap (java.util.HashMap)3 Pump (com.airhacks.enhydrator.Pump)2 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)2 Source (com.airhacks.enhydrator.in.Source)2 LogSink (com.airhacks.enhydrator.out.LogSink)2 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Column (com.airhacks.enhydrator.in.Column)1 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)1 RowTransformer (com.airhacks.enhydrator.transform.RowTransformer)1 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1