Skip to content

Commit

Permalink
[FLINK-26607][python] Correct the MAX_LONG_VALUE/MIN_LONG_VALUE in se…
Browse files Browse the repository at this point in the history
…veral places

This closes apache#19089.
  • Loading branch information
cun8cun8 authored and zhuyuan03 committed Jul 4, 2022
1 parent 0208df2 commit 67ea2c6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 deletions.
25 changes: 25 additions & 0 deletions flink-python/pyflink/common/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
################################################################################
# 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.
################################################################################
"""
A constant holding the maximum value a long can have, 2^63 – 1.
"""
MAX_LONG_VALUE = 0x7fffffffffffffff
"""
A constant holding the minimum value a long can have, -2^63
"""
MIN_LONG_VALUE = - MAX_LONG_VALUE - 1
10 changes: 1 addition & 9 deletions flink-python/pyflink/datastream/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import TypeVar, Generic, Iterable, Collection, Any, cast

from pyflink.common import Time, Types
from pyflink.common.constants import MAX_LONG_VALUE, MIN_LONG_VALUE
from pyflink.common.serializer import TypeSerializer
from pyflink.datastream.functions import RuntimeContext, InternalWindowFunction
from pyflink.datastream.state import StateDescriptor, ReducingStateDescriptor, \
Expand Down Expand Up @@ -52,15 +53,6 @@
'CountWindowSerializer',
'SessionWindowTimeGapExtractor']

"""
A constant holding the maximum value a long can have, 2^63 – 1.
"""
MAX_LONG_VALUE = 0x7fffffffffffffff
"""
A constant holding the minimum value a long can have, -2^63
"""
MIN_LONG_VALUE = - MAX_LONG_VALUE - 1


def long_to_int_with_bit_mixing(x: int) -> int:
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import typing
from typing import TypeVar, Iterable, Collection

from pyflink.common.constants import MAX_LONG_VALUE
from pyflink.datastream import WindowAssigner, Trigger, MergingWindowAssigner, TriggerResult
from pyflink.datastream.functions import KeyedStateStore, RuntimeContext, InternalWindowFunction
from pyflink.datastream.state import StateDescriptor, ListStateDescriptor, \
ReducingStateDescriptor, AggregatingStateDescriptor, ValueStateDescriptor, MapStateDescriptor, \
State, AggregatingState, ReducingState, MapState, ListState, ValueState, AppendingState
from pyflink.fn_execution.datastream.timerservice import InternalTimerService
from pyflink.datastream.window import MAX_LONG_VALUE
from pyflink.fn_execution.datastream.window.merging_window_set import MergingWindowSet
from pyflink.fn_execution.internal_state import InternalMergingState, InternalKvState, \
InternalAppendingState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ from pyflink.fn_execution.table.aggregate_fast cimport DistinctViewDescriptor, R
from pyflink.fn_execution.coder_impl_fast cimport InternalRowKind

import datetime
import sys
from typing import List, Dict

import pytz

from pyflink.common.constants import MAX_LONG_VALUE
from pyflink.fn_execution.datastream.timerservice_impl import LegacyInternalTimerServiceImpl
from pyflink.fn_execution.coders import PickleCoder
from pyflink.fn_execution.table.state_data_view import DataViewSpec, ListViewSpec, MapViewSpec, \
Expand All @@ -42,8 +42,6 @@ from pyflink.fn_execution.table.window_process_function import GeneralWindowProc
from pyflink.fn_execution.table.window_trigger import Trigger
from pyflink.table.udf import ImperativeAggregateFunction

MAX_LONG_VALUE = sys.maxsize

cdef InternalRow join_row(list left, list right, InternalRowKind row_kind):
return InternalRow(left.__add__(right), row_kind)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# limitations under the License.
################################################################################
import datetime
import sys
from abc import ABC, abstractmethod
from typing import TypeVar, Generic, List, Dict

import pytz

from pyflink.common import Row, RowKind
from pyflink.common.constants import MAX_LONG_VALUE
from pyflink.fn_execution.datastream.timerservice import InternalTimer
from pyflink.fn_execution.datastream.timerservice_impl import LegacyInternalTimerServiceImpl
from pyflink.fn_execution.coders import PickleCoder
Expand All @@ -37,7 +37,6 @@
from pyflink.fn_execution.table.window_trigger import Trigger
from pyflink.table.udf import ImperativeAggregateFunction, FunctionContext

MAX_LONG_VALUE = sys.maxsize

N = TypeVar('N')

Expand Down
4 changes: 1 addition & 3 deletions flink-python/pyflink/fn_execution/table/window_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
import sys
from abc import ABC, abstractmethod
from typing import Generic, TypeVar, List, Iterable

from pyflink.common.constants import MAX_LONG_VALUE
from pyflink.datastream.state import StateDescriptor, State, ValueStateDescriptor, \
ListStateDescriptor, MapStateDescriptor
from pyflink.datastream.window import TimeWindow, CountWindow
from pyflink.fn_execution.datastream.timerservice_impl import LegacyInternalTimerServiceImpl
from pyflink.fn_execution.coders import from_type_info, MapCoder, GenericArrayCoder
from pyflink.fn_execution.internal_state import InternalMergingState

MAX_LONG_VALUE = sys.maxsize

K = TypeVar('K')
W = TypeVar('W', TimeWindow, CountWindow)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
import sys
from abc import abstractmethod, ABC
from typing import Generic, List, Iterable, Dict, Set

from pyflink.common import Row
from pyflink.common.constants import MAX_LONG_VALUE
from pyflink.datastream.state import MapState
from pyflink.fn_execution.table.window_assigner import WindowAssigner, PanedWindowAssigner, \
MergingWindowAssigner
from pyflink.fn_execution.table.window_context import Context, K, W

MAX_LONG_VALUE = sys.maxsize


def join_row(left: List, right: List):
return Row(*(left + right))
Expand Down
5 changes: 1 addition & 4 deletions flink-python/pyflink/table/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
import sys
import time
from abc import abstractmethod
from decimal import Decimal

from pyflink.common.constants import MAX_LONG_VALUE, MIN_LONG_VALUE
from pyflink.table import AggregateFunction, MapView, ListView

MAX_LONG_VALUE = sys.maxsize
MIN_LONG_VALUE = -MAX_LONG_VALUE - 1


class AvgAggFunction(AggregateFunction):

Expand Down

0 comments on commit 67ea2c6

Please sign in to comment.