apache_beam.typehints.typecheck module¶
Runtime type checking support.
For internal use only; no backwards-compatibility guarantees.
-
class
apache_beam.typehints.typecheck.
AbstractDoFnWrapper
(dofn)[source]¶ Bases:
apache_beam.transforms.core.DoFn
An abstract class to create wrapper around DoFn
-
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]
-
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)
-
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.typehints.typecheck.
OutputCheckWrapperDoFn
(dofn, full_label)[source]¶ Bases:
apache_beam.typehints.typecheck.AbstractDoFnWrapper
A DoFn that verifies against common errors in the output type.
-
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
(*args, **kwargs)¶
-
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)¶
-
process
(*args, **kwargs)¶
-
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
()¶
-
start_bundle
(*args, **kwargs)¶
-
teardown
()¶
-
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.typehints.typecheck.
TypeCheckWrapperDoFn
(dofn, type_hints, label=None)[source]¶ Bases:
apache_beam.typehints.typecheck.AbstractDoFnWrapper
A wrapper around a DoFn which performs type-checking of input and output.
-
static
type_check
(type_constraint, datum, is_input)[source]¶ Typecheck a PTransform related datum according to a type constraint.
This function is used to optionally type-check either an input or an output to a PTransform.
Parameters: - type_constraint – An instance of a typehints.TypeContraint, one of the white-listed builtin Python types, or a custom user class.
- datum – An instance of a Python object.
- is_input – True if ‘datum’ is an input to a PTransform’s DoFn. False otherwise.
Raises: TypeError
– If ‘datum’ fails to type-check according to ‘type_constraint’.
-
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
(*args, **kwargs)¶
-
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
()¶
-
start_bundle
(*args, **kwargs)¶
-
teardown
()¶
-
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)¶
-
static
-
class
apache_beam.typehints.typecheck.
TypeCheckCombineFn
(combinefn, type_hints, label=None)[source]¶ Bases:
apache_beam.transforms.core.CombineFn
A wrapper around a CombineFn performing type-checking of input and output.
-
add_inputs
(mutable_accumulator, elements, *args, **kwargs)¶ Returns the result of folding each element in elements into accumulator.
This is provided in case the implementation affords more efficient bulk addition of elements. The default implementation simply loops over the inputs invoking add_input for each one.
Parameters: - mutable_accumulator – the current accumulator, may be modified and returned for efficiency
- elements – the elements to add, should not be mutated
- *args – Additional arguments and side inputs.
- **kwargs – Additional arguments and side inputs.
-
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.
-
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]
-
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.typehints.typecheck.
TypeCheckVisitor
[source]¶ Bases:
apache_beam.pipeline.PipelineVisitor
-
visit_value
(value, producer_node)¶ Callback for visiting a PValue in the pipeline DAG.
Parameters: - value – PValue visited (typically a PCollection instance).
- producer_node – AppliedPTransform object whose transform produced the pvalue.
-
-
class
apache_beam.typehints.typecheck.
PerformanceTypeCheckVisitor
[source]¶ Bases:
apache_beam.pipeline.PipelineVisitor
-
enter_composite_transform
(transform_node)¶ Callback for entering traversal of a composite transform node.
-
leave_composite_transform
(transform_node)¶ Callback for leaving traversal of a composite transform node.
-
visit_value
(value, producer_node)¶ Callback for visiting a PValue in the pipeline DAG.
Parameters: - value – PValue visited (typically a PCollection instance).
- producer_node – AppliedPTransform object whose transform produced the pvalue.
-