@Test public void testCommonLogFormat() throws Exception { String[] directives = new String[]{ "parse-as-log body %h %l %u %t \"%r\" %>s %b", "drop body" }; List<Row> rows = Arrays.asList( new Row("body", "127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb.gif HTTP/1.0\" 200 2326") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); }
@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' or 'byte array'.", column)); } String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' is of invalid type '%s'. It should be of type 'String' or 'byte array'.", column, object.getClass().getSimpleName())); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } return rows; }
ParseLog 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' or 'byte array'.", column)); } String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' is of invalid type '%s'. It should be of type 'String' or 'byte array'.", column, object.getClass().getSimpleName())); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } return rows; } }
ParseLog 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' or 'byte array'.", column)); } String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' is of invalid type '%s'. It should be of type 'String' or 'byte array'.", column, object.getClass().getSimpleName())); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } return rows; }  }
ParseLog 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' or 'byte array'.", column)); } String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' is of invalid type '%s'. It should be of type 'String' or 'byte array'.", column, object.getClass().getSimpleName())); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } 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(); }
ParseLog 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' or 'byte array'.", column)); } String log; if (object instanceof String) { log = (String) object; } else if (object instanceof byte[]) { log = new String((byte[]) object); } else { throw new DirectiveExecutionException( NAME, String.format("Column '%s' is of invalid type '%s'. It should be of type 'String' or 'byte array'.", column, object.getClass().getSimpleName())); } line.set(row); try { parser.parse(line, log); } catch (Exception e) { row.addOrSet("log.parse.error", 1); } } } 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; }