hequn8128 commented on a change in pull request #10017: [FLINK-14019][python] 
add support for managing environment and dependencies of Python UDF in Flink 
Python API
URL: https://github.com/apache/flink/pull/10017#discussion_r342009003
 
 

 ##########
 File path: flink-python/pyflink/common/dependency_manager.py
 ##########
 @@ -0,0 +1,106 @@
+################################################################################
+#  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.
+################################################################################
+import json
+import os
+import uuid
+
+__all__ = ['DependencyManager']
+
+
+class DependencyManager(object):
+    """
+    Container class of dependency-related parameters. It collects all the 
dependency parameters
+    and transmit them to JVM before executing job.
+    """
+
+    PYTHON_FILE_PREFIX = "python_file"
+    PYTHON_REQUIREMENTS_FILE_PREFIX = "python_requirements_file"
+    PYTHON_REQUIREMENTS_CACHE_PREFIX = "python_requirements_cache"
+    PYTHON_ARCHIVE_PREFIX = "python_archive"
+
+    PYTHON_FILE_MAP = "PYTHON_FILE_MAP"
+    PYTHON_REQUIREMENTS_FILE = "PYTHON_REQUIREMENTS_FILE"
+    PYTHON_REQUIREMENTS_CACHE = "PYTHON_REQUIREMENTS_CACHE"
+    PYTHON_ARCHIVES_MAP = "PYTHON_ARCHIVES_MAP"
+    PYTHON_EXEC = "PYTHON_EXEC"
+
+    def __init__(self, parameters, j_env):
+        self._parameters = parameters
+        self._j_env = j_env
+        self._python_file_map = dict()  # type: dict[str, str]
+        self._archives_map = dict()  # type: dict[str, str]
+        self._counter_map = dict()  # type: dict[str, int]
+
+    def _generate_file_key(self, prefix):
+        if prefix not in self._counter_map:
+            self._counter_map[prefix] = 0
+        else:
+            self._counter_map[prefix] += 1
+        return "%s_%d_%s" % (prefix, self._counter_map[prefix], uuid.uuid4())
+
+    def add_python_file(self, file_path):
+        key = self._generate_file_key(DependencyManager.PYTHON_FILE_PREFIX)
+        self._python_file_map[key] = os.path.basename(file_path)
+        self._parameters.set_string(
+            DependencyManager.PYTHON_FILE_MAP, 
json.dumps(self._python_file_map))
+        self.register_file(key, file_path)
+
+    def set_python_requirements(self, requirements_file_path, 
requirements_cached_dir=None):
+
+        if 
self._parameters.contains_key(DependencyManager.PYTHON_REQUIREMENTS_FILE):
+            self.remove_file(
+                
self._parameters.get_string(DependencyManager.PYTHON_REQUIREMENTS_FILE, ""))
+            
self._parameters.remove_config(DependencyManager.PYTHON_REQUIREMENTS_FILE)
 
 Review comment:
   Add a meaningful method for this? For example, removeIfDelete() and it can 
also be used to remove requirements_cached.
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to