[improve][pip] PIP-484: Expose Window interface for WindowFunction processing
Motivation
Pulsar Window Functions currently invoke WindowFunction.process(Collection<Record<X>>, ...) with all messages in the window on every trigger. Internally, WindowManager already classifies events into full, newly added, and expired lists on each activation, but WindowFunctionExecutor drops getNew() and getExpired() before calling the user function.
This makes incremental computation inefficient for sliding windows and forces users to manually diff full collections.
Modifications
This PR adds PIP-484, which proposes:
- Promote the existing internal
Window<T>interface to the public API (get(),getNew(),getExpired(), timestamps). - Remove the internal
org.apache.pulsar.functions.windowing.Windowtype; instance code importsorg.apache.pulsar.functions.api.Windowdirectly. - Add a new default
process(Window<Record<X>>, WindowContext)overload on the existingWindowFunction<X, T>interface. The default delegates toprocess(window.get(), context), so lambdas and existing class implementations remain unchanged. - Update
WindowFunctionExecutorto pass the fullWindowobject toWindowFunction.process(window, context)instead of onlyinputWindow.get().
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
- [ ] Dependencies (add or upgrade a dependency)
- [x] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
overall LGTM, just 2 points:
- The FunctionCommon.getFunctionClassParent() change is more critical than the PIP describes — it's not about "keeping type inference correct," it's that without it, deployment will NPE (assuming doJavaChecks is fixed first). The call chain is getFunctionTypes → getFunctionClassParent → resolveInterfaceTypeArguments. When the parent interface is misidentified as java.util.function.Function, resolveInterfaceTypeArguments traverses the interface hierarchy and never finds Function (since IncrementalWindowFunction doesn't extend it), returns null, and typeArgsList.get(0) throws NPE. This should be documented as a hard dependency, not a correctness improvement.
- Window.get() / getNew() / getExpired() return mutable List
. While each trigger creates fresh lists so mutations can't corrupt internal state, once this becomes a public API the Javadoc should explicitly state whether callers are allowed to modify the returned lists.
A few PIP-process items (separate from the proposal content):
- PR title is
[improve][fn], but the PIP README specifies[improve][pip] PIP-xxx: {title}for PIP PRs. Worth aligning (the semantic-PR CI may flag it). - No
PIPlabel is applied yet — it's needed for the PIP index/tracking query. - Please confirm PIP-484 is still the next free number — numbers are assigned by open-PR order and can race with other in-flight PIPs.
- The Links section still has
TBDfor the[DISCUSS]/[VOTE]mailing-list threads — expected at this stage, just a reminder to fill them in before the vote concludes.
@dao-jun @david-streamlio Thanks for the review. I've revised PIP-484: instead of adding IncrementalWindowFunction, we now expose the public Window interface and extend WindowFunction with a default process(Window, WindowContext) overload. Existing WindowFunction users (including lambdas) remain backward compatible, and no deployment-validation changes are required.
@Dream95 The proposal reads well now and the design discussion has mostly converged here — at this point the main thing gating progress is the mailing-list [DISCUSS] thread, which is a required step in the PIP process before a vote can be called.
Could you kick that off? Roughly:
- Send a
[DISCUSS] PIP-484: Expose Window interface for WindowFunction processingemail to[email protected](link back to this PR). - Once it's on the list, replace
Mailing List discussion thread: TBDin the PIP with the lists.apache.org permalink. - Let it run ~a week / until comments settle, fold in any feedback, then start the
[VOTE]thread and fill in that link too.
That moves the design conversation to where the binding +1s happen. The review comments I left are all polish and can be folded in during the discussion — they're not blockers. Thanks for the iterations on this!
@dao-jun @david-streamlio Thanks again for reviewing PIP-484 earlier.
The mailing-list [VOTE] thread is now open:
https://lists.apache.org/thread/mcnl2tf5lppz52vkk8qrby2xzn55gfz1
If you have a chance, could you please cast a vote there? Happy to address any remaining concerns.