Search in sources :

Example 1 with ColumnCopier

use of com.airhacks.enhydrator.transform.ColumnCopier 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 2 with ColumnCopier

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

the class PipelineTest method getJDBCPipeline.

public static Pipeline getJDBCPipeline() {
    DestinationMapper mapper = new DestinationMapper();
    mapper.addMapping(0, new TargetMapping("*", "*"));
    JDBCSource source = JDBCSourceIT.getSource();
    NamedSink logSink = new LogSink();
    NamedSink jdbcSink = JDBCSinkTest.getSink();
    ColumnTransformation e1 = new ColumnTransformation("name", "convert", true);
    ColumnTransformation e2 = new ColumnTransformation(42, "compress", true);
    Pipeline origin = new Pipeline("jdbc", "src/test/scripts", "select * from Coffee where name like ? and strength = ?", source);
    origin.addSink(logSink);
    origin.addSink(jdbcSink);
    origin.addQueryParam("arabica");
    origin.addQueryParam(2);
    origin.addEntryTransformation(e1);
    origin.addEntryTransformation(e2);
    origin.addPreRowTransformation(mapper);
    origin.addPostRowTransformation(new SkipFirstRow());
    origin.addPreRowTransformation(new NashornRowTransformer("src/test/scripts", "encrypt"));
    origin.addPostRowTransformation(new NashornRowTransformer("src/test/scripts", "compress"));
    Map<String, ColumnCopier.NameList> mappings = new HashMap<>();
    mappings.put("duke", new ColumnCopier.NameList(Arrays.asList("java", "javaee")));
    origin.addPostRowTransformation(new ColumnCopier(mappings));
    origin.addFilter("true");
    origin.addExpression("print($ROW); $ROW");
    return origin;
}
Also used : DestinationMapper(com.airhacks.enhydrator.transform.DestinationMapper) LogSink(com.airhacks.enhydrator.out.LogSink) TargetMapping(com.airhacks.enhydrator.transform.TargetMapping) NashornRowTransformer(com.airhacks.enhydrator.transform.NashornRowTransformer) HashMap(java.util.HashMap) ColumnCopier(com.airhacks.enhydrator.transform.ColumnCopier) NamedSink(com.airhacks.enhydrator.out.NamedSink) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow)

Aggregations

LogSink (com.airhacks.enhydrator.out.LogSink)2 ColumnCopier (com.airhacks.enhydrator.transform.ColumnCopier)2 Pump (com.airhacks.enhydrator.Pump)1 Column (com.airhacks.enhydrator.in.Column)1 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)1 Row (com.airhacks.enhydrator.in.Row)1 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)1 NamedSink (com.airhacks.enhydrator.out.NamedSink)1 Datatype (com.airhacks.enhydrator.transform.Datatype)1 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)1 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)1 Memory (com.airhacks.enhydrator.transform.Memory)1 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)1 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)1 TargetMapping (com.airhacks.enhydrator.transform.TargetMapping)1 HashMap (java.util.HashMap)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 Before (org.junit.Before)1 Test (org.junit.Test)1