@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (String column : columns) { int idx = row.find(column.trim()); if (idx != -1) { row.remove(idx); } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = 0; for (Pair<String, Object> v : row.getFields()) { if (!keep.contains(v.getFirst())) { row.remove(idx); } else { ++idx; } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(col); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException(toString() + " : Did not find '" + col + "' in the row."); } try { if (object instanceof String) { JsonObject element = gson.fromJson(XML.toJSONObject((String) object).toString(), JsonElement.class).getAsJsonObject(); JsParser.jsonFlatten(element, col, 1, depth, row); row.remove(idx); } else { throw new DirectiveExecutionException( String.format("%s : Invalid type '%s' of column '%s'. Should be of type String.", toString(), col, object != null ? object.getClass().getName() : "null") ); } } catch (JSONException e) { throw new DirectiveExecutionException(toString() + " : " + e.getMessage()); } } } return rows; }