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