@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = 0; for (String name : columns) { if (idx < row.length()) { row.setColumn(idx, name.trim()); } idx++; } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String name = row.getColumn(i); if (toLower) { row.setColumn(i, name.toLowerCase()); } else { row.setColumn(i, name.toUpperCase()); } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String column = row.getColumn(i); // Trims column = column.trim(); // Lower case columns column = column.toLowerCase(); // Filtering unwanted characters column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int sidx = row.find(left); int didx = row.find(right); if (sidx == -1) { throw new DirectiveExecutionException(MSG.get("column.not.found", toString(), left)); } if (didx == -1) { throw new DirectiveExecutionException(MSG.get("column.not.found", toString(), right)); } row.setColumn(sidx, right); row.setColumn(didx, left); } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String name = row.getColumn(i); try { Unix4jCommandBuilder builder = Unix4j.echo(name).sed(sed); row.setColumn(i, builder.toStringResult()); } catch (IllegalArgumentException e) { throw new DirectiveExecutionException( String.format(toString() + " : " + e.getMessage()) ); } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException, ErrorRowException { for (Row row : rows) { int idx = row.find(source.value()); int idxnew = row.find(target.value()); if (idx != -1) { if (idxnew == -1) { row.setColumn(idx, target.value()); } else { throw new DirectiveExecutionException( String.format( "%s : %s column already exists. Apply the directive 'drop %s' before renaming %s to %s.", toString(), target.value(), target.value(), source.value(), source.value() ) ); } } } return rows; } }