Search in sources :

Example 1 with SkipFirstRow

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

the class ParentTest method copy.

/**
     * Name;Size;Folder
     */
@Test
public void copy() {
    Source source = new CSVFileSource("./src/test/files/files.csv", ";", "UTF-8", true);
    VirtualSinkSource vss = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(source).startWith(new SkipFirstRow()).startWith(new NonRecursiveTree("Name", "Folder")).to(vss).to(new LogSink()).build();
    pump.start();
    System.out.println(vss.getRows());
    int numberOfRows = vss.getNumberOfRows();
    assertThat(numberOfRows, is(2));
    Row parentWithChildren = vss.getRow(0);
    assertNotNull(parentWithChildren);
    assertThat(parentWithChildren.getNumberOfColumns(), is(3));
    List<Row> children = parentWithChildren.getChildren();
    assertThat(children.size(), is(2));
    children.forEach(e -> assertThat(e.getNumberOfColumns(), is(2)));
}
Also used : NonRecursiveTree(com.airhacks.enhydrator.functions.NonRecursiveTree) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Example 2 with SkipFirstRow

use of com.airhacks.enhydrator.transform.SkipFirstRow 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)

Example 3 with SkipFirstRow

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

the class SkipFirstRowTest method skipFirstRow.

@Test
public void skipFirstRow() {
    SkipFirstRow cut = new SkipFirstRow();
    Row actual = cut.execute(new Row());
    assertNull(actual);
    actual = cut.execute(new Row());
    assertNotNull(actual);
}
Also used : SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 4 with SkipFirstRow

use of com.airhacks.enhydrator.transform.SkipFirstRow 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);
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Aggregations

SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)4 Row (com.airhacks.enhydrator.in.Row)3 LogSink (com.airhacks.enhydrator.out.LogSink)3 Test (org.junit.Test)3 Pump (com.airhacks.enhydrator.Pump)2 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)2 Source (com.airhacks.enhydrator.in.Source)2 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)2 NonRecursiveTree (com.airhacks.enhydrator.functions.NonRecursiveTree)1 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)1 NamedSink (com.airhacks.enhydrator.out.NamedSink)1 ColumnCopier (com.airhacks.enhydrator.transform.ColumnCopier)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 TargetMapping (com.airhacks.enhydrator.transform.TargetMapping)1 HashMap (java.util.HashMap)1