- 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 thisPTransformshould 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 theCoderof the outputPCollections produced by this transform.withOutputCoders(Map<String, Coder<?>> outputCoders) Specifies the keys andCoders of the outputPCollections 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
PTransformclass, 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 (orsourcekeyword argument) should be aPythonCallableSourcewhich represents the expand method of thePTransformaccepting 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 (orsourcekeyword argument) should be aPythonCallableSourcewhich will return the desired PTransform when called with the remaining arguments and keyword arguments. Often this will be aPythonCallableSourcerepresenting a PTransform class, for examplePythonExternalTransform .from("__constructor__") .withArgs( PythonCallable.of("class MyPTransform(beam.PTransform): ..."), ...valuesForMyPTransformConstructorIfAny);- Type Parameters:
InputT- InputPCollectiontypeOutputT- OutputPCollectiontype- Parameters:
transformName- fully qualified transform name.- Returns:
- A
PythonExternalTransformfor 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- InputPCollectiontypeOutputT- OutputPCollectiontype- Parameters:
transformName- fully qualified transform name.expansionService- address and port number for externally launched expansion service- Returns:
- A
PythonExternalTransformfor 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 aRowobjects. 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 andCoders of the outputPCollections produced by this transform.- Parameters:
outputCoders- a mapping from output keys toCoders.- Returns:
- updated wrapper for the cross-language transform.
-
withOutputCoder
Specifies theCoderof the outputPCollections produced by this transform. Should only be used if this transform produces a single output.- Parameters:
outputCoder- outputCoderof 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:PTransformOverride this method to specify how thisPTransformshould be expanded on the givenInputT.NOTE: This method should not be called directly. Instead apply the
PTransformshould be applied to theInputTusing theapplymethod.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).
-