@Test public void testSplitWhenNoPatternMatch() throws Exception { String[] directives = new String[] { "split-to-rows body X", }; List<Row> rows = Arrays.asList( new Row("body", "AABBCDE\nEEFFFF") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); }
@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) { String[] lines = ((String) object).split(regex); for (String line : lines) { Row r = new Row(row); r.setValue(idx, line); results.add(r); } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } } return results; }
SplitToRows 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) { String[] lines = ((String) object).split(regex); for (String line : lines) { Row r = new Row(row); r.setValue(idx, line); results.add(r); } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } } return results; } }
SplitToRows 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) { String[] lines = ((String) object).split(regex); for (String line : lines) { Row r = new Row(row); r.setValue(idx, line); results.add(r); } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } } return results; }  }
SplitToRows 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) { String[] lines = ((String) object).split(regex); for (String line : lines) { Row r = new Row(row); r.setValue(idx, line); results.add(r); } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } } 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(); }
SplitToRows 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) { String[] lines = ((String) object).split(regex); for (String line : lines) { Row r = new Row(row); r.setValue(idx, line); results.add(r); } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } } 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; }