@Test public void testBasicURLWorking() throws Exception { String[] directives = new String[] { "split-url url", }; List<Row> rows = Arrays.asList( new Row("url", "http: ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals(80, rows.get(0).getValue("url_port")); Assert.assertEquals("example.com", rows.get(0).getValue("url_host")); }
@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) { row.add(protocolCol, null); row.add(authCol, null); row.add(hostCol, null); row.add(portCol, null); row.add(pathCol, null); row.add(queryCol, null); row.add(fileCol, null); continue; } if (object instanceof String) { try { URL url = new URL((String) object); row.add(protocolCol, url.getProtocol()); row.add(authCol, url.getAuthority()); row.add(hostCol, url.getHost()); row.add(portCol, url.getPort()); row.add(pathCol, url.getPath()); row.add(fileCol, url.getFile()); row.add(queryCol, url.getQuery()); } catch (MalformedURLException e) { throw new DirectiveExecutionException( NAME, String.format("Malformed url '%s' found in column '%s'.", (String) object, column), 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; }
SplitURL 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) { row.add(protocolCol, null); row.add(authCol, null); row.add(hostCol, null); row.add(portCol, null); row.add(pathCol, null); row.add(queryCol, null); row.add(fileCol, null); continue; } if (object instanceof String) { try { URL url = new URL((String) object); row.add(protocolCol, url.getProtocol()); row.add(authCol, url.getAuthority()); row.add(hostCol, url.getHost()); row.add(portCol, url.getPort()); row.add(pathCol, url.getPath()); row.add(fileCol, url.getFile()); row.add(queryCol, url.getQuery()); } catch (MalformedURLException e) { throw new DirectiveExecutionException( NAME, String.format("Malformed url '%s' found in column '%s'.", (String) object, column), 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; } }
SplitURL 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) { row.add(protocolCol, null); row.add(authCol, null); row.add(hostCol, null); row.add(portCol, null); row.add(pathCol, null); row.add(queryCol, null); row.add(fileCol, null); continue; } if (object instanceof String) { try { URL url = new URL((String) object); row.add(protocolCol, url.getProtocol()); row.add(authCol, url.getAuthority()); row.add(hostCol, url.getHost()); row.add(portCol, url.getPort()); row.add(pathCol, url.getPath()); row.add(fileCol, url.getFile()); row.add(queryCol, url.getQuery()); } catch (MalformedURLException e) { throw new DirectiveExecutionException( NAME, String.format("Malformed url '%s' found in column '%s'.", (String) object, column), 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; }  }
SplitURL 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) { row.add(protocolCol, null); row.add(authCol, null); row.add(hostCol, null); row.add(portCol, null); row.add(pathCol, null); row.add(queryCol, null); row.add(fileCol, null); continue; } if (object instanceof String) { try { URL url = new URL((String) object); row.add(protocolCol, url.getProtocol()); row.add(authCol, url.getAuthority()); row.add(hostCol, url.getHost()); row.add(portCol, url.getPort()); row.add(pathCol, url.getPath()); row.add(fileCol, url.getFile()); row.add(queryCol, url.getQuery()); } catch (MalformedURLException e) { throw new DirectiveExecutionException( NAME, String.format("Malformed url '%s' found in column '%s'.", (String) object, column), 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 List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
SplitURL 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) { row.add(protocolCol, null); row.add(authCol, null); row.add(hostCol, null); row.add(portCol, null); row.add(pathCol, null); row.add(queryCol, null); row.add(fileCol, null); continue; } if (object instanceof String) { try { URL url = new URL((String) object); row.add(protocolCol, url.getProtocol()); row.add(authCol, url.getAuthority()); row.add(hostCol, url.getHost()); row.add(portCol, url.getPort()); row.add(pathCol, url.getPath()); row.add(fileCol, url.getFile()); row.add(queryCol, url.getQuery()); } catch (MalformedURLException e) { throw new DirectiveExecutionException( NAME, String.format("Malformed url '%s' found in column '%s'.", (String) object, column), 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 List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }