hequn8128 commented on a change in pull request #9766: [FLINK-14018][python] 
Add Python building blocks to make sure the basic functionality of Python 
ScalarFunction could work
URL: https://github.com/apache/flink/pull/9766#discussion_r329310696
 
 

 ##########
 File path: flink-python/pyflink/table/udf.py
 ##########
 @@ -0,0 +1,217 @@
+################################################################################
+#  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 collections
+import functools
+import inspect
+from abc import ABCMeta, abstractmethod
+
+from pyflink.java_gateway import get_gateway
+from pyflink.table.types import DataType, _to_java_type
+from pyflink.util import utils
+
+__all__ = ['FunctionContext', 'ScalarFunction', 'udf']
+
+
+class FunctionContext(object):
+    """
+    Used to obtain global runtime information about the context in which the
+    user-defined function is executed. The information includes the metric 
group,
+    and global job parameters, etc.
+    """
+    pass
+
+
+class UserDefinedFunction(object):
+    """
+    Base interface for user-defined function.
+    """
+    __metaclass__ = ABCMeta
+
+    def open(self, function_context):
+        """
+        Initialization method for the function. It is called before the actual 
working methods
+        and thus suitable for one time setup work.
+
+        :param function_context: the context of the function
+        :type function_context: FunctionContext
+        """
+        pass
+
+    def close(self):
+        """
+        Tear-down method for the user code. It is called after the last call 
to the main
+        working methods.
+        """
+        pass
+
+    def is_deterministic(self):
+        """
+        Returns information about the determinism of the function's results.
+        It returns true if and only if a call to this function is guaranteed to
+        always return the same result given the same parameters. true is 
assumed by default.
+        If the function is not pure functional like random(), date(), now(),
+        this method must return false.
+
+        :return: the determinism of the function's results.
+        :rtype: bool
+        """
+        return True
+
+
+class ScalarFunction(UserDefinedFunction):
+    """
+    Base interface for user-defined scalar function. A user-defined scalar 
functions maps zero, one,
+    or multiple scalar values to a new scalar value.
+    """
+
+    @abstractmethod
+    def eval(self, *args):
+        """
+        Method which defines the logic of the scalar function.
+        """
+        pass
+
+
+class LambdaScalarFunction(ScalarFunction):
 
 Review comment:
   This class is used for both lambda and python functions. Maybe we can change 
the name to `DelegatingScalarFunction`? (Also change the comments below)

----------------------------------------------------------------
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