claudevdm commented on code in PR #36621: URL: https://github.com/apache/beam/pull/36621#discussion_r2470027195
########## sdks/python/apache_beam/examples/cookbook/ordered_window_elements/batch.py: ########## @@ -0,0 +1,522 @@ +# +# 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. +# + +import logging +from enum import Enum +from typing import Any +from typing import Callable +from typing import Optional + +import apache_beam as beam +from apache_beam.coders import BooleanCoder +from apache_beam.coders import PickleCoder +from apache_beam.pvalue import AsDict +from apache_beam.transforms.combiners import ToListCombineFn +from apache_beam.transforms.ptransform import PTransform +from apache_beam.transforms.timeutil import TimeDomain +from apache_beam.transforms.userstate import OrderedListStateSpec +from apache_beam.transforms.userstate import ReadModifyWriteStateSpec +from apache_beam.transforms.userstate import TimerSpec +from apache_beam.transforms.userstate import on_timer +from apache_beam.transforms.window import GlobalWindow +from apache_beam.utils.timestamp import MIN_TIMESTAMP +from apache_beam.utils.timestamp import DurationTypes # pylint: disable=unused-import +from apache_beam.utils.timestamp import Timestamp +from apache_beam.utils.timestamp import TimestampTypes # pylint: disable=unused-import + + +class FanOutToWindows(beam.DoFn): + """ + Assigns each element to all the windows that contain it. + + This DoFn is used to expand a single element into multiple elements, each + associated with a specific window. + + Args: + duration: The duration of each window in seconds. + slide_interval: The interval at which windows slide in seconds. + offset: The offset for window alignment in seconds. +""" + def __init__(self, duration, slide_interval, offset): + self.duration = duration + self.slide_interval = slide_interval + self.offset = offset + + def process(self, element): + """ + Processes an element and assigns it to relevant windows. + + Args: + element: A tuple (timestamp, value) where timestamp is a Timestamp object Review Comment: Can you link Timestamp to the definition in this docstring? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
