apache_beam.runners.direct.sdf_direct_runner module¶
This module contains Splittable DoFn logic that is specific to DirectRunner.
-
class
apache_beam.runners.direct.sdf_direct_runner.
SplittableParDoOverride
[source]¶ Bases:
apache_beam.pipeline.PTransformOverride
A transform override for ParDo transformss of SplittableDoFns.
Replaces the ParDo transform with a SplittableParDo transform that performs SDF specific logic.
-
get_replacement_inputs
(applied_ptransform)¶ Provides inputs that will be passed to the replacement PTransform.
Parameters: applied_ptransform – Original AppliedPTransform containing the PTransform to be replaced. Returns: An iterable of PValues that will be passed to the expand() method of the replacement PTransform.
-
get_replacement_transform
(ptransform)¶ Provides a runner specific override for a given PTransform.
Parameters: ptransform – PTransform to be replaced. Returns: A PTransform that will be the replacement for the PTransform given as an argument.
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
SplittableParDo
(ptransform)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransform
A transform that processes a PCollection using a Splittable DoFn.
-
annotations
() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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]
-
classmethod
from_runner_api
(proto, context)¶
-
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.
-
get_windowing
(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type
(unused_input_type)¶
-
label
¶
-
pipeline
= None¶
-
classmethod
register_urn
(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input
()¶
-
side_inputs
= ()¶
-
to_runner_api
(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter
(unused_context)¶
-
to_runner_api_pickled
(unused_context)¶
-
type_check_inputs
(pvalueish)¶
-
type_check_inputs_or_outputs
(pvalueish, input_or_output)¶
-
type_check_outputs
(pvalueish)¶
-
with_input_types
(input_type_hint)¶ Annotates the input type of a
PTransform
with a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint
.Raises: TypeError
– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types
(type_hint)¶ Annotates the output type of a
PTransform
with a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint
.Raises: TypeError
– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ElementAndRestriction
(element, restriction, watermark_estimator_state)[source]¶ Bases:
object
A holder for an element, restriction, and watermark estimator state.
-
class
apache_beam.runners.direct.sdf_direct_runner.
PairWithRestrictionFn
(do_fn)[source]¶ Bases:
apache_beam.transforms.core.DoFn
A transform that pairs each element with a restriction.
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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
.
-
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
orDoFn.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)¶
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
SplitRestrictionFn
(do_fn)[source]¶ Bases:
apache_beam.transforms.core.DoFn
A transform that perform initial splitting of Splittable DoFn inputs.
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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
.
-
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
orDoFn.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)¶
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ExplodeWindowsFn
(*unused_args, **unused_kwargs)[source]¶ Bases:
apache_beam.transforms.core.DoFn
A transform that forces the runner to explode windows.
This is done to make sure that Splittable DoFn proceses an element for each of the windows that element belongs to.
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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
orDoFn.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)¶
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
RandomUniqueKeyFn
(*unused_args, **unused_kwargs)[source]¶ Bases:
apache_beam.transforms.core.DoFn
A transform that assigns a unique key to each element.
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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
orDoFn.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)¶
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ProcessKeyedElements
(sdf, element_coder, restriction_coder, windowing_strategy, ptransform_args, ptransform_kwargs, ptransform_side_inputs)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransform
A primitive transform that performs SplittableDoFn magic.
Input to this transform should be a PCollection of keyed ElementAndRestriction objects.
-
annotations
() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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]
-
classmethod
from_runner_api
(proto, context)¶
-
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.
-
get_windowing
(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type
(unused_input_type)¶
-
label
¶
-
pipeline
= None¶
-
classmethod
register_urn
(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input
()¶
-
side_inputs
= ()¶
-
to_runner_api
(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter
(unused_context)¶
-
to_runner_api_pickled
(unused_context)¶
-
type_check_inputs
(pvalueish)¶
-
type_check_inputs_or_outputs
(pvalueish, input_or_output)¶
-
type_check_outputs
(pvalueish)¶
-
with_input_types
(input_type_hint)¶ Annotates the input type of a
PTransform
with a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint
.Raises: TypeError
– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types
(type_hint)¶ Annotates the output type of a
PTransform
with a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint
.Raises: TypeError
– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ProcessKeyedElementsViaKeyedWorkItemsOverride
[source]¶ Bases:
apache_beam.pipeline.PTransformOverride
A transform override for ProcessElements transform.
-
get_replacement_inputs
(applied_ptransform)¶ Provides inputs that will be passed to the replacement PTransform.
Parameters: applied_ptransform – Original AppliedPTransform containing the PTransform to be replaced. Returns: An iterable of PValues that will be passed to the expand() method of the replacement PTransform.
-
get_replacement_transform
(ptransform)¶ Provides a runner specific override for a given PTransform.
Parameters: ptransform – PTransform to be replaced. Returns: A PTransform that will be the replacement for the PTransform given as an argument.
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ProcessKeyedElementsViaKeyedWorkItems
(process_keyed_elements_transform)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransform
A transform that processes Splittable DoFn input via KeyedWorkItems.
-
annotations
() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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]
-
classmethod
from_runner_api
(proto, context)¶
-
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.
-
get_windowing
(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type
(unused_input_type)¶
-
label
¶
-
pipeline
= None¶
-
classmethod
register_urn
(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input
()¶
-
side_inputs
= ()¶
-
to_runner_api
(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter
(unused_context)¶
-
to_runner_api_pickled
(unused_context)¶
-
type_check_inputs
(pvalueish)¶
-
type_check_inputs_or_outputs
(pvalueish, input_or_output)¶
-
type_check_outputs
(pvalueish)¶
-
with_input_types
(input_type_hint)¶ Annotates the input type of a
PTransform
with a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint
.Raises: TypeError
– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types
(type_hint)¶ Annotates the output type of a
PTransform
with a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint
.Raises: TypeError
– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ProcessElements
(process_keyed_elements_transform)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransform
A primitive transform for processing keyed elements or KeyedWorkItems.
Will be evaluated by runners.direct.transform_evaluator._ProcessElementsEvaluator.
-
annotations
() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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]
-
classmethod
from_runner_api
(proto, context)¶
-
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.
-
get_windowing
(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type
(unused_input_type)¶
-
label
¶
-
pipeline
= None¶
-
classmethod
register_urn
(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input
()¶
-
side_inputs
= ()¶
-
to_runner_api
(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter
(unused_context)¶
-
to_runner_api_pickled
(unused_context)¶
-
type_check_inputs
(pvalueish)¶
-
type_check_inputs_or_outputs
(pvalueish, input_or_output)¶
-
type_check_outputs
(pvalueish)¶
-
with_input_types
(input_type_hint)¶ Annotates the input type of a
PTransform
with a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint
.Raises: TypeError
– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types
(type_hint)¶ Annotates the output type of a
PTransform
with a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint
.Raises: TypeError
– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()
for further details.Returns: A reference to the instance of this particular PTransform
object. This allows chaining type-hinting related methods.Return type: PTransform
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
ProcessFn
(sdf, args_for_invoker, kwargs_for_invoker)[source]¶ Bases:
apache_beam.transforms.core.DoFn
A DoFn that executes machineary for invoking a Splittable DoFn.
Input to the ParDo step that includes a ProcessFn will be a PCollection of ElementAndRestriction objects.
This class is mainly responsible for following. (1) setup environment for properly invoking a Splittable DoFn. (2) invoke process() method of a Splittable DoFn. (3) after the process() invocation of the Splittable DoFn, determine if a re-invocation of the element is needed. If this is the case, set state and a timer for a re-invocation and hold output watermark till this re-invocation. (4) after the final invocation of a given element clear any previous state set for re-invoking the element and release the output watermark.
-
step_context
¶
-
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; aDisplayDataItem
for values that have more data (e.g. short value, label, url); or aHasDisplayData
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
orDoFn.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)¶
-
-
class
apache_beam.runners.direct.sdf_direct_runner.
SDFProcessElementInvoker
(max_num_outputs, max_duration)[source]¶ Bases:
object
A utility that invokes SDF process() method and requests checkpoints.
This class is responsible for invoking the process() method of a Splittable DoFn and making sure that invocation terminated properly. Based on the input configuration, this class may decide to request a checkpoint for a process() execution so that runner can process current output and resume the invocation at a later time.
More specifically, when initializing a SDFProcessElementInvoker, caller may specify the number of output elements or processing time after which a checkpoint should be requested. This class is responsible for properly requesting a checkpoint based on either of these criteria. When the process() call of Splittable DoFn ends, this class performs validations to make sure that processing ended gracefully and returns a SDFProcessElementInvoker.Result that contains information which can be used by the caller to perform another process() invocation for the residual.
A process() invocation may decide to give up processing voluntarily by returning a ProcessContinuation object (see documentation of ProcessContinuation for more details). So if a ‘ProcessContinuation’ is produced this class ends the execution and performs steps to finalize the current invocation.
-
class
Result
(residual_restriction=None, process_continuation=None, future_output_watermark=None)[source]¶ Bases:
object
Returned as a result of a invoke_process_element() invocation.
Parameters: - residual_restriction – a restriction for the unprocessed part of the element.
- process_continuation – a ProcessContinuation if one was returned as the last element of the SDF process() invocation.
- future_output_watermark – output watermark of the results that will be produced when invoking the Splittable DoFn for the current element with residual_restriction.
-
invoke_process_element
(sdf_invoker, output_processor, element, restriction, watermark_estimator_state, *args, **kwargs)[source]¶ Invokes process() method of a Splittable DoFn for a given element.
Parameters: - sdf_invoker – a DoFnInvoker for the Splittable DoFn.
- element – the element to process
Returns: a SDFProcessElementInvoker.Result object.
-
class