@Test public void testColumnCleanse() throws Exception { String[] directives = new String[] { "cleanse-column-names", }; List<Row> rows = Arrays.asList( new Row("COL1", "1").add("col:2", "2").add("Col3", "3").add("COLUMN4", "4").add("col!5", "5") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals("col1", rows.get(0).getColumn(0)); Assert.assertEquals("col_2", rows.get(0).getColumn(1)); Assert.assertEquals("col3", rows.get(0).getColumn(2)); Assert.assertEquals("column4", rows.get(0).getColumn(3)); Assert.assertEquals("col_5", rows.get(0).getColumn(4)); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.width(); ++i) { String column = row.getColumn(i); column = column.trim(); column = column.toLowerCase(); column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } return rows; }
CleanseColumnNames implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.width(); ++i) { String column = row.getColumn(i); column = column.trim(); column = column.toLowerCase(); column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } return rows; } }
CleanseColumnNames implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.width(); ++i) { String column = row.getColumn(i); column = column.trim(); column = column.toLowerCase(); column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } return rows; }  }
CleanseColumnNames implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.width(); ++i) { String column = row.getColumn(i); column = column.trim(); column = column.toLowerCase(); column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } 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(); }
CleanseColumnNames implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.width(); ++i) { String column = row.getColumn(i); column = column.trim(); column = column.toLowerCase(); column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } 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; }