Search in sources :

Example 1 with Column

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"));
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 2 with Column

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));
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 3 with Column

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);
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 4 with Column

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();
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ColumnCopier(com.airhacks.enhydrator.transform.ColumnCopier) Column(com.airhacks.enhydrator.in.Column) Test(org.junit.Test) Assert.assertThat(org.junit.Assert.assertThat) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Datatype(com.airhacks.enhydrator.transform.Datatype) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) Pump(com.airhacks.enhydrator.Pump) Row(com.airhacks.enhydrator.in.Row) Before(org.junit.Before) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) ColumnCopier(com.airhacks.enhydrator.transform.ColumnCopier) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) Before(org.junit.Before)

Example 5 with Column

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);
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Aggregations

Column (com.airhacks.enhydrator.in.Column)10 Row (com.airhacks.enhydrator.in.Row)9 Test (org.junit.Test)8 Memory (com.airhacks.enhydrator.transform.Memory)2 Pump (com.airhacks.enhydrator.Pump)1 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)1 LogSink (com.airhacks.enhydrator.out.LogSink)1 ColumnCopier (com.airhacks.enhydrator.transform.ColumnCopier)1 Datatype (com.airhacks.enhydrator.transform.Datatype)1 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 Before (org.junit.Before)1