Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f91b5af
[Dataflow] Add Operation::finishKey() and move timers into it
arunpandianp May 10, 2026
a8e4b0e
Update empty work item iterator
arunpandianp May 11, 2026
986b903
Check if finishKey is called before flushState
arunpandianp May 11, 2026
107517b
Fix tests
arunpandianp May 11, 2026
9e83f33
Call finishKey from WorkerCustomSources
arunpandianp May 11, 2026
d5ef9e5
Fix tests
arunpandianp May 11, 2026
08a7f7d
Add DoFnRunner::finishKey method.
arunpandianp May 12, 2026
e3f45c7
Fix build
arunpandianp May 12, 2026
5085977
run test
arunpandianp May 12, 2026
2c25bc1
Merge remote-tracking branch 'beam/master' into multikey
arunpandianp May 13, 2026
f817e4a
Merge branch 'multikey' into multikey2
arunpandianp May 13, 2026
2b0635e
Merge remote-tracking branch 'beam/master' into multikey2
arunpandianp May 27, 2026
70803b4
address comments
arunpandianp May 28, 2026
e3e9409
address comments
arunpandianp May 28, 2026
2044c1f
spotless fix
arunpandianp Jun 1, 2026
d2cb298
Add key parameter to finishKey
arunpandianp Jun 4, 2026
01d83b8
change finishKey signature to finishKey(@Nullable Object key)
arunpandianp Jun 5, 2026
c7aa197
restore postsubmit files
arunpandianp Jun 8, 2026
84b4520
Revert "change finishKey signature to finishKey(@Nullable Object key)"
arunpandianp Jun 11, 2026
c2a5624
Merge branch 'master' into multikey2
arunpandianp Jun 11, 2026
61e2e80
Remove sideinput logic from finishKey, Make finishKey methods a noop
arunpandianp Jun 11, 2026
762622d
spotless
arunpandianp Jun 11, 2026
a2b3c00
fix compile
arunpandianp Jun 11, 2026
7988779
fix nullness
arunpandianp Jun 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public interface DoFnRunner<InputT extends @Nullable Object, OutputT extends @Nu
<KeyT extends @Nullable Object> void onWindowExpiration(
BoundedWindow window, Instant timestamp, KeyT key);

/**
* Performs per-key cleanup or processing after all elements, timers for a key have been processed
* and before moving to the next key or before finishBundle for the last key.
*
* <p>This is an optional method that can be used by runners as a hook to reset any per key state
* before moving to a different key in the same bundle. Currently used only by the Dataflow
* Streaming runner.
*
* @param key current key to clean up or finish processing
*/
<KeyT extends @Nullable Object> void finishKey(KeyT key);

/**
* Returns the underlying fn instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.beam.sdk.values.WindowedValues;
import org.apache.beam.sdk.values.WindowingStrategy;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -101,6 +102,11 @@ public void finishBundle() {
doFnRunner.finishBundle();
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {
doFnRunner.finishKey(key);
}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
doFnRunner.onWindowExpiration(window, timestamp, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public void finishBundle() {
}
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
invoker.invokeOnWindowExpiration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.beam.sdk.values.WindowedValues;
import org.apache.beam.sdk.values.WindowingStrategy;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.MoreObjects;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Duration;
import org.joda.time.Instant;

Expand Down Expand Up @@ -131,6 +132,11 @@ public void finishBundle() {
doFnRunner.finishBundle();
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {
doFnRunner.finishKey(key);
}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
doFnRunner.onWindowExpiration(window, timestamp, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.apache.beam.sdk.values.WindowingStrategy;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.MoreObjects;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Duration;
import org.joda.time.Instant;
import org.junit.Before;
Expand Down Expand Up @@ -379,6 +380,9 @@ public void finishBundle() {
finished = true;
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.apache.beam.sdk.values.CausedByDrain;
import org.apache.beam.sdk.values.WindowedValue;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -105,6 +106,9 @@ public void finishBundle() {
container.updateMetrics(stepName);
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
delegate.onWindowExpiration(window, timestamp, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,9 @@ public void finishBundle() {
}
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ public void finishBundle() {
Optional.ofNullable(finishBundleCallback).ifPresent(Runnable::run);
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ public void finishBundle() {
wrappedRunner.finishBundle();
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(
BoundedWindow window, Instant timestamp, KeyT key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public void processTimers() throws Exception {
// Nothing.
}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
receiver = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void processTimers() throws Exception {
// The timers for the underlying ParDoFn are processed at the end of each element
}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
underlyingParDoFn.finishBundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public void processElement(Object untypedElem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.beam.sdk.values.WindowedValue;
import org.apache.beam.sdk.values.WindowedValues;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -128,6 +129,11 @@ public void finishBundle() {
simpleRunner.finishBundle();
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {
simpleRunner.finishKey(key);
}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
simpleRunner.onWindowExpiration(window, timestamp, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoFn;
import org.apache.beam.runners.dataflow.worker.util.common.worker.Receiver;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A base class for {@link ParDoFn} implementations for overriding particular methods while
Expand Down Expand Up @@ -47,6 +48,11 @@ public void processTimers() throws Exception {
delegate.processTimers();
}

@Override
public void finishKey(@Nullable Object key) throws Exception {
delegate.finishKey(key);
}

@Override
public void finishBundle() throws Exception {
delegate.finishBundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.beam.sdk.util.WindowedValueReceiver;
import org.apache.beam.sdk.values.CausedByDrain;
import org.apache.beam.sdk.values.WindowedValue;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -102,6 +103,9 @@ private void invokeProcessElement(WindowedValue<InputT> elem) {
@Override
public void finishBundle() {}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public void processTimers() throws Exception {
// it here to build a KeyedWorkItem
}

@Override
public void finishKey(Object key) throws Exception {
checkState(fnRunner != null);
fnRunner.finishKey(key);
}

@Override
public void finishBundle() throws Exception {
checkState(fnRunner != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public void processElement(Object untypedElem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ public void processElement(Object elem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
groupingTable.flush(receiver);
Expand Down Expand Up @@ -377,6 +380,9 @@ public void processElement(Object elem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
groupingTable.flush(receiver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public void processElement(Object untypedElem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
this.receiver = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public void processTimers() throws Exception {
() -> sideInputProcessor);
}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
helpers.finishBundle(sideInputProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Lists;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Sets;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -155,6 +156,11 @@ public void finishBundle() {
sideInputFetcher.persist();
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {
simpleDoFnRunner.finishKey(key);
}

@Override
public <KeyT> void onWindowExpiration(BoundedWindow window, Instant timestamp, KeyT key) {
simpleDoFnRunner.onWindowExpiration(window, timestamp, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ public void processTimers() throws Exception {
() -> sideInputProcessor);
}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {
helpers.finishBundle(sideInputProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void finishKey() {
checkState(!finishKeyCalled, "finishKey was already called");
checkStateNotNull(workExecutor, "workExecutor must be set before calling finishKey()");
try {
workExecutor.finishKey();
workExecutor.finishKey(key);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void processElement(Object element) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() throws Exception {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.apache.beam.sdk.values.CausedByDrain;
import org.apache.beam.sdk.values.WindowedValue;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Instant;

/**
Expand Down Expand Up @@ -80,6 +81,11 @@ public <KeyT> void onTimer(
"Attempt to deliver a timer to a DoFn, but timers are not supported in Dataflow.");
}

@Override
public <KeyT extends @Nullable Object> void finishKey(KeyT key) {
simpleDoFnRunner.finishKey(key);
}

@Override
public void finishBundle() {
simpleDoFnRunner.finishBundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public void processElement(Object untypedElem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void processElement(Object untypedElem) throws Exception {
@Override
public void processTimers() {}

@Override
public void finishKey(Object key) throws Exception {}

@Override
public void finishBundle() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void execute() throws Exception {
}

@Override
public void finishKey() throws Exception {}
public void finishKey(Object key) throws Exception {}

@Override
public SourceOperationResponse getResponse() {
Expand Down
Loading
Loading