WeiZhong94 commented on a change in pull request #14816:
URL: https://github.com/apache/flink/pull/14816#discussion_r584725808



##########
File path: flink-python/pyflink/fn_execution/window.py
##########
@@ -0,0 +1,126 @@
+################################################################################
+#  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 sys
+from abc import ABC, abstractmethod
+
+MAX_LONG_VALUE = sys.maxsize
+
+
+def long_to_int_with_bit_mixing(x: int) -> int:
+    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
+    x = (x ^ (x >> 27)) * 0x94d049bb133111eb
+    x = x ^ (x >> 31)
+    return x
+
+
+def mod_inverse(x: int) -> int:
+    inverse = x * x * x
+    inverse *= 2 - x * inverse
+    inverse *= 2 - x * inverse
+    inverse *= 2 - x * inverse
+    return inverse
+
+
+class Window(ABC):
+    """
+    Window is a grouping of elements into finite buckets. Windows have a 
maximum timestamp
+    which means that, at some point, all elements that go into one window will 
have arrived.
+    """
+
+    @abstractmethod
+    def max_timestamp(self) -> int:
+        pass
+
+
+class TimeWindow(Window):
+    """
+    Window that represents a time interval from start (inclusive) to end 
(exclusive).
+    """
+
+    def __init__(self, start: int, end: int):
+        super(TimeWindow, self).__init__()
+        self.start = start
+        self.end = end
+
+    def max_timestamp(self) -> int:
+        return self.end - 1
+
+    def intersects(self, other: 'TimeWindow') -> bool:
+        """
+        Returns True if this window intersects the given window.
+        """
+        return self.start <= other.end and self.end >= other.start
+
+    def cover(self, other: 'TimeWindow') -> 'TimeWindow':
+        """
+        Returns the minimal window covers both this window and the given 
window.
+        """
+        return TimeWindow(min(self.start, other.start), max(self.end, 
other.end))
+
+    @staticmethod
+    def get_window_start_with_offset(timestamp: int, offset: int, window_size: 
int):
+        """
+        Method to get the window start for a timestamp.

Review comment:
       Leaving a blank line between the description and parameters will be more 
readable

##########
File path: flink-python/pyflink/fn_execution/coder_impl_fast.pyx
##########
@@ -811,6 +813,42 @@ cdef class FlattenRowCoderImpl(BaseCoderImpl):
         if self._field_coder_type:
             free(self._field_coder_type)
 
+cdef class WindowCoderImpl(BaseCoderImpl):
+    def __init__(self):
+        self._tmp_output_pos = 0
+        self._tmp_output_data = <char*> malloc(16)
+
+    cpdef bytes encode_nested(self, value):
+        pass
+
+    cdef void _encode_bigint(self, libc.stdint.int64_t v):
+        self._tmp_output_data[self._tmp_output_pos] = <unsigned char> (v >> 56)
+        self._tmp_output_data[self._tmp_output_pos + 1] = <unsigned char> (v 
>> 48)
+        self._tmp_output_data[self._tmp_output_pos + 2] = <unsigned char> (v 
>> 40)
+        self._tmp_output_data[self._tmp_output_pos + 3] = <unsigned char> (v 
>> 32)
+        self._tmp_output_data[self._tmp_output_pos + 4] = <unsigned char> (v 
>> 24)
+        self._tmp_output_data[self._tmp_output_pos + 5] = <unsigned char> (v 
>> 16)
+        self._tmp_output_data[self._tmp_output_pos + 6] = <unsigned char> (v 
>> 8)
+        self._tmp_output_data[self._tmp_output_pos + 7] = <unsigned char> v
+        self._tmp_output_pos += 8
+
+    def __dealloc__(self):
+        if self._tmp_output_data:
+            free(self._tmp_output_data)
+
+cdef class TimeWindowCoderImpl(WindowCoderImpl):
+

Review comment:
       Unnecessary blank line




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


Reply via email to