WeiZhong94 commented on a change in pull request #9707: [FLINK-14015][python] 
Introduces PythonScalarFunctionOperator to execute Python user-defined functions
URL: https://github.com/apache/flink/pull/9707#discussion_r326985782
 
 

 ##########
 File path: 
flink-python/src/main/java/org/apache/flink/streaming/api/operators/python/AbstractPythonFunctionOperator.java
 ##########
 @@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.api.operators.python;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.python.PythonFunctionRunner;
+import org.apache.flink.python.PythonOptions;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Base class for all stream operators to execute Python functions.
+ */
+@Internal
+public abstract class AbstractPythonFunctionOperator<IN, OUT>
+               extends AbstractStreamOperator<OUT>
+               implements OneInputStreamOperator<IN, OUT>, BoundedOneInput {
+
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * The {@link PythonFunctionRunner} which is responsible for Python 
user-defined function execution.
+        */
+       private transient PythonFunctionRunner<IN> pythonFunctionRunner;
+
+       /**
+        * Use an AtomicBoolean because we start/stop bundles by a timer thread.
+        */
+       private transient AtomicBoolean bundleStarted;
+
+       /**
+        * Number of processed elements in the current bundle.
+        */
+       private transient int elementCount;
+
+       /**
+        * Max number of elements to include in a bundle.
+        */
+       private transient int maxBundleSize;
+
+       /**
+        * Max duration of a bundle.
+        */
+       private transient long maxBundleTimeMills;
+
+       /**
+        * Time that the last bundle was finished.
+        */
+       private transient long lastFinishBundleTime;
+
+       /**
+        * A timer that finishes the current bundle after a fixed amount of 
time.
+        */
+       private transient ScheduledFuture<?> checkFinishBundleTimer;
+
+       /**
+        * Callback to be executed after the current bundle was finished.
+        */
+       private transient Runnable bundleFinishedCallback;
+
+       @Override
+       public void open() throws Exception {
+               try {
+                       this.bundleStarted = new AtomicBoolean(false);
+
+                       this.maxBundleSize = 
getOperatorConfig().getConfiguration().getInteger(PythonOptions.MAX_BUNDLE_SIZE);
 
 Review comment:
   `getOperatorConfig().getConfiguration()` returns the task configuration of 
specific JobVertex. Maybe using ExecutionConfig#getGlobalJobParameters() is 
better?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to