-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add an ExtractWindowingInfo transform. #34051
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0dba719
Add ExtractWindowingInfo transform.
robertwb 8534f25
Add default and iterable syntactic sugar.
robertwb b98e331
Docstring cleanup.
robertwb 911a3be
Make mypy happy.
robertwb 86795a0
Add a yaml windowing info extraction example.
robertwb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
sdks/python/apache_beam/yaml/examples/transforms/aggregation/combine_sum_windowed.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # coding=utf-8 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| # This is an example that illustrates how to use session windows and | ||
| # then extract windowing information for further processing. | ||
|
|
||
| pipeline: | ||
| type: chain | ||
| transforms: | ||
| # Create some fake data. | ||
| - type: Create | ||
| name: CreateVisits | ||
| config: | ||
| elements: | ||
| - user: alice | ||
| timestamp: 1 | ||
| - user: alice | ||
| timestamp: 3 | ||
| - user: bob | ||
| timestamp: 7 | ||
| - user: bob | ||
| timestamp: 12 | ||
| - user: bob | ||
| timestamp: 20 | ||
| - user: alice | ||
| timestamp: 101 | ||
| - user: alice | ||
| timestamp: 109 | ||
| - user: alice | ||
| timestamp: 115 | ||
|
|
||
| # Use the timestamp field as the element timestamp. | ||
| # (Typically this would be assigned by the source.) | ||
| - type: AssignTimestamps | ||
| config: | ||
| timestamp: timestamp | ||
|
|
||
| # Group the data by user for each session window count the number of events | ||
| # in each per session. | ||
| # See https://beam.apache.org/documentation/programming-guide/#session-windows | ||
| - type: Combine | ||
| name: SumVisitsPerUser | ||
| config: | ||
| language: python | ||
| group_by: user | ||
| combine: | ||
| visits: | ||
| value: user | ||
| fn: count | ||
| windowing: | ||
| type: sessions | ||
| gap: 10s | ||
|
|
||
| # Extract the implicit Beam windowing data (including what the final | ||
| # merged session values were) into explicit fields of our rows. | ||
| - type: ExtractWindowingInfo | ||
| config: | ||
| fields: [window_start, window_end, window_string] | ||
|
|
||
| # Drop "short" sessions (in this case, Alice's first two visits.) | ||
| - type: Filter | ||
| config: | ||
| language: python | ||
| keep: window_end - window_start > 15 | ||
|
|
||
| # Only keep a couple of fields. | ||
| - type: MapToFields | ||
| config: | ||
| fields: | ||
| user: user | ||
| window_string: window_string | ||
|
|
||
| - type: LogForTesting | ||
|
|
||
| # Expected: | ||
| # Row(user='bob', window_string='[7.0, 30.0)') | ||
| # Row(user='alice', window_string='[101.0, 125.0)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional, not sure if I like this more) - thoughts on
event_timestamp? It might be a little more explicit.We could even allow a user to specify
processing_timestamp(resolves totime.time()) as a convenience.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea.
I'm going to leave it as timestamp. Event timestamps are actually attached to the element, and windows are always in terms of this time. It's also a bit deceptive because if I try to inspect/reify processing time, that's not what will be used when anything else tries to act on it. (In addition, one needs triggers/timers to get into processing time and that's a whole can of worms we don't expose to YAML.)