dianfu commented on a change in pull request #9858: [FLINK-14208][python] 
Optimize Python UDFs with parameters of constant values
URL: https://github.com/apache/flink/pull/9858#discussion_r332989251
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/operations.py
 ##########
 @@ -79,6 +82,34 @@ def get(self, value):
         return self.scalar_function_invoker.invoke_eval(value)
 
 
+serializer = PickleSerializer()
+
+
+class ConstantInputGetter(InputGetter):
+    """
+    InputGetter for the input argument which is the constant value.
+
+    :param constant_value: the constant value of the column in the input row
+    """
+
+    def __init__(self, constant_value):
+        j_type = constant_value.value[0]
+        pickled_data = serializer.loads(constant_value.value[1:])
+        if j_type == '\x00' or j_type == 0:
+            self._constant_value = pickled_data
+        elif j_type == '\x01' or j_type == 1:
+            self._constant_value = datetime.date(year=0, month=0, 
day=pickled_data)
+        elif j_type == '\x02' or j_type == 2:
+            self._constant_value = datetime.time(microsecond=pickled_data * 
1000)
+        elif j_type == '\x03' or j_type == 3:
+            self._constant_value = relativedelta(months=pickled_data)
+        elif j_type == '\x04' or j_type == 4:
+            self._constant_value = datetime.timedelta(seconds=pickled_data)
 
 Review comment:
   throw an meaningful exception if non of the above conditions hold?

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