@Test public void testUrlEncoding() throws Exception { String[] directives = new String[] { "url-encode url", }; List<Row> rows = Arrays.asList( new Row("url", "http: ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals("http%3A%2F%2Fwww.yahoo.com%3Fa%3Db+c%26b%3Dab%26xyz%3D1", rows.get(0).getValue("url")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (object instanceof String) { try { row.setValue(idx, URLEncoder.encode((String) object, "UTF-8")); } catch (UnsupportedEncodingException e) { } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, String.format("Column '%s' does not exist.", column)); } } return rows; }
UrlEncode implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (object instanceof String) { try { row.setValue(idx, URLEncoder.encode((String) object, "UTF-8")); } catch (UnsupportedEncodingException e) { } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, String.format("Column '%s' does not exist.", column)); } } return rows; } }
UrlEncode implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (object instanceof String) { try { row.setValue(idx, URLEncoder.encode((String) object, "UTF-8")); } catch (UnsupportedEncodingException e) { } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, String.format("Column '%s' does not exist.", column)); } } return rows; }  }
UrlEncode implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (object instanceof String) { try { row.setValue(idx, URLEncoder.encode((String) object, "UTF-8")); } catch (UnsupportedEncodingException e) { } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, String.format("Column '%s' does not exist.", column)); } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override Mutation lineage(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); }
UrlEncode implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object == null) { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has null value. It should be a non-null 'String'.", column)); } if (object instanceof String) { try { row.setValue(idx, URLEncoder.encode((String) object, "UTF-8")); } catch (UnsupportedEncodingException e) { } } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' has invalid type '%s'. It should be of type 'String'.", column, object.getClass().getSimpleName())); } } else { throw new DirectiveExecutionException(NAME, String.format("Column '%s' does not exist.", column)); } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override Mutation lineage(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); static final String NAME; }