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"));
}
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);
}
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));
}
Aggregations