use of org.apache.beam.sdk.io.jdbc.JdbcUtil.PartitioningFn in project beam by apache.
the class JdbcIOTest method testPartitioningDateTime.
@Test
public void testPartitioningDateTime() {
PCollection<KV<DateTime, DateTime>> ranges = pipeline.apply(Create.of(KV.of(10L, KV.of(new DateTime(0), DateTime.now())))).apply(ParDo.of(new PartitioningFn<>(TypeDescriptor.of(DateTime.class))));
PAssert.that(ranges.apply(Count.globally())).satisfies(new SerializableFunction<Iterable<Long>, Void>() {
@Override
public Void apply(Iterable<Long> input) {
// We must have exactly least one element
Long count = input.iterator().next();
// The implementation for range partitioning relies on millis from epoch.
// We allow off-by-one differences because we can have slight differences
// in integers when computing strides, and advancing through timestamps.
assertThat(Double.valueOf(count), closeTo(10, 1));
return null;
}
});
pipeline.run().waitUntilFinish();
}
Aggregations