You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "Abyss-lord (via GitHub)" <gi...@apache.org> on 2026/06/04 03:23:03 UTC

[PR] [#8612] feat(client): Add PartitionRange [gravitino]

Abyss-lord opened a new pull request, #11422:
URL: https://github.com/apache/gravitino/pull/11422

   
   ### What changes were proposed in this pull request?
   
   Add `PartitionRange` to python client.
   
   ### Why are the changes needed?
   
   Fix: #8612 
   
   ### Does this PR introduce _any_ user-facing change?
   
   no
   
   ### How was this patch tested?
   
   unit test.
   


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370440760


##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   fix



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def between(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   fix



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#issuecomment-4753627743

   Can you fix these comments by Copilot?


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370439504


##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR

Review Comment:
   fix, not to check null value on comparator.



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3363036329


##########
clients/client-python/gravitino/api/rel/expressions/named_reference.py:
##########
@@ -84,3 +84,30 @@ def __hash__(self) -> int:
     def __str__(self) -> str:
         """Returns the string representation of the field reference."""
         return ".".join(self._field_names)
+
+
+class MetadataField(NamedReference):
+    """A NamedReference that references a metadata field."""
+
+    _field_names: list[str]
+
+    def __init__(self, field_names: list[str]) -> None:
+        super().__init__()
+        self._field_names = field_names
+
+    def field_name(self) -> list[str]:
+        return list(self._field_names)

Review Comment:
   I think we can directly return `self._field_names` as it is already a list of strings.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   In Java client, `comparator` is not allowed to be null. I would recommend to change the signature listed as follows. 
   
   ```python
       @classmethod
       def up_to(
           cls,
           upper_partition_name: str,
           upper_bound_type: BoundType,
           comparator: SortOrder = DEFAULT_COMPARATOR,
       ) -> "PartitionRange":
   ```



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR

Review Comment:
   The behavior is not similar to the Java client listed as follows. Or we may consider not to check null value on `comparator` as the signature is explicitly claimed that the argument must not be null.
   
   https://github.com/apache/gravitino/blob/9419878b5d2bccc7bb9f1f3a3220b11807d3be8a/api/src/main/java/org/apache/gravitino/stats/PartitionRange.java#L70-L72



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   Similar comment on `up_to` method. 



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:

Review Comment:
   Why do we define a frozen data class here? I do not see equivalent definition in Java client.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def between(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   Similar comment on method `up_to`.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None

Review Comment:
   I think we should use the modern type hints: `str | None`. 



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def between(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which has both lower and upper partition names with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            upper_partition_name (str):  the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with both lower and upper partition names
+            and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    def lower_partition_name(self) -> Optional[str]:
+        """
+        Returns the lower partition name if it exists.
+
+        Returns:
+            Optional[str]: an Optional containing the lower partition name if it exists, otherwise None.
+        """
+        return self._lower_partition_name
+
+    def upper_partition_name(self) -> Optional[str]:
+        """
+        Returns the upper partition name if it exists.
+
+        Returns:
+            Optional[str]: an Optional containing the upper partition name if it exists, otherwise None
+        """
+        return self._upper_partition_name
+
+    def lower_bound_type(self) -> Optional[BoundType]:
+        """
+        Returns the type of the lower bound if it exists.
+
+        Returns:
+            Optional[BoundType]: an Optional containing the lower bound type if it exists, otherwise None.
+        """
+        return self._lower_bound_type
+
+    def upper_bound_type(self) -> Optional[BoundType]:
+        """
+        Returns the type of the upper bound if it exists.
+
+        Returns:
+            Optional[BoundType]: an Optional containing the upper bound type if it exists, otherwise None.
+        """
+        return self._upper_bound_type
+
+    def comparator(self) -> SortOrder:
+        """
+        Returns the comparator for this partition range.
+
+        Returns:
+            SortOrder: the comparator for this partition range.
+        """
+        return self._comparator
+
+
+# A PartitionRange that includes all partitions.
+ALL_PARTITIONS = PartitionRange(_comparator=PartitionRange.DEFAULT_COMPARATOR)

Review Comment:
   We don't need to assign value to `_comparator` as it has default value set in the class.



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370443253


##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def between(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which has both lower and upper partition names with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            upper_partition_name (str):  the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (Optional[SortOrder], optional): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with both lower and upper partition names
+            and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+
+        if comparator is None:
+            comparator = cls.DEFAULT_COMPARATOR
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    def lower_partition_name(self) -> Optional[str]:
+        """
+        Returns the lower partition name if it exists.
+
+        Returns:
+            Optional[str]: an Optional containing the lower partition name if it exists, otherwise None.
+        """
+        return self._lower_partition_name
+
+    def upper_partition_name(self) -> Optional[str]:
+        """
+        Returns the upper partition name if it exists.
+
+        Returns:
+            Optional[str]: an Optional containing the upper partition name if it exists, otherwise None
+        """
+        return self._upper_partition_name
+
+    def lower_bound_type(self) -> Optional[BoundType]:
+        """
+        Returns the type of the lower bound if it exists.
+
+        Returns:
+            Optional[BoundType]: an Optional containing the lower bound type if it exists, otherwise None.
+        """
+        return self._lower_bound_type
+
+    def upper_bound_type(self) -> Optional[BoundType]:
+        """
+        Returns the type of the upper bound if it exists.
+
+        Returns:
+            Optional[BoundType]: an Optional containing the upper bound type if it exists, otherwise None.
+        """
+        return self._upper_bound_type
+
+    def comparator(self) -> SortOrder:
+        """
+        Returns the comparator for this partition range.
+
+        Returns:
+            SortOrder: the comparator for this partition range.
+        """
+        return self._comparator
+
+
+# A PartitionRange that includes all partitions.
+ALL_PARTITIONS = PartitionRange(_comparator=PartitionRange.DEFAULT_COMPARATOR)

Review Comment:
   fix



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#issuecomment-4618669434

   Hi @tsungchih @mchades @sunyuhan1998 ,could you please review this PR when you have time? I’d really appreciate your feedback.
   


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#issuecomment-4645062495

   Hi @tsungchih , I've completed the code updates and would appreciate your review of the PR when you have a moment.


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370426456


##########
clients/client-python/gravitino/api/rel/expressions/named_reference.py:
##########
@@ -84,3 +84,30 @@ def __hash__(self) -> int:
     def __str__(self) -> str:
         """Returns the string representation of the field reference."""
         return ".".join(self._field_names)
+
+
+class MetadataField(NamedReference):
+    """A NamedReference that references a metadata field."""
+
+    _field_names: list[str]
+
+    def __init__(self, field_names: list[str]) -> None:
+        super().__init__()
+        self._field_names = field_names
+
+    def field_name(self) -> list[str]:
+        return list(self._field_names)

Review Comment:
   Thanks for the suggestion. I intentionally return a new list here to protect the internal `field_names` from being modified by callers.
   
   Although `self._field_names` is already a list of strings, returning it directly would expose the internal mutable list. For example, a caller could do:
   
   ```python
   field_names = ref.field_name()
   field_names.append("unexpected_field")
   ```



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370441607


##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:

Review Comment:
   fix



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#issuecomment-4849884033

   > Can you fix these comments by Copilot?
   
   sure


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3370440078


##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar, Optional
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass(frozen=True)
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: Optional[str] = None
+    _lower_bound_type: Optional[BoundType] = None
+    _upper_partition_name: Optional[str] = None
+    _upper_bound_type: Optional[BoundType] = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: Optional[SortOrder] = None,
+    ) -> "PartitionRange":

Review Comment:
   fix



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#issuecomment-4619061396

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|66.77%|:green_circle:|
   |:-|:-|:-:|
   |Files changed|No Java source files changed|-|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.82%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.04%|:red_circle:|
   |catalog-fileset|80.33%|:green_circle:|
   |catalog-glue|66.67%|:green_circle:|
   |catalog-hive|79.33%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|45.31%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|44.89%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.66%|:green_circle:|
   |catalog-lakehouse-paimon|79.29%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|77.91%|:green_circle:|
   |common|49.99%|:green_circle:|
   |core|82.49%|:green_circle:|
   |filesystem-hadoop3|76.97%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|41.2%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.39%|:red_circle:|
   |hive-metastore-common|53.26%|:green_circle:|
   |iceberg-common|56.54%|:green_circle:|
   |iceberg-rest-server|72.76%|:green_circle:|
   |idp-basic|85.99%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.83%|:red_circle:|
   |lance-rest-server|60.27%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.73%|:green_circle:|
   |server-common|73.13%|:green_circle:|
   |spark|32.79%|:red_circle:|
   |spark-common|37.99%|:red_circle:|
   |trino-connector|39.44%|:red_circle:|
   


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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8612] feat(client): Add PartitionRange [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11422:
URL: https://github.com/apache/gravitino/pull/11422#discussion_r3392484514


##########
clients/client-python/gravitino/client/gravitino_metalake.py:
##########
@@ -1,3 +1,4 @@
+# pylint: disable=too-many-lines
 # Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   This file now has a duplicate `# pylint: disable=too-many-lines` (one before the ASF header and another later before imports). Keeping both is redundant; since the directive already exists later in the file, drop the newly added one at the top.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,228 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass()
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: str | None = None
+    _lower_bound_type: BoundType | None = None
+    _upper_partition_name: str | None = None
+    _upper_bound_type: BoundType | None = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+

Review Comment:
   `up_to()` allows callers to pass `comparator=None`, which would create a `PartitionRange` whose `comparator()` violates its `SortOrder` contract and can later fail when used for sorting/serialization. The Java API also rejects null comparators; add a precondition here as well.



##########
clients/client-python/tests/unittests/api/stats/test_partition_range.py:
##########
@@ -0,0 +1,114 @@
+# 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 unittest
+
+from gravitino.api.stats.partition_range import ALL_PARTITIONS, PartitionRange
+from gravitino.exceptions.base import IllegalArgumentException
+
+
+class TestPartitionRange(unittest.TestCase):
+    def test_partition_range(self) -> None:
+        range1: PartitionRange = PartitionRange.down_to(
+            "partition1", PartitionRange.BoundType.OPEN
+        )
+        self.assertIsNotNone(range1.lower_partition_name())
+        self.assertEqual("partition1", range1.lower_partition_name())
+        self.assertEqual(PartitionRange.BoundType.OPEN, range1.lower_bound_type())
+        self.assertIsNotNone(range1.lower_bound_type())
+        self.assertIsNone(range1.upper_partition_name())
+        self.assertIsNone(range1.upper_bound_type())
+        self.assertIsNotNone(range1.comparator())
+
+        range2: PartitionRange = PartitionRange.up_to(
+            "partition3", PartitionRange.BoundType.CLOSED
+        )
+        self.assertIsNotNone(range2.upper_partition_name())
+        self.assertEqual("partition3", range2.upper_partition_name())
+        self.assertEqual(PartitionRange.BoundType.CLOSED, range2.upper_bound_type())
+        self.assertIsNotNone(range2.upper_bound_type())
+        self.assertIsNone(range2.lower_partition_name())
+        self.assertIsNone(range2.lower_bound_type())
+        self.assertIsNotNone(range2.comparator())
+
+        range3: PartitionRange = PartitionRange.between(
+            "partition1",
+            PartitionRange.BoundType.OPEN,
+            "partition3",
+            PartitionRange.BoundType.CLOSED,
+        )
+        self.assertIsNotNone(range3.lower_partition_name())
+        self.assertEqual("partition1", range3.lower_partition_name())
+        self.assertIsNotNone(range3.lower_bound_type())
+        self.assertEqual(PartitionRange.BoundType.OPEN, range3.lower_bound_type())
+        self.assertIsNotNone(range3.upper_partition_name())
+        self.assertEqual("partition3", range3.upper_partition_name())
+        self.assertIsNotNone(range3.upper_bound_type())
+        self.assertEqual(PartitionRange.BoundType.CLOSED, range3.upper_bound_type())
+        self.assertIsNotNone(range3.comparator())
+
+        range4: PartitionRange = PartitionRange.between(
+            "partition1",
+            PartitionRange.BoundType.CLOSED,
+            "partition3",
+            PartitionRange.BoundType.OPEN,
+        )
+        self.assertIsNotNone(range4.lower_partition_name())
+        self.assertEqual("partition1", range4.lower_partition_name())
+        self.assertIsNotNone(range4.lower_bound_type())
+        self.assertEqual(PartitionRange.BoundType.CLOSED, range4.lower_bound_type())
+        self.assertIsNotNone(range4.upper_partition_name())
+        self.assertEqual("partition3", range4.upper_partition_name())
+        self.assertIsNotNone(range4.upper_bound_type())
+        self.assertEqual(PartitionRange.BoundType.OPEN, range4.upper_bound_type())
+        self.assertIsNotNone(range4.comparator())
+
+    def test_create_down_range_with_null_arguments(self) -> None:
+        with self.assertRaises(IllegalArgumentException):
+            PartitionRange.down_to(None, PartitionRange.BoundType.CLOSED)  # type: ignore
+
+        with self.assertRaises(IllegalArgumentException):
+            PartitionRange.down_to("partition1", None)  # type: ignore
+
+    def test_create_up_range_with_null_arguments(self) -> None:
+        with self.assertRaises(IllegalArgumentException):
+            PartitionRange.up_to(None, PartitionRange.BoundType.CLOSED)  # type: ignore
+
+        with self.assertRaises(IllegalArgumentException):
+            PartitionRange.up_to("partition1", None)  # type: ignore
+
+    def test_up_to_with_null_comparator(self) -> None:
+        down_closed_range = PartitionRange.down_to(
+            "partition1", PartitionRange.BoundType.CLOSED
+        )
+
+        self.assertIsNotNone(down_closed_range.comparator())
+
+        up_open_range = PartitionRange.up_to(
+            "partition2", PartitionRange.BoundType.OPEN
+        )
+
+        self.assertIsNotNone(up_open_range.comparator())
+

Review Comment:
   `test_up_to_with_null_comparator` doesn't actually pass a null comparator, so it won't catch the (currently allowed) `comparator=None` bug. Update the test to assert that passing `None` for the comparator raises `IllegalArgumentException` (and ideally cover `up_to`, `down_to`, and `between`).



##########
clients/client-python/gravitino/api/rel/expressions/named_reference.py:
##########
@@ -84,3 +84,30 @@ def __hash__(self) -> int:
     def __str__(self) -> str:
         """Returns the string representation of the field reference."""
         return ".".join(self._field_names)
+
+
+class MetadataField(NamedReference):
+    """A NamedReference that references a metadata field."""
+
+    _field_names: list[str]
+
+    def __init__(self, field_names: list[str]) -> None:
+        super().__init__()
+        self._field_names = field_names
+

Review Comment:
   `MetadataField` stores the caller-provided `field_names` list directly. Because `__hash__`/`__str__` depend on `_field_names`, mutating the original list after construction can change the object's hash/string representation, which is unsafe (e.g., if used as a dict key). Copy the list in the constructor to make the instance stable.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,228 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass()
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: str | None = None
+    _lower_bound_type: BoundType | None = None
+    _upper_partition_name: str | None = None
+    _upper_bound_type: BoundType | None = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+

Review Comment:
   `down_to()` allows `comparator=None`, which would produce an invalid `PartitionRange` (and `comparator()` would return None despite its type signature). Add a precondition check to reject null comparators, consistent with the server-side/Java behavior.



##########
clients/client-python/gravitino/api/stats/partition_range.py:
##########
@@ -0,0 +1,228 @@
+# 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.
+
+
+from __future__ import annotations
+
+from dataclasses import dataclass
+from enum import Enum
+from typing import ClassVar
+
+from gravitino.api.rel.expressions.named_reference import (
+    PARTITION_NAME_FIELD,
+)
+from gravitino.api.rel.expressions.sorts.sort_direction import SortDirection
+from gravitino.api.rel.expressions.sorts.sort_orders import SortOrder, SortOrders
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass()
+class PartitionRange:
+    DEFAULT_COMPARATOR: ClassVar[SortOrder] = SortOrders.of(
+        PARTITION_NAME_FIELD, SortDirection.ASCENDING
+    )
+    _lower_partition_name: str | None = None
+    _lower_bound_type: BoundType | None = None
+    _upper_partition_name: str | None = None
+    _upper_bound_type: BoundType | None = None
+    _comparator: SortOrder = DEFAULT_COMPARATOR
+
+    class BoundType(Enum):
+        """Enum representing the type of bounds for a partition range."""
+
+        OPEN = "OPEN"  # exclusive
+        CLOSED = "CLOSED"  # inclusive
+
+    @classmethod
+    def up_to(
+        cls,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has upper bound partition name with a specific comparator type.
+
+        Args:
+            upper_partition_name (str): the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the upper partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+
+        return PartitionRange(
+            _upper_partition_name=upper_partition_name,
+            _upper_bound_type=upper_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def down_to(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which only has lower bound partition name with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with the lower partition name and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+
+        return PartitionRange(
+            _lower_partition_name=lower_partition_name,
+            _lower_bound_type=lower_bound_type,
+            _comparator=comparator,
+        )
+
+    @classmethod
+    def between(
+        cls,
+        lower_partition_name: str,
+        lower_bound_type: BoundType,
+        upper_partition_name: str,
+        upper_bound_type: BoundType,
+        comparator: SortOrder = DEFAULT_COMPARATOR,
+    ) -> "PartitionRange":
+        """
+        Creates a PartitionRange which has both lower and upper partition names with a specific comparator type.
+
+        Args:
+            lower_partition_name (str): the lower partition name.
+            lower_bound_type (BoundType): the type of the lower bound (open or closed).
+            upper_partition_name (str):  the upper partition name.
+            upper_bound_type (BoundType): the type of the upper bound (open or closed).
+            comparator (SortOrder): the comparator to use for this range.
+
+        Returns:
+            PartitionRange: a PartitionRange with both lower and upper partition names
+            and the specified comparator type.
+        """
+        Precondition.check_argument(
+            lower_partition_name is not None,
+            "Lower partition name cannot be null",
+        )
+        Precondition.check_argument(
+            lower_bound_type is not None,
+            "Lower bound type cannot be null",
+        )
+        Precondition.check_argument(
+            lower_partition_name.strip() != "",
+            "Lower partition name cannot be empty",
+        )
+
+        Precondition.check_argument(
+            upper_partition_name is not None,
+            "Upper partition name cannot be null",
+        )
+        Precondition.check_argument(
+            upper_bound_type is not None,
+            "Upper bound type cannot be null",
+        )
+        Precondition.check_argument(
+            upper_partition_name.strip() != "",
+            "Upper partition name cannot be empty",
+        )
+

Review Comment:
   `between()` allows `comparator=None`, which can create a `PartitionRange` that later fails when the comparator is used (and contradicts the `SortOrder` return type). Add a precondition to reject null comparators, matching the Java API's validation.



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

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org