@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { Map<String, Object> toJson = new HashMap<>(); for (Pair<String, Object> entry : row.getFields()) { toJson.put(entry.getFirst(), entry.getSecond()); } row.addOrSet(column, gson.toJson(toJson)); } 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; } }
if (nameIdx == -1) { Pair<String, String> components = extractDomainAndAccount(emailAddress); row.add(column + "_account", components.getFirst()); row.add(column + "_domain", components.getSecond()); } else { String name = emailAddress.substring(0, nameIdx); emailAddress = emailAddress.substring(nameIdx + 1, endIdx); Pair<String, String> components = extractDomainAndAccount(emailAddress); row.add(column + "_account", components.getFirst()); row.add(column + "_domain", components.getSecond());
/** * @return List of fields of record. */ public List<Pair<String, Object>> getFields() { List<Pair<String, Object>> v = new ArrayList<>(); int i = 0; for (String column : columns) { v.add(new Pair<>(column, values.get(i))); ++i; } return v; }
/** * Computes percentages for each of the measures managed by this instance. * * @param sum denominator for computing the percentages. * @return List of measures and associated percentages. */ public List<Pair<String, Double>> percentage(Double sum) { List<Pair<String, Double>> percentages = new ArrayList<>(); for (Map.Entry<String, MutableDouble> entry : metrics.entrySet()) { double percentage = entry.getValue().get() / sum; if (percentage > 100.0) { percentage = 100; } percentages.add(new Pair<>(entry.getKey(), percentage)); } return percentages; } }