@Test public void testBasicMergeFunctionality() throws Exception { String[] directives = new String[] { "merge A B C ','", "merge B A D ' '" }; List<Row> rows = Arrays.asList( new Row("A", "Root").add("B", "Joltie") ); rows = TestingRig.execute(directives, rows); Assert.assertEquals(1, rows.size()); Assert.assertEquals("Root,Joltie", rows.get(0).getValue("C")); Assert.assertEquals("Joltie Root", rows.get(0).getValue("D")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx1 = row.find(col1); int idx2 = row.find(col2); if (idx1 != -1 && idx2 != -1) { StringBuilder builder = new StringBuilder(); builder.append(row.getValue(idx1)); builder.append(delimiter); builder.append(row.getValue(idx2)); row.add(dest, builder.toString()); } results.add(row); } return results; }
Merge implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx1 = row.find(col1); int idx2 = row.find(col2); if (idx1 != -1 && idx2 != -1) { StringBuilder builder = new StringBuilder(); builder.append(row.getValue(idx1)); builder.append(delimiter); builder.append(row.getValue(idx2)); row.add(dest, builder.toString()); } results.add(row); } return results; } }
Merge implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx1 = row.find(col1); int idx2 = row.find(col2); if (idx1 != -1 && idx2 != -1) { StringBuilder builder = new StringBuilder(); builder.append(row.getValue(idx1)); builder.append(delimiter); builder.append(row.getValue(idx2)); row.add(dest, builder.toString()); } results.add(row); } return results; }  }
Merge implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx1 = row.find(col1); int idx2 = row.find(col2); if (idx1 != -1 && idx2 != -1) { StringBuilder builder = new StringBuilder(); builder.append(row.getValue(idx1)); builder.append(delimiter); builder.append(row.getValue(idx2)); row.add(dest, builder.toString()); } results.add(row); } return results; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
Merge implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx1 = row.find(col1); int idx2 = row.find(col2); if (idx1 != -1 && idx2 != -1) { StringBuilder builder = new StringBuilder(); builder.append(row.getValue(idx1)); builder.append(delimiter); builder.append(row.getValue(idx2)); row.add(dest, builder.toString()); } results.add(row); } return results; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }