Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-26607][python] There are multiple MAX_LONG_VALUE value errors in pyflink code #19089

Closed
wants to merge 6 commits into from
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 @@ -16,7 +16,6 @@
# limitations under the License.
################################################################################
import datetime
import sys
from abc import ABC, abstractmethod
from typing import TypeVar, Generic, List, Dict

Expand All @@ -33,11 +32,11 @@
MergingWindowAssigner
from pyflink.fn_execution.table.window_context import WindowContext, TriggerContext, K, W
from pyflink.fn_execution.table.window_process_function import GeneralWindowProcessFunction, \
InternalWindowProcessFunction, PanedWindowProcessFunction, MergingWindowProcessFunction
InternalWindowProcessFunction, PanedWindowProcessFunction, MergingWindowProcessFunction, \
MAX_LONG_VALUE
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