Created
March 26, 2021 10:18
-
-
Save PlugaruT/9af53bcb54ece94523a386147392ab4c to your computer and use it in GitHub Desktop.
This file contains 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
import apache_beam as beam | |
from apache_beam.transforms.window import FixedWindows, GlobalWindows | |
events = [ | |
("k1", {"a": 1, "b":2}), | |
("k1", {"a": 1, "b":2}), | |
("k2", {"a": 1, "b":2}), | |
("k2", {"a": 1, "b":2}), | |
("k3", {"a": 1, "b":2}), | |
("k4", {"a": 1, "b":2}), | |
] | |
class ToGlobalWindow(beam.DoFn): | |
def process(self, element): | |
yield GlobalWindows.windowed_value(element) | |
def main(): | |
with beam.Pipeline() as p: | |
( | |
p | beam.Create(events) | beam.WindowInto(windowfn=FixedWindows(size=60)) | beam.GroupByKey() | beam.ParDo(ToGlobalWindow()) | beam.Map(print) | |
) | |
p.run() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment