@Test public void testDefaultCoderHandlesNull() throws CannotProvideCoderException { Latest.LatestFn<Long> fn = new Latest.LatestFn<>(); CoderRegistry registry = CoderRegistry.createDefault(); TimestampedValue.TimestampedValueCoder<Long> inputCoder = TimestampedValue.TimestampedValueCoder.of(VarLongCoder.of()); assertThat( "Default output coder should handle null values", fn.getDefaultOutputCoder(registry, inputCoder), instanceOf(NullableCoder.class)); assertThat( "Default accumulator coder should handle null values", fn.getAccumulatorCoder(registry, inputCoder), instanceOf(NullableCoder.class)); } }
return TimestampedValueCoder.of( inferCoderFromObject(coderRegistry, schemaRegistry, ((TimestampedValue) o).getValue())); } else if (o instanceof List) {
ValuesSource<TimestampedValue<String>> valuesSource = new ValuesSource<>( TEST_VALUES, TimestampedValue.TimestampedValueCoder.of(StringUtf8Coder.of())); SourceForTest<TimestampedValue<String>> sourceForTest = new SourceForTest<>(options, valuesSource);
KvCoder.of( inputCoder.getKeyCoder(), TimestampedValue.TimestampedValueCoder.of(inputCoder.getValueCoder()))) .apply("Latest Value", Combine.perKey(new LatestFn<>())) .setCoder(inputCoder);
input, Create.of(timestampedElements).withCoder(TimestampedValueCoder.of(coder)));
@Override public PCollection<KV<K, TimestampedValue<V>>> expand(PCollection<KV<K, V>> input) { KvCoder<K, V> coder = (KvCoder<K, V>) input.getCoder(); return input .apply( ParDo.of( new DoFn<KV<K, V>, KV<K, TimestampedValue<V>>>() { @ProcessElement public void processElement( @Element KV<K, V> element, @Timestamp Instant timestamp, OutputReceiver<KV<K, TimestampedValue<V>>> r) { r.output( KV.of( element.getKey(), TimestampedValue.of(element.getValue(), timestamp))); } })) .setCoder( KvCoder.of(coder.getKeyCoder(), TimestampedValueCoder.of(coder.getValueCoder()))); } }
@Override public PCollection<T> expand(PCollection<T> input) { Coder<T> inputCoder = input.getCoder(); return input .apply( "Reify Timestamps", ParDo.of( new DoFn<T, TimestampedValue<T>>() { @ProcessElement public void processElement( @Element T element, @Timestamp Instant timestamp, OutputReceiver<TimestampedValue<T>> r) { r.output(TimestampedValue.of(element, timestamp)); } })) .setCoder(TimestampedValue.TimestampedValueCoder.of(inputCoder)) .apply("Latest Value", Combine.globally(new LatestFn<>())) .setCoder(NullableCoder.of(inputCoder)); } }
@Override public PCollection<TimestampedValue<T>> expand(PCollection<T> input) { return input .apply( ParDo.of( new DoFn<T, TimestampedValue<T>>() { @ProcessElement public void processElement( @Element T element, @Timestamp Instant timestamp, OutputReceiver<TimestampedValue<T>> r) { r.output(TimestampedValue.of(element, timestamp)); } })) .setCoder(TimestampedValueCoder.of(input.getCoder())); } }
CheckpointCoder(Coder<T> elemCoder) { this.elemsCoder = NullableCoder.of(ListCoder.of(TimestampedValue.TimestampedValueCoder.of(elemCoder))); this.elemCoder = elemCoder; this.sourceCoder = NullableCoder.of(SerializableCoder.of(BoundedSource.class)); }
ExactlyOnceWriter(Write<K, V> spec, Coder<KV<K, V>> elemCoder) { this.spec = spec; this.outOfOrderBufferSpec = StateSpecs.bag(KvCoder.of(BigEndianLongCoder.of(), TimestampedValueCoder.of(elemCoder))); }
private GrowthStateCoder( Coder<OutputT> outputCoder, Coder<TerminationStateT> terminationStateCoder) { this.outputCoder = outputCoder; this.terminationStateCoder = terminationStateCoder; this.completedCoder = MapCoder.of(HASH_CODE_CODER, INSTANT_CODER); this.timestampedOutputCoder = TimestampedValue.TimestampedValueCoder.of(outputCoder); }
ExactlyOnceWriter(Write<K, V> spec, Coder<KV<K, V>> elemCoder) { this.spec = spec; this.outOfOrderBufferSpec = StateSpecs.bag(KvCoder.of(BigEndianLongCoder.of(), TimestampedValueCoder.of(elemCoder))); }