Java Code Examples for org.apache.beam.sdk.util.WindowedValue#withValue()
The following examples show how to use
org.apache.beam.sdk.util.WindowedValue#withValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FnApiDoFnRunner.java From beam with Apache License 2.0 | 6 votes |
private void processElementForSplitRestriction( WindowedValue<KV<InputT, KV<RestrictionT, WatermarkEstimatorStateT>>> elem) { currentElement = elem.withValue(elem.getValue().getKey()); currentRestriction = elem.getValue().getValue().getKey(); currentWatermarkEstimatorState = elem.getValue().getValue().getValue(); try { doFnInvoker.invokeSplitRestriction(processContext); } finally { currentElement = null; currentRestriction = null; currentWatermarkEstimatorState = null; } // TODO(BEAM-10212): Support caching state data across bundle boundaries. this.stateAccessor.finalizeState(); }
Example 2
Source File: FnApiDoFnRunner.java From beam with Apache License 2.0 | 6 votes |
private void processElementForWindowObservingSplitRestriction( WindowedValue<KV<InputT, KV<RestrictionT, WatermarkEstimatorStateT>>> elem) { currentElement = elem.withValue(elem.getValue().getKey()); currentRestriction = elem.getValue().getValue().getKey(); currentWatermarkEstimatorState = elem.getValue().getValue().getValue(); try { Iterator<BoundedWindow> windowIterator = (Iterator<BoundedWindow>) elem.getWindows().iterator(); while (windowIterator.hasNext()) { currentWindow = windowIterator.next(); doFnInvoker.invokeSplitRestriction(processContext); } } finally { currentElement = null; currentRestriction = null; currentWatermarkEstimatorState = null; currentWindow = null; } // TODO(BEAM-10212): Support caching state data across bundle boundaries. this.stateAccessor.finalizeState(); }
Example 3
Source File: GroupNonMergingWindowsFunctions.java From beam with Apache License 2.0 | 6 votes |
@Override public WindowedValue<KV<K, Iterable<V>>> next() { while (inner.hasNext()) { final ByteArray nextKey = inner.peek()._1; if (nextKey.equals(currentKey)) { // we still did not see all values for a given key inner.next(); continue; } currentKey = nextKey; final WindowedValue<KV<K, V>> decodedItem = decodeItem(inner.peek()); return decodedItem.withValue( KV.of(decodedItem.getValue().getKey(), new ValueIterator(inner, currentKey))); } hasNext = false; return null; }
Example 4
Source File: FlinkStreamingTransformTranslators.java From beam with Apache License 2.0 | 6 votes |
@Override public void flatMap( WindowedValue<KV<K, InputT>> inWithMultipleWindows, Collector<WindowedValue<SingletonKeyedWorkItem<K, InputT>>> out) throws Exception { // we need to wrap each one work item per window for now // since otherwise the PushbackSideInputRunner will not correctly // determine whether side inputs are ready // // this is tracked as https://issues.apache.org/jira/browse/BEAM-1850 for (WindowedValue<KV<K, InputT>> in : inWithMultipleWindows.explodeWindows()) { SingletonKeyedWorkItem<K, InputT> workItem = new SingletonKeyedWorkItem<>( in.getValue().getKey(), in.withValue(in.getValue().getValue())); out.collect(WindowedValue.valueInGlobalWindow(workItem)); } }
Example 5
Source File: FlinkStreamingTransformTranslators.java From beam with Apache License 2.0 | 6 votes |
@Override public void flatMap( WindowedValue<KV<K, InputT>> inWithMultipleWindows, Collector<WindowedValue<SingletonKeyedWorkItem<K, InputT>>> out) throws Exception { // we need to wrap each one work item per window for now // since otherwise the PushbackSideInputRunner will not correctly // determine whether side inputs are ready // // this is tracked as https://issues.apache.org/jira/browse/BEAM-1850 for (WindowedValue<KV<K, InputT>> in : inWithMultipleWindows.explodeWindows()) { SingletonKeyedWorkItem<K, InputT> workItem = new SingletonKeyedWorkItem<>( in.getValue().getKey(), in.withValue(in.getValue().getValue())); out.collect(in.withValue(workItem)); } }
Example 6
Source File: CloningBundleFactory.java From beam with Apache License 2.0 | 5 votes |
@Override public UncommittedBundle<T> add(WindowedValue<T> element) { try { // Use the cloned value to ensure that if the coder behaves poorly (e.g. a NoOpCoder that // does not expect to be used) that is reflected in the values given to downstream // transforms WindowedValue<T> clone = element.withValue(CoderUtils.clone(coder, element.getValue())); underlying.add(clone); } catch (CoderException e) { throw UserCodeException.wrap(e); } return this; }
Example 7
Source File: SDFFeederViaStateAndTimers.java From beam with Apache License 2.0 | 5 votes |
/** * Resumes from a timer and returns the current element/restriction pair (with an up-to-date value * of the restriction). */ public WindowedValue<KV<InputT, RestrictionT>> resume(TimerData timer) { initState(timer.getNamespace()); WindowedValue<KV<InputT, RestrictionT>> seed = seedState.read(); inputTimestamp = seed.getTimestamp(); return seed.withValue(KV.of(seed.getValue().getKey(), restrictionState.read())); }
Example 8
Source File: WorkerCustomSources.java From beam with Apache License 2.0 | 5 votes |
@Override public WindowedValue<ValueWithRecordId<T>> getCurrent() throws NoSuchElementException { WindowedValue<T> result = WindowedValue.timestampedValueInGlobalWindow( reader.getCurrent(), reader.getCurrentTimestamp()); return result.withValue( new ValueWithRecordId<>(result.getValue(), reader.getCurrentRecordId())); }
Example 9
Source File: PartitioningShuffleReader.java From beam with Apache License 2.0 | 5 votes |
@Override public boolean advance() throws IOException { if (!iterator.hasNext()) { current = null; return false; } ShuffleEntry record = iterator.next(); K key = CoderUtils.decodeFromByteArray(shuffleReader.keyCoder, record.getKey()); WindowedValue<V> windowedValue = CoderUtils.decodeFromByteArray(shuffleReader.windowedValueCoder, record.getValue()); shuffleReader.notifyElementRead(record.length()); current = windowedValue.withValue(KV.of(key, windowedValue.getValue())); return true; }
Example 10
Source File: KvToKeyedWorkItemOp.java From beam with Apache License 2.0 | 5 votes |
@Override public void processElement( WindowedValue<KV<K, V>> inputElement, OpEmitter<KeyedWorkItem<K, V>> emitter) { final KV<K, V> kv = inputElement.getValue(); for (WindowedValue<KV<K, V>> windowedValue : inputElement.explodeWindows()) { final KeyedWorkItem<K, V> workItem = new SingletonKeyedWorkItem<>(kv.getKey(), windowedValue.withValue(kv.getValue())); emitter.emitElement(windowedValue.withValue(workItem)); } }
Example 11
Source File: FlinkStreamingPortablePipelineTranslator.java From beam with Apache License 2.0 | 4 votes |
@Override public WindowedValue<KV<Void, T>> map(WindowedValue<T> value) { return value.withValue(KV.of(null, value.getValue())); }
Example 12
Source File: PartialGroupByKeyParDoFns.java From beam with Apache License 2.0 | 4 votes |
@Override public Object getKeyFromInputPair(Object pair) { @SuppressWarnings("unchecked") WindowedValue<KV<?, ?>> windowedKv = (WindowedValue<KV<?, ?>>) pair; return windowedKv.withValue(windowedKv.getValue().getKey()); }
Example 13
Source File: PartialGroupByKeyParDoFns.java From beam with Apache License 2.0 | 4 votes |
@Override public Object makeOutputPair(Object key, Object values) { WindowedValue<?> windowedKey = (WindowedValue<?>) key; return windowedKey.withValue(KV.of(windowedKey.getValue(), values)); }
Example 14
Source File: TranslationUtils.java From beam with Apache License 2.0 | 4 votes |
@Override public WindowedValue<KV<K, V>> call(KV<K, WindowedValue<V>> kv) { WindowedValue<V> wv = kv.getValue(); return wv.withValue(KV.of(kv.getKey(), wv.getValue())); }
Example 15
Source File: MapFnRunnersTest.java From beam with Apache License 2.0 | 4 votes |
public ThrowingFunction<WindowedValue<String>, WindowedValue<String>> createMapFunctionForPTransform(String ptransformId, PTransform pTransform) { assertEquals(EXPECTED_ID, ptransformId); assertEquals(EXPECTED_PTRANSFORM, pTransform); return (WindowedValue<String> str) -> str.withValue(str.getValue().toUpperCase()); }
Example 16
Source File: PrecombineGroupingTable.java From beam with Apache License 2.0 | 4 votes |
@Override public Object makeOutputPair(Object key, Object values) { WindowedValue<?> windowedKey = (WindowedValue<?>) key; return windowedKey.withValue(KV.of(windowedKey.getValue(), values)); }
Example 17
Source File: PrecombineGroupingTable.java From beam with Apache License 2.0 | 4 votes |
@Override public Object getKeyFromInputPair(Object pair) { @SuppressWarnings("unchecked") WindowedValue<KV<?, ?>> windowedKv = (WindowedValue<KV<?, ?>>) pair; return windowedKv.withValue(windowedKv.getValue().getKey()); }