use of com.airhacks.enhydrator.in.Column in project enhydrator by AdamBien.
the class ExpressionTest method accessToColumn.
@Test
public void accessToColumn() {
Row row = new Row();
final String inputValue = "duke";
row.addColumn(-1, "chief", inputValue);
Row result = this.cut.execute(row, "$EMPTY.addColumn(-1,'new_duke',chief.value + '_modified');$EMPTY;");
Column column = result.getColumnByName("new_duke");
assertNotNull(column);
Object value = column.getValue();
assertNotNull(value);
assertThat(value, is(inputValue + "_modified"));
}
use of com.airhacks.enhydrator.in.Column in project enhydrator by AdamBien.
the class FunctionScriptLoaderTest method bindingsAvailable.
@Test
public void bindingsAvailable() {
Row input = new Row();
final String inputValue = "duke";
input.addColumn(-1, "name", inputValue);
RowTransformer function = this.cut.getRowTransformer("bindings");
Row output = function.execute(input);
assertNotNull(output);
final Column outputColumn = output.getColumnByName("synthetic");
assertNotNull(outputColumn);
assertThat(outputColumn.getValue(), is(inputValue));
}
use of com.airhacks.enhydrator.in.Column in project enhydrator by AdamBien.
the class IndexMapperTest method testExecuteReIndexColumns.
/**
* Test of execute method, of class IndexMapper.
*/
@Test
public void testExecuteReIndexColumns() {
// define the index of columns by the ordered names array list
indexMapper.orderedNames = new ArrayList<String>() {
{
add("name");
add("age");
add("weight");
add("height");
}
};
// do the test
Row actualRow = indexMapper.execute(row);
// check the indices
assertEquals(0, actualRow.getColumnByName("name").getIndex());
assertEquals(1, actualRow.getColumnByName("age").getIndex());
assertEquals(2, actualRow.getColumnByName("weight").getIndex());
assertEquals(3, actualRow.getColumnByName("height").getIndex());
assertEquals(-1, actualRow.getColumnByName("resetIndexOne").getIndex());
assertEquals(-1, actualRow.getColumnByName("resetIndexTwo").getIndex());
Column nameColumn = actualRow.getColumnByIndex(0);
assertEquals(0, nameColumn.getIndex());
Column ageColumn = actualRow.getColumnByIndex(1);
assertEquals(1, ageColumn.getIndex());
Column weightColumn = actualRow.getColumnByIndex(2);
assertEquals(2, weightColumn.getIndex());
Column heightColumn = actualRow.getColumnByIndex(3);
assertEquals(3, heightColumn.getIndex());
// index -1 has only one entry - it was overwritten during the reindex of the column by index map
Column columnByIndex = actualRow.getColumnByIndex(-1);
}
use of com.airhacks.enhydrator.in.Column 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.in.Column in project enhydrator by AdamBien.
the class ColumnCopierTest method executeWithExistingMappings.
@Test
public void executeWithExistingMappings() {
this.cut.columnMappings.put("duke", new ColumnCopier.NameList(Arrays.asList("java", "javaee")));
Row row = new Row();
row.addColumn(new Column(0, "duke", "42"));
Row withCopiedColumns = this.cut.execute(row);
assertFalse(withCopiedColumns.isEmpty());
assertThat(withCopiedColumns.getColumns().size(), is(3));
Column javaColumn = row.getColumnByName("java");
assertNotNull(javaColumn);
Column javaeeColumn = row.getColumnByName("javaee");
assertNotNull(javaeeColumn);
}
Aggregations