@Test @Category(NeedsRunner.class) public void testFilterFieldsByName() { // Pass only elements where field1 == "pass && field2 > 50. PCollection<POJO> filtered = pipeline .apply( Create.of( new POJO("pass", 52, 2), new POJO("pass", 2, 2), new POJO("fail", 100, 100))) .apply( Filter.<POJO>create() .whereFieldName("field1", s -> "pass".equals(s)) .whereFieldName("field2", i -> (Integer) i > 50)); PAssert.that(filtered).containsInAnyOrder(new POJO("pass", 52, 2)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testFilterMultipleFields() { // Pass only elements where field1 + field2 >= 100. PCollection<POJO> filtered = pipeline .apply(Create.of(new POJO("", 52, 48), new POJO("", 52, 2), new POJO("", 70, 33))) .apply( Filter.<POJO>create() .whereFieldNames( Lists.newArrayList("field2", "field3"), r -> r.getInt32("field2") + r.getInt32("field3") >= 100)); PAssert.that(filtered).containsInAnyOrder(new POJO("", 52, 48), new POJO("", 70, 33)); pipeline.run(); } }
public static <T> Inner<T> create() { return new Inner<T>(); }
@Test @Category(NeedsRunner.class) public void testMissingFieldName() { thrown.expect(IllegalArgumentException.class); pipeline .apply(Create.of(new POJO("pass", 52, 2))) .apply(Filter.<POJO>create().whereFieldName("missing", f -> true)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testMissingFieldIndex() { thrown.expect(IllegalArgumentException.class); pipeline .apply(Create.of(new POJO("pass", 52, 2))) .apply(Filter.<POJO>create().whereFieldId(23, f -> true)); pipeline.run(); }