@Internal public abstract class BeamPythonFunctionRunner extends Object implements PythonFunctionRunner
BeamPythonFunctionRunner
used to execute Python functions.Modifier and Type | Field and Description |
---|---|
protected FlinkFnApi.CoderInfoDescriptor |
inputCoderDescriptor |
protected static org.slf4j.Logger |
LOG |
protected org.apache.beam.sdk.fn.data.FnDataReceiver<org.apache.beam.sdk.util.WindowedValue<byte[]>> |
mainInputReceiver
The receiver which forwards the input elements to a remote environment for processing.
|
protected FlinkFnApi.CoderInfoDescriptor |
outputCoderDescriptor |
protected LinkedBlockingQueue<Tuple2<String,byte[]>> |
resultBuffer
Buffers the Python function execution result which has still not been processed.
|
protected Map<String,FlinkFnApi.CoderInfoDescriptor> |
sideOutputCoderDescriptors |
Constructor and Description |
---|
BeamPythonFunctionRunner(String taskName,
ProcessPythonEnvironmentManager environmentManager,
FlinkMetricContainer flinkMetricContainer,
KeyedStateBackend<?> keyedStateBackend,
OperatorStateBackend operatorStateBackend,
TypeSerializer<?> keySerializer,
TypeSerializer<?> namespaceSerializer,
TimerRegistration timerRegistration,
MemoryManager memoryManager,
double managedMemoryFraction,
FlinkFnApi.CoderInfoDescriptor inputCoderDescriptor,
FlinkFnApi.CoderInfoDescriptor outputCoderDescriptor,
Map<String,FlinkFnApi.CoderInfoDescriptor> sideOutputCoderDescriptors) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
buildTransforms(org.apache.beam.model.pipeline.v1.RunnerApi.Components.Builder componentsBuilder) |
void |
close()
Tear-down the Python function runner.
|
org.apache.beam.runners.fnexecution.control.JobBundleFactory |
createJobBundleFactory(org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.Struct pipelineOptions) |
void |
flush()
Forces to finish the processing of the current bundle of elements.
|
protected abstract Optional<org.apache.beam.model.pipeline.v1.RunnerApi.Coder> |
getOptionalTimerCoderProto() |
protected abstract List<org.apache.beam.runners.core.construction.graph.TimerReference> |
getTimers(org.apache.beam.model.pipeline.v1.RunnerApi.Components components) |
void |
notifyNoMoreResults()
Interrupts the progress of takeResult.
|
void |
open(ReadableConfig config)
Prepares the Python function runner, such as preparing the Python execution environment, etc.
|
Tuple3<String,byte[],Integer> |
pollResult()
Retrieves the Python function result.
|
void |
process(byte[] data)
Executes the Python function with the input byte array.
|
void |
processTimer(byte[] timerData)
Send the triggered timer to the Python function.
|
protected void |
startBundle() |
Tuple3<String,byte[],Integer> |
takeResult()
Retrieves the Python function result, waiting if necessary until an element becomes
available.
|
protected static final org.slf4j.Logger LOG
protected final FlinkFnApi.CoderInfoDescriptor inputCoderDescriptor
protected final FlinkFnApi.CoderInfoDescriptor outputCoderDescriptor
protected final Map<String,FlinkFnApi.CoderInfoDescriptor> sideOutputCoderDescriptors
@VisibleForTesting protected transient LinkedBlockingQueue<Tuple2<String,byte[]>> resultBuffer
@VisibleForTesting protected transient org.apache.beam.sdk.fn.data.FnDataReceiver<org.apache.beam.sdk.util.WindowedValue<byte[]>> mainInputReceiver
public BeamPythonFunctionRunner(String taskName, ProcessPythonEnvironmentManager environmentManager, @Nullable FlinkMetricContainer flinkMetricContainer, @Nullable KeyedStateBackend<?> keyedStateBackend, @Nullable OperatorStateBackend operatorStateBackend, @Nullable TypeSerializer<?> keySerializer, @Nullable TypeSerializer<?> namespaceSerializer, @Nullable TimerRegistration timerRegistration, MemoryManager memoryManager, double managedMemoryFraction, FlinkFnApi.CoderInfoDescriptor inputCoderDescriptor, FlinkFnApi.CoderInfoDescriptor outputCoderDescriptor, Map<String,FlinkFnApi.CoderInfoDescriptor> sideOutputCoderDescriptors)
public void open(ReadableConfig config) throws Exception
PythonFunctionRunner
open
in interface PythonFunctionRunner
Exception
public void close() throws Exception
PythonFunctionRunner
close
in interface AutoCloseable
close
in interface PythonFunctionRunner
Exception
public void process(byte[] data) throws Exception
PythonFunctionRunner
process
in interface PythonFunctionRunner
data
- the byte array data.Exception
public void processTimer(byte[] timerData) throws Exception
PythonFunctionRunner
processTimer
in interface PythonFunctionRunner
Exception
@VisibleForTesting protected void startBundle()
public Tuple3<String,byte[],Integer> pollResult() throws Exception
PythonFunctionRunner
pollResult
in interface PythonFunctionRunner
null
if the result buffer is
empty. f0 means the byte array buffer which stores the Python function result. f1 means
the length of the Python function result byte array.Exception
public Tuple3<String,byte[],Integer> takeResult() throws Exception
PythonFunctionRunner
takeResult
in interface PythonFunctionRunner
Exception
public void flush() throws Exception
PythonFunctionRunner
flush
in interface PythonFunctionRunner
Exception
public void notifyNoMoreResults()
protected abstract void buildTransforms(org.apache.beam.model.pipeline.v1.RunnerApi.Components.Builder componentsBuilder)
protected abstract List<org.apache.beam.runners.core.construction.graph.TimerReference> getTimers(org.apache.beam.model.pipeline.v1.RunnerApi.Components components)
protected abstract Optional<org.apache.beam.model.pipeline.v1.RunnerApi.Coder> getOptionalTimerCoderProto()
@VisibleForTesting public org.apache.beam.runners.fnexecution.control.JobBundleFactory createJobBundleFactory(org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.Struct pipelineOptions) throws Exception
Exception
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.