@Test public void testBasicCharacterCut() throws Exception { String[] directives = new String[] { "cut-character body one 1-3", "cut-character body two 5-7", "cut-character body three 9-13", "cut-character body four 15-", "cut-character body five 1,2,3", "cut-character body six -3", "cut-character body seven 1,2,3-5", }; List<Row> rows = Arrays.asList( new Row("body", "one two three four five six seven eight") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals(8, rows.get(0).width()); Assert.assertEquals("one", rows.get(0).getValue("one")); Assert.assertEquals("two", rows.get(0).getValue("two")); Assert.assertEquals("three", rows.get(0).getValue("three")); Assert.assertEquals("four five six seven eight", rows.get(0).getValue("four")); Assert.assertEquals("one", rows.get(0).getValue("five")); Assert.assertEquals("one", rows.get(0).getValue("six")); Assert.assertEquals("one t", rows.get(0).getValue("seven")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object value = row.getValue(idx); if (value == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", source)); } if (value instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", source, value.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, "Scope column '" + source + "' does not exist."); } } return rows; }
CharacterCut implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object value = row.getValue(idx); if (value == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", source)); } if (value instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", source, value.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, "Scope column '" + source + "' does not exist."); } } return rows; } }
CharacterCut implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object value = row.getValue(idx); if (value == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", source)); } if (value instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", source, value.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, "Scope column '" + source + "' does not exist."); } } return rows; }  }
CharacterCut implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object value = row.getValue(idx); if (value == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", source)); } if (value instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", source, value.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, "Scope column '" + source + "' does not exist."); } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
CharacterCut implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object value = row.getValue(idx); if (value == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", source)); } if (value instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", source, value.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, "Scope column '" + source + "' does not exist."); } } return rows; }  @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; }