Search in sources :

Example 1 with PartitioningFn

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();
}
Also used : PartitioningFn(org.apache.beam.sdk.io.jdbc.JdbcUtil.PartitioningFn) KV(org.apache.beam.sdk.values.KV) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

PartitioningFn (org.apache.beam.sdk.io.jdbc.JdbcUtil.PartitioningFn)1 KV (org.apache.beam.sdk.values.KV)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1