Search in sources :

Example 16 with StringUtf8Coder

use of org.apache.beam.sdk.coders.StringUtf8Coder in project beam by apache.

the class GroupNonMergingWindowsFunctionsTest method createGbkIterator.

private <W extends BoundedWindow> GroupByKeyIterator<String, Integer, W> createGbkIterator(W window, Coder<W> winCoder, WindowingStrategy<Object, W> winStrategy) throws Coder.NonDeterministicException {
    StringUtf8Coder keyCoder = StringUtf8Coder.of();
    final WindowedValue.FullWindowedValueCoder<KV<String, Integer>> winValCoder = WindowedValue.getFullCoder(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()), winStrategy.getWindowFn().windowCoder());
    ItemFactory<String, Integer, W> factory = ItemFactory.forWindow(keyCoder, winValCoder, winCoder, window);
    List<Tuple2<ByteArray, byte[]>> items = Arrays.asList(factory.create("k1", 1), factory.create("k1", 2), factory.create("k2", 3), factory.create("k2", 4), factory.create("k2", 5));
    return new GroupByKeyIterator<>(items.iterator(), keyCoder, winStrategy, winValCoder);
}
Also used : WindowedValue(org.apache.beam.sdk.util.WindowedValue) Tuple2(scala.Tuple2) GroupByKeyIterator(org.apache.beam.runners.spark.translation.GroupNonMergingWindowsFunctions.GroupByKeyIterator) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) KV(org.apache.beam.sdk.values.KV)

Example 17 with StringUtf8Coder

use of org.apache.beam.sdk.coders.StringUtf8Coder in project beam by apache.

the class LocalDeserializerProviderTest method testInferKeyCoder.

@Test
public void testInferKeyCoder() {
    CoderRegistry registry = CoderRegistry.createDefault();
    assertTrue(LocalDeserializerProvider.of(LongDeserializer.class).getCoder(registry).getValueCoder() instanceof VarLongCoder);
    assertTrue(LocalDeserializerProvider.of(StringDeserializer.class).getCoder(registry).getValueCoder() instanceof StringUtf8Coder);
    assertTrue(LocalDeserializerProvider.of(InstantDeserializer.class).getCoder(registry).getValueCoder() instanceof InstantCoder);
    assertTrue(LocalDeserializerProvider.of(DeserializerWithInterfaces.class).getCoder(registry).getValueCoder() instanceof VarLongCoder);
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) VarLongCoder(org.apache.beam.sdk.coders.VarLongCoder) InstantCoder(org.apache.beam.sdk.coders.InstantCoder) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) Test(org.junit.Test)

Aggregations

StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)17 Test (org.junit.Test)15 WindowedValue (org.apache.beam.sdk.util.WindowedValue)13 StreamRecordStripper.stripStreamRecordFromWindowedValue (org.apache.beam.runners.flink.translation.wrappers.streaming.StreamRecordStripper.stripStreamRecordFromWindowedValue)10 TupleTag (org.apache.beam.sdk.values.TupleTag)10 SerializablePipelineOptions (org.apache.beam.runners.core.construction.SerializablePipelineOptions)9 KV (org.apache.beam.sdk.values.KV)8 KeyedOneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)8 ByteBuffer (java.nio.ByteBuffer)7 FlinkPipelineOptions (org.apache.beam.runners.flink.FlinkPipelineOptions)7 DoFn (org.apache.beam.sdk.transforms.DoFn)6 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)6 Instant (org.joda.time.Instant)6 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)5 HashMap (java.util.HashMap)4 StateNamespace (org.apache.beam.runners.core.StateNamespace)4 VarLongCoder (org.apache.beam.sdk.coders.VarLongCoder)4 WindowingStrategy (org.apache.beam.sdk.values.WindowingStrategy)4 ArrayList (java.util.ArrayList)3 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)3