apache_beam.transforms.combinefn_lifecycle_pipeline module

class apache_beam.transforms.combinefn_lifecycle_pipeline.CallSequenceEnforcingCombineFn[source]

Bases: apache_beam.transforms.core.CombineFn

instances = {}
setup(*args, **kwargs)[source]
create_accumulator(*args, **kwargs)[source]
add_input(mutable_accumulator, element, *args, **kwargs)[source]
add_inputs(mutable_accumulator, elements, *args, **kwargs)[source]
merge_accumulators(accumulators, *args, **kwargs)[source]
extract_output(accumulator, *args, **kwargs)[source]
teardown(*args, **kwargs)[source]
apply(elements, *args, **kwargs)

Returns result of applying this CombineFn to the input values.

Parameters:
  • elements – the set of values to combine.
  • *args – Additional arguments and side inputs.
  • **kwargs – Additional arguments and side inputs.
compact(accumulator, *args, **kwargs)

Optionally returns a more compact represenation of the accumulator.

This is called before an accumulator is sent across the wire, and can be useful in cases where values are buffered or otherwise lazily kept unprocessed when added to the accumulator. Should return an equivalent, though possibly modified, accumulator.

By default returns the accumulator unmodified.

Parameters:
  • accumulator – the current accumulator
  • *args – Additional arguments and side inputs.
  • **kwargs – Additional arguments and side inputs.
default_label()
default_type_hints()
display_data()

Returns the display data associated to a pipeline component.

It should be reimplemented in pipeline components that wish to have static display data.

Returns:A dictionary containing key:value pairs. The value might be an integer, float or string value; a DisplayDataItem for values that have more data (e.g. short value, label, url); or a HasDisplayData instance that has more display data that should be picked up. For example:
{
  'key1': 'string_value',
  'key2': 1234,
  'key3': 3.14159265,
  'key4': DisplayDataItem('apache.org', url='http://apache.org'),
  'key5': subComponent
}
Return type:Dict[str, Any]
for_input_type(input_type)

Returns a specialized implementation of self, if it exists.

Otherwise, returns self.

Parameters:input_type – the type of input elements.
static from_callable(fn)
classmethod from_runner_api(fn_proto, context)

Converts from an FunctionSpec to a Fn object.

Prefer registering a urn with its parameter type and constructor.

get_accumulator_coder()
get_type_hints()

Gets and/or initializes type hints for this object.

If type hints have not been set, attempts to initialize type hints in this order: - Using self.default_type_hints(). - Using self.__class__ type hints.

static maybe_from_callable(fn, has_side_inputs=True)
classmethod register_pickle_urn(pickle_urn)

Registers and implements the given urn via pickling.

classmethod register_urn(urn, parameter_type, fn=None)

Registers a urn with a constructor.

For example, if ‘beam:fn:foo’ had parameter type FooPayload, one could write RunnerApiFn.register_urn(‘bean:fn:foo’, FooPayload, foo_from_proto) where foo_from_proto took as arguments a FooPayload and a PipelineContext. This function can also be used as a decorator rather than passing the callable in as the final parameter.

A corresponding to_runner_api_parameter method would be expected that returns the tuple (‘beam:fn:foo’, FooPayload)

to_runner_api(context)

Returns an FunctionSpec encoding this Fn.

Prefer overriding self.to_runner_api_parameter.

to_runner_api_parameter(context)
with_input_types(*arg_hints, **kwarg_hints)
with_output_types(*arg_hints, **kwarg_hints)
class apache_beam.transforms.combinefn_lifecycle_pipeline.IndexAssigningDoFn(*unused_args, **unused_kwargs)[source]

Bases: apache_beam.transforms.core.DoFn

state_param = StateParam(index)
process(element, state=StateParam(index))[source]
BundleFinalizerParam

alias of apache_beam.transforms.core._BundleFinalizerParam

DoFnProcessParams = [ElementParam, SideInputParam, TimestampParam, WindowParam, <class 'apache_beam.transforms.core._WatermarkEstimatorParam'>, PaneInfoParam, <class 'apache_beam.transforms.core._BundleFinalizerParam'>, KeyParam, <class 'apache_beam.transforms.core._StateDoFnParam'>, <class 'apache_beam.transforms.core._TimerDoFnParam'>]
DynamicTimerTagParam = DynamicTimerTagParam
ElementParam = ElementParam
KeyParam = KeyParam
PaneInfoParam = PaneInfoParam
RestrictionParam

alias of apache_beam.transforms.core._RestrictionDoFnParam

SideInputParam = SideInputParam
StateParam

alias of apache_beam.transforms.core._StateDoFnParam

TimerParam

alias of apache_beam.transforms.core._TimerDoFnParam

TimestampParam = TimestampParam
WatermarkEstimatorParam

alias of apache_beam.transforms.core._WatermarkEstimatorParam

WindowParam = WindowParam
default_label()
default_type_hints()
display_data()

Returns the display data associated to a pipeline component.

It should be reimplemented in pipeline components that wish to have static display data.

Returns:A dictionary containing key:value pairs. The value might be an integer, float or string value; a DisplayDataItem for values that have more data (e.g. short value, label, url); or a HasDisplayData instance that has more display data that should be picked up. For example:
{
  'key1': 'string_value',
  'key2': 1234,
  'key3': 3.14159265,
  'key4': DisplayDataItem('apache.org', url='http://apache.org'),
  'key5': subComponent
}
Return type:Dict[str, Any]
finish_bundle()

Called after a bundle of elements is processed on a worker.

static from_callable(fn)
classmethod from_runner_api(fn_proto, context)

Converts from an FunctionSpec to a Fn object.

Prefer registering a urn with its parameter type and constructor.

get_function_arguments(func)
get_type_hints()

Gets and/or initializes type hints for this object.

If type hints have not been set, attempts to initialize type hints in this order: - Using self.default_type_hints(). - Using self.__class__ type hints.

infer_output_type(input_type)
classmethod register_pickle_urn(pickle_urn)

Registers and implements the given urn via pickling.

classmethod register_urn(urn, parameter_type, fn=None)

Registers a urn with a constructor.

For example, if ‘beam:fn:foo’ had parameter type FooPayload, one could write RunnerApiFn.register_urn(‘bean:fn:foo’, FooPayload, foo_from_proto) where foo_from_proto took as arguments a FooPayload and a PipelineContext. This function can also be used as a decorator rather than passing the callable in as the final parameter.

A corresponding to_runner_api_parameter method would be expected that returns the tuple (‘beam:fn:foo’, FooPayload)

setup()

Called to prepare an instance for processing bundles of elements.

This is a good place to initialize transient in-memory resources, such as network connections. The resources can then be disposed in DoFn.teardown.

start_bundle()

Called before a bundle of elements is processed on a worker.

Elements to be processed are split into bundles and distributed to workers. Before a worker calls process() on the first element of its bundle, it calls this method.

teardown()

Called to use to clean up this instance before it is discarded.

A runner will do its best to call this method on any given instance to prevent leaks of transient resources, however, there may be situations where this is impossible (e.g. process crash, hardware failure, etc.) or unnecessary (e.g. the pipeline is shutting down and the process is about to be killed anyway, so all transient resources will be released automatically by the OS). In these cases, the call may not happen. It will also not be retried, because in such situations the DoFn instance no longer exists, so there’s no instance to retry it on.

Thus, all work that depends on input elements, and all externally important side effects, must be performed in DoFn.process or DoFn.finish_bundle.

to_runner_api(context)

Returns an FunctionSpec encoding this Fn.

Prefer overriding self.to_runner_api_parameter.

to_runner_api_parameter(context)
static unbounded_per_element()

A decorator on process fn specifying that the fn performs an unbounded amount of work per input element.

with_input_types(*arg_hints, **kwarg_hints)
with_output_types(*arg_hints, **kwarg_hints)
apache_beam.transforms.combinefn_lifecycle_pipeline.run_combine(pipeline, input_elements=5, lift_combiners=True)[source]
apache_beam.transforms.combinefn_lifecycle_pipeline.run_pardo(pipeline, input_elements=10)[source]