@Test public void testSplitToColumns() throws Exception { String[] directives = new String[] { "split-to-columns body \\n", }; List<Row> rows = Arrays.asList( new Row("body", "AABBCDE\nEEFFFF") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals("AABBCDE", rows.get(0).getValue("body_1")); Assert.assertEquals("EEFFFF", rows.get(0).getValue("body_2")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (!(object instanceof String)) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } String[] lines = ((String) object).split(regex); int i = 1; for (String line : lines) { row.add(String.format("%s_%d", column, i), line); ++i; } results.add(row); } } return results; }
SplitToColumns 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 idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (!(object instanceof String)) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } String[] lines = ((String) object).split(regex); int i = 1; for (String line : lines) { row.add(String.format("%s_%d", column, i), line); ++i; } results.add(row); } } return results; } }
SplitToColumns 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 idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (!(object instanceof String)) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } String[] lines = ((String) object).split(regex); int i = 1; for (String line : lines) { row.add(String.format("%s_%d", column, i), line); ++i; } results.add(row); } } return results; }  }
SplitToColumns 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 idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (!(object instanceof String)) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } String[] lines = ((String) object).split(regex); int i = 1; for (String line : lines) { row.add(String.format("%s_%d", column, i), line); ++i; } 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(); }
SplitToColumns 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 idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (!(object instanceof String)) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } String[] lines = ((String) object).split(regex); int i = 1; for (String line : lines) { row.add(String.format("%s_%d", column, i), line); ++i; } 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; }