- All Implemented Interfaces:
Serializable
,HasDisplayData
- See Also:
-
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Method Summary
Modifier and TypeMethodDescriptionOverride this method to specify how thisPTransform
should be expanded on the givenInputT
.static <InputT extends PInput,
OutputT extends POutput>
PythonExternalTransform<InputT, OutputT> Instantiates a cross-language wrapper for a Python transform with a given transform name.static <InputT extends PInput,
OutputT extends POutput>
PythonExternalTransform<InputT, OutputT> Instantiates a cross-language wrapper for a Python transform with a given transform name.Positional arguments for the Python cross-language transform.withExtraPackages
(List<String> extraPackages) Specifies that the given Python packages are required for this transform, which will cause them to be installed in both the construction-time and execution time environment.Specifies a single keyword argument for the Python cross-language transform.withKwargs
(Map<String, Object> kwargs) Specifies keyword arguments for the Python cross-language transform.withKwargs
(Row kwargs) Specifies keyword arguments as a Row objects.withOutputCoder
(Coder<?> outputCoder) Specifies theCoder
of the outputPCollection
s produced by this transform.withOutputCoders
(Map<String, Coder<?>> outputCoders) Specifies the keys andCoder
s of the outputPCollection
s produced by this transform.withTypeHint
(Class<?> argType, Schema.FieldType fieldType) Specifies the field type of arguments.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
-
Method Details
-
from
public static <InputT extends PInput,OutputT extends POutput> PythonExternalTransform<InputT,OutputT> from(String transformName) Instantiates a cross-language wrapper for a Python transform with a given transform name.The given fully qualified name will be imported and called to instantiate the transform. Often this is the fully qualified name of a Python
PTransform
class, in which case the arguments will be passed to its constructor, but any callable will do.Two special names,
__callable__
and__constructor__
can be used to define a suitable transform inline if none exists.When
__callable__
is provided, the first argument (orsource
keyword argument) should be aPythonCallableSource
which represents the expand method of thePTransform
accepting and returning aPValue
(and may also take additional arguments and keyword arguments). For example, one might writePythonExternalTransform .from("__callable__") .withArgs( PythonCallable.of("def expand(pcoll, x, y): return pcoll | ..."), valueForX, valueForY);
When
__constructor__
is provided, the first argument (orsource
keyword argument) should be aPythonCallableSource
which will return the desired PTransform when called with the remaining arguments and keyword arguments. Often this will be aPythonCallableSource
representing a PTransform class, for examplePythonExternalTransform .from("__constructor__") .withArgs( PythonCallable.of("class MyPTransform(beam.PTransform): ..."), ...valuesForMyPTransformConstructorIfAny);
- Type Parameters:
InputT
- InputPCollection
typeOutputT
- OutputPCollection
type- Parameters:
transformName
- fully qualified transform name.- Returns:
- A
PythonExternalTransform
for the given transform name.
-
from
public static <InputT extends PInput,OutputT extends POutput> PythonExternalTransform<InputT,OutputT> from(String transformName, String expansionService) Instantiates a cross-language wrapper for a Python transform with a given transform name.See
from(String)
for the meaning of transformName.- Type Parameters:
InputT
- InputPCollection
typeOutputT
- OutputPCollection
type- Parameters:
transformName
- fully qualified transform name.expansionService
- address and port number for externally launched expansion service- Returns:
- A
PythonExternalTransform
for the given transform name.
-
withArgs
Positional arguments for the Python cross-language transform. If invoked more than once, new arguments will be appended to the previously specified arguments.- Parameters:
args
- list of arguments.- Returns:
- updated wrapper for the cross-language transform.
-
withKwarg
Specifies a single keyword argument for the Python cross-language transform. This may be invoked multiple times to add more than one keyword argument.- Parameters:
name
- argument name.value
- argument value- Returns:
- updated wrapper for the cross-language transform.
-
withKwargs
Specifies keyword arguments for the Python cross-language transform. If invoked more than once, new keyword arguments map will be added to the previously prided keyword arguments.- Returns:
- updated wrapper for the cross-language transform.
-
withKwargs
Specifies keyword arguments as a Row objects.- Parameters:
kwargs
- keyword arguments as aRow
objects. An empty Row represents zero keyword arguments.- Returns:
- updated wrapper for the cross-language transform.
-
withTypeHint
public PythonExternalTransform<InputT,OutputT> withTypeHint(Class<?> argType, Schema.FieldType fieldType) Specifies the field type of arguments.Type hints are especially useful for logical types since type inference does not work well for logical types.
- Parameters:
argType
- A class object for the argument type.fieldType
- A schema field type for the argument.- Returns:
- updated wrapper for the cross-language transform.
-
withOutputCoders
Specifies the keys andCoder
s of the outputPCollection
s produced by this transform.- Parameters:
outputCoders
- a mapping from output keys toCoder
s.- Returns:
- updated wrapper for the cross-language transform.
-
withOutputCoder
Specifies theCoder
of the outputPCollection
s produced by this transform. Should only be used if this transform produces a single output.- Parameters:
outputCoder
- outputCoder
of the transform.- Returns:
- updated wrapper for the cross-language transform.
-
withExtraPackages
Specifies that the given Python packages are required for this transform, which will cause them to be installed in both the construction-time and execution time environment.- Parameters:
extraPackages
- a list of pip-installable package specifications, such as would be found in a requirements file.- Returns:
- updated wrapper for the cross-language transform.
-
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
-