use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class FlinkStatefulDoFnFunction method fireTimer.
private void fireTimer(TimerInternals.TimerData timer, DoFnRunner<KV<K, V>, OutputT> doFnRunner) {
StateNamespace namespace = timer.getNamespace();
checkArgument(namespace instanceof StateNamespaces.WindowNamespace);
BoundedWindow window = ((StateNamespaces.WindowNamespace) namespace).getWindow();
doFnRunner.onTimer(timer.getTimerId(), window, timer.getTimestamp(), timer.getDomain());
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class ApexParDoOperator method fireTimer.
@Override
public void fireTimer(Object key, Collection<TimerData> timerDataSet) {
pushbackDoFnRunner.startBundle();
@SuppressWarnings("unchecked") Coder<Object> keyCoder = (Coder) currentKeyStateInternals.getKeyCoder();
((StateInternalsProxy) currentKeyStateInternals).setKey(key);
currentKeyTimerInternals.setContext(key, keyCoder, new Instant(this.currentInputWatermark), new Instant(this.currentOutputWatermark));
for (TimerData timerData : timerDataSet) {
StateNamespace namespace = timerData.getNamespace();
checkArgument(namespace instanceof WindowNamespace);
BoundedWindow window = ((WindowNamespace<?>) namespace).getWindow();
pushbackDoFnRunner.onTimer(timerData.getTimerId(), window, timerData.getTimestamp(), timerData.getDomain());
}
pushbackDoFnRunner.finishBundle();
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testSetStateWithUnderlying.
@Test
public void testSetStateWithUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<SetState<Integer>> valueTag = StateTags.set("foo", VarIntCoder.of());
SetState<Integer> underlyingValue = underlying.state(namespace, valueTag);
assertThat(underlyingValue.read(), emptyIterable());
underlyingValue.add(1);
assertThat(underlyingValue.read(), containsInAnyOrder(1));
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
SetState<Integer> copyOnAccessState = internals.state(namespace, valueTag);
assertThat(copyOnAccessState.read(), containsInAnyOrder(1));
copyOnAccessState.add(4);
assertThat(copyOnAccessState.read(), containsInAnyOrder(4, 1));
assertThat(underlyingValue.read(), containsInAnyOrder(1));
SetState<Integer> reReadUnderlyingValue = underlying.state(namespace, valueTag);
assertThat(underlyingValue.read(), equalTo(reReadUnderlyingValue.read()));
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithAddedUnderlying.
@Test
public void testCommitWithAddedUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
internals.commit();
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = underlying.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("bar");
stringBag.add("baz");
BagState<String> internalState = internals.state(namespace, bagTag);
assertThat(internalState.read(), emptyIterable());
BagState<String> reReadUnderlyingState = underlying.state(namespace, bagTag);
assertThat(reReadUnderlyingState.read(), containsInAnyOrder("bar", "baz"));
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithOnlyClearedValuesIsEmpty.
@Test
public void testCommitWithOnlyClearedValuesIsEmpty() {
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = internals.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("foo");
stringBag.clear();
internals.commit();
assertThat(internals.isEmpty(), is(true));
}
Aggregations