pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[improve][pip] PIP-484: Expose Window interface for WindowFunction processing

Open Dream95 opened this issue 5 months ago • 4 comments

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.Window type; instance code imports org.apache.pulsar.functions.api.Window directly.
  • Add a new default process(Window<Record<X>>, WindowContext) overload on the existing WindowFunction<X, T> interface. The default delegates to process(window.get(), context), so lambdas and existing class implementations remain unchanged.
  • Update WindowFunctionExecutor to pass the full Window object to WindowFunction.process(window, context) instead of only inputWindow.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

Dream95 avatar Jun 08 '26 10:06 Dream95

overall LGTM, just 2 points:

  1. 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.
  2. 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.

dao-jun avatar Jun 10 '26 06:06 dao-jun

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 PIP label 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 TBD for the [DISCUSS]/[VOTE] mailing-list threads — expected at this stage, just a reminder to fill them in before the vote concludes.

david-streamlio avatar Jun 10 '26 14:06 david-streamlio

@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 avatar Jun 16 '26 14:06 Dream95

@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:

  1. Send a [DISCUSS] PIP-484: Expose Window interface for WindowFunction processing email to [email protected] (link back to this PR).
  2. Once it's on the list, replace Mailing List discussion thread: TBD in the PIP with the lists.apache.org permalink.
  3. 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!

david-streamlio avatar Jun 17 '26 16:06 david-streamlio

@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.

Dream95 avatar Jul 23 '26 13:07 Dream95