Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windowfunction interface to functions api #3324

Merged
merged 4 commits into from
Jan 14, 2019

Conversation

srkukarni
Copy link
Contributor

Motivation

Currently we support windowed functions but these functions have to be java.util.Function. However simple java.util.Function cannot fetch any kind of meta data about the function since it lacks any kind of context handle. This pr introduces the WindowFunction as anologous to the Function interface which exposes the Context interface.

Modifications

Describe the modifications you've done.

Result

After your change, what will change.

@srkukarni srkukarni added this to the 2.3.0 milestone Jan 8, 2019
@srkukarni srkukarni self-assigned this Jan 8, 2019
* Process the input.
* @return the output
*/
O process(Collection<I> input, WindowContext context) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the API we should have for window functions because there is no way to get the topic of individual msg/record in the collection/window. Maybe the collection should be something like Collection<Record> ? so that users can get the topic from which the msg originated from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up pr, I was thinking of adding something to WindowContext to get something like getCurrentWindow(or something like that) that returns information in terms of Collection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the thing is each entry in the collection could be from a different topic. I am not sure how a getCurrentWindow function would work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If getcurrentWindow returns Collection that should be sufficient. Each Record will have information about the topic of that record.

Copy link
Contributor

@jerrypeng jerrypeng Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but collections are not necessarily ordered in Java

Copy link
Contributor

@jerrypeng jerrypeng Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is also not an eloquent API IMO. Users would have to use the index from one list to look up info in another list manually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the current java.util.function way for handling windowing is not ordered in Java either.
WRT API, if the WindowContext exposes a getCurrentWindow that exposes a Window that should deal with most of the use cases. For the most simple of use cases, just use the collection. For more complicated uses, rely instead on windowContext.getCurrentWindow()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerrypeng as discussed, I've updated the interface to reflect our discussions. Please take a look again. Thanks!

@srkukarni
Copy link
Contributor Author

rerun integration tests

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.functions.windowing;
package org.apache.pulsar.functions.api;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an API breaking change. can we document that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sijie This is not api breaking change. Previously WindowContext was not exposed to the user at all. It was just implementation detail. Now we are exposing this.
I will add up documentation as part of the another pr because there are other changes on top of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants