Skip to content

Commit a412a75

Browse files
[improve][pip] PIP-396: Align WindowFunction's WindowContext with BaseContext (#23659)
1 parent fad925f commit a412a75

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

pip/pip-396.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# PIP-396: Align WindowFunction's WindowContext with BaseContext
2+
3+
# Background knowledge
4+
5+
Pulsar Functions and Connectors provide a `BaseContext` object, enabling users to access the current execution environment, including logs, metrics, states, secrets, and other context-specific features.
6+
The `WindowFunction`, designed to process multiple messages at once, offers a `WindowContext` object with similar functionality. However, `WindowContext` lacks certain features available in `BaseContext`.
7+
8+
# Motivation
9+
10+
Currently, the `WindowContext` interface does not include some critical methods provided by `BaseContext`, such as `getSecret` and `deleteState`. This limitation makes Window Functions feel less capable compared to standard Functions.
11+
12+
# Goals
13+
14+
## In Scope
15+
16+
- Enhance `WindowContext` by adding missing features from `BaseContext`.
17+
18+
## Out of Scope
19+
20+
# High-Level Design
21+
22+
The solution involves aligning `WindowContext` with `BaseContext` by extending the `WindowContext` interface and implementing missing methods in `WindowContextImpl`.
23+
24+
# Detailed Design
25+
26+
## Design & Implementation Details
27+
28+
Refer to implementation PR: https://github.com/apache/pulsar/pull/23628
29+
30+
The implementation strategy is straightforward:
31+
32+
- Update the `WindowContext` interface to extend the `BaseContext` interface.
33+
- Remove duplicate method definitions in `WindowContext` already covered by `BaseContext`.
34+
- Implement the following missing methods in the `WindowContextImpl` class:
35+
36+
```java
37+
@Override
38+
public String getSecret(String secretName) {
39+
return this.context.getSecret(secretName);
40+
}
41+
42+
@Override
43+
public CompletableFuture<Void> incrCounterAsync(String key, long amount) {
44+
return this.context.incrCounterAsync(key, amount);
45+
}
46+
47+
@Override
48+
public CompletableFuture<Long> getCounterAsync(String key) {
49+
return this.context.getCounterAsync(key);
50+
}
51+
52+
@Override
53+
public CompletableFuture<Void> putStateAsync(String key, ByteBuffer value) {
54+
return this.context.putStateAsync(key, value);
55+
}
56+
57+
@Override
58+
public CompletableFuture<ByteBuffer> getStateAsync(String key) {
59+
return this.context.getStateAsync(key);
60+
}
61+
62+
@Override
63+
public void deleteState(String key) {
64+
this.context.deleteState(key);
65+
}
66+
67+
@Override
68+
public CompletableFuture<Void> deleteStateAsync(String key) {
69+
return this.context.deleteStateAsync(key);
70+
}
71+
72+
@Override
73+
public void fatal(Throwable t) {
74+
this.context.fatal(t);
75+
}
76+
```
77+
78+
## Public-facing Changes
79+
80+
With this update, developers working on Window Functions can leverage the following new methods from WindowContext:
81+
82+
- getSecret
83+
- incrCounterAsync
84+
- getCounterAsync
85+
- putStateAsync
86+
- getStateAsync
87+
- deleteState
88+
- deleteStateAsync
89+
- fatal
90+
91+
### Configuration
92+
93+
# Backward & Forward Compatibility
94+
95+
This update is fully backward-compatible. No existing methods in WindowContext are modified or removed, ensuring seamless integration with current implementations.

0 commit comments

Comments
 (0)