public void setValue(final String name, final String value) { String key = name.toLowerCase(); if (key.contains("original") || key.contains("bytesclf") || key.contains("cookie") ) { return; } key = key.replaceAll("[^a-zA-Z0-9_]","_"); row.addOrSet(key, value); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ZonedDateTime date1 = getDate(row, column1); ZonedDateTime date2 = getDate(row, column2); if (date1 != null && date2 != null) { row.addOrSet(destCol, date1.toInstant().toEpochMilli() - date2.toInstant().toEpochMilli()); } else { row.addOrSet(destCol, null); } } return rows; }
@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; } }
row.addOrSet(column, object);
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException, ErrorRowException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object object = row.getValue(idx); if (object == null || !(object instanceof Double)) { continue; } Double value = (Double) object; String format = this.format.format(value); row.addOrSet(destination, format); } } return rows; } }
/** * Recursively flattens JSON until the 'depth' is reached. * * @param root of the JSONObject * @param field name to be used to be stored in the row. * @param depth current depth into JSON structure. * @param maxDepth maximum depth to reach * @param row to which the flatten fields need to be added. */ public static void jsonFlatten(JsonObject root, String field, int depth, int maxDepth, Row row) { if (depth > maxDepth) { row.addOrSet(String.format("%s", field), root); return; } Iterator<Map.Entry<String, JsonElement>> elements = root.entrySet().iterator(); while(elements.hasNext()) { Map.Entry<String, JsonElement> next = elements.next(); String key = next.getKey(); JsonElement element = next.getValue(); if (element instanceof JsonObject) { jsonFlatten(element.getAsJsonObject(), String.format("%s_%s", field, key), depth + 1, maxDepth, row); } else { row.add(String.format("%s_%s", field, key), getValue(element)); } } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException, ErrorRowException { for (Row row : rows) { int idx = row.find(source); if (idx != -1) { Object object = row.getValue(idx); if (object == null || !(object instanceof String)) { continue; } String value = (String) object; if (value.trim().isEmpty()) { continue; } try { BigDecimal number = (BigDecimal)fmt.parse(value); row.addOrSet(destination, number.doubleValue()); } catch (ParseException e) { throw new ErrorRowException(e.getMessage(), 1); } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException, ErrorRowException { for (Row row : rows) { Map<String, Object> parameters = new HashMap<>(); for (String column : columns) { int idx = row.find(column); if (idx != -1) { parameters.put(column, row.getValue(idx)); } } try { Map<String, Object> result = invokeHttp(url, parameters, headers); for(Map.Entry<String, Object> entry : result.entrySet()) { row.addOrSet(entry.getKey(), entry.getValue()); } } catch (Exception e) { // If there are any issues, they will be pushed on the error port. throw new ErrorRowException(e.getMessage(), 500); } } return rows; }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { // Iterate through all the rows. for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( String.format("%s : Invalid type '%s' of column '%s'. Should be of type String or byte[].", toString(), object != null ? object.getClass().getName() : "null", column) ); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } return rows; }
@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 instanceof String) { String result = Unix4j.fromString((String) value).cut("-c", range).toStringResult(); row.addOrSet(destination, result); } else { throw new DirectiveExecutionException( String.format("%s : Invalid type '%s' of column '%s'. Should be of type String.", toString(), value.getClass().getName(), source) ); } } else { throw new DirectiveExecutionException(toString() + " : Scope column '" + source + "' does not exist in the row."); } } return rows; } }
row.addOrSet(String.format("%s_decode_%s", column, method.toString().toLowerCase(Locale.ENGLISH)), obj);
row.addOrSet(String.format("%s_encode_%s", column, method.toString().toLowerCase(Locale.ENGLISH)), obj);