use of com.airhacks.enhydrator.transform.DatatypeNameMapper in project enhydrator by AdamBien.
the class ConvertToIntAndCopyTest method init.
@Before
public void init() {
this.input = new VirtualSinkSource();
this.output = new VirtualSinkSource();
//map column answer to Integer
final DatatypeNameMapper datatypeMapper = new DatatypeNameMapper();
datatypeMapper.addMapping("answer", Datatype.INTEGER);
//Copy column question to answer and origin
ColumnCopier columnCopier = new ColumnCopier();
columnCopier.addMapping("question", "answer", "origin");
this.pump = new Pump.Engine().startWith(columnCopier).startWith(datatypeMapper).with("answer", (c) -> {
Integer columnValue = (Integer) c;
return columnValue * 2;
}).from(input).to(output).to(new LogSink()).build();
}
use of com.airhacks.enhydrator.transform.DatatypeNameMapper 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.DatatypeNameMapper 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