github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/io/external/generate_sequence.py (about)

     1  #
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  # pytype: skip-file
    19  
    20  from apache_beam.transforms.external import ExternalTransform
    21  from apache_beam.transforms.external import ImplicitSchemaPayloadBuilder
    22  
    23  
    24  class GenerateSequence(ExternalTransform):
    25    """
    26      An external PTransform which provides a bounded or unbounded stream of
    27      integers.
    28  
    29      Note: To use this transform, you need to start the Java expansion service.
    30      Please refer to the portability documentation on how to do that. The
    31      expansion service address has to be provided when instantiating this
    32      transform. During pipeline translation this transform will be replaced by
    33      the Java SDK's GenerateSequence.
    34  
    35      If you start Flink's job server, the expansion service will be started on
    36      port 8097. This is also the configured default for this transform. For a
    37      different address, please set the expansion_service parameter.
    38  
    39      For more information see:
    40      - https://beam.apache.org/documentation/runners/flink/
    41      - https://beam.apache.org/roadmap/portability/
    42  
    43      Note: Runners need to support translating Read operations in order to use
    44      this source. At the moment only the Flink Runner supports this.
    45  
    46      Experimental; no backwards compatibility guarantees.
    47    """
    48    URN = 'beam:external:java:generate_sequence:v1'
    49  
    50    def __init__(
    51        self,
    52        start,
    53        stop=None,
    54        elements_per_period=None,
    55        max_read_time=None,
    56        expansion_service=None):
    57      super().__init__(
    58          self.URN,
    59          ImplicitSchemaPayloadBuilder({
    60              'start': start,
    61              'stop': stop,
    62              'elements_per_period': elements_per_period,
    63              'max_read_time': max_read_time,
    64          }),
    65          expansion_service)