@Test public void testSpace() throws Exception { String[] directives = new String[] { "fill-null-or-empty :value 'Not Available'", }; List<Row> rows = Arrays.asList( new Row("value", null), new Row("value", null), new Row("value", "Should be fine") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 3); Assert.assertEquals("Not Available", rows.get(0).getValue("value")); Assert.assertEquals("Not Available", rows.get(1).getValue("value")); Assert.assertEquals("Should be fine", rows.get(2).getValue("value")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx == -1) { row.add(column, value); continue; } Object object = row.getValue(idx); if (object == null) { row.setValue(idx, value); } else { if (object instanceof String) { if (((String) object).isEmpty()) { row.setValue(idx, value); } } else if (object instanceof JSONObject) { if (JSONObject.NULL.equals(object)) { row.setValue(idx, value); } } } } return rows; }
FillNullOrEmpty implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx == -1) { row.add(column, value); continue; } Object object = row.getValue(idx); if (object == null) { row.setValue(idx, value); } else { if (object instanceof String) { if (((String) object).isEmpty()) { row.setValue(idx, value); } } else if (object instanceof JSONObject) { if (JSONObject.NULL.equals(object)) { row.setValue(idx, value); } } } } return rows; } }
FillNullOrEmpty implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx == -1) { row.add(column, value); continue; } Object object = row.getValue(idx); if (object == null) { row.setValue(idx, value); } else { if (object instanceof String) { if (((String) object).isEmpty()) { row.setValue(idx, value); } } else if (object instanceof JSONObject) { if (JSONObject.NULL.equals(object)) { row.setValue(idx, value); } } } } return rows; }  }
FillNullOrEmpty implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx == -1) { row.add(column, value); continue; } Object object = row.getValue(idx); if (object == null) { row.setValue(idx, value); } else { if (object instanceof String) { if (((String) object).isEmpty()) { row.setValue(idx, value); } } else if (object instanceof JSONObject) { if (JSONObject.NULL.equals(object)) { row.setValue(idx, value); } } } } 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(); }
FillNullOrEmpty implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx == -1) { row.add(column, value); continue; } Object object = row.getValue(idx); if (object == null) { row.setValue(idx, value); } else { if (object instanceof String) { if (((String) object).isEmpty()) { row.setValue(idx, value); } } else if (object instanceof JSONObject) { if (JSONObject.NULL.equals(object)) { row.setValue(idx, value); } } } } 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; }