unknowntpo commented on code in PR #5964:
URL: https://github.com/apache/gravitino/pull/5964#discussion_r1905020048


##########
clients/client-python/gravitino/api/expressions/partitions/partitions.py:
##########
@@ -0,0 +1,231 @@
+# 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 typing import List, Dict, Any, Optional
+
+from gravitino.api.expressions.literals.literal import Literal
+from gravitino.api.expressions.partitions.identity_partition import 
IdentityPartition
+from gravitino.api.expressions.partitions.list_partition import ListPartition
+from gravitino.api.expressions.partitions.partition import Partition
+from gravitino.api.expressions.partitions.range_partition import RangePartition
+
+
+class Partitions:
+    """The helper class for partition expressions."""
+
+    EMPTY_PARTITIONS: List[Partition] = []
+    """
+    An empty array of partitions
+    """
+
+    @staticmethod
+    def range(
+        name: str,
+        upper: Literal[Any],
+        lower: Literal[Any],
+        properties: Optional[Dict[str, str]],
+    ) -> RangePartition:
+        """
+        Creates a range partition.
+
+        Args:
+            name: The name of the partition.
+            upper: The upper bound of the partition.
+            lower: The lower bound of the partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return RangePartitionImpl(name, upper, lower, properties)
+
+    @staticmethod
+    def list(
+        name: str,
+        lists: List[List[Literal[Any]]],
+        properties: Optional[Dict[str, str]],
+    ) -> ListPartition:
+        """
+        Creates a list partition.
+
+        Args:
+            name: The name of the partition.
+            lists: The values of the list partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return ListPartitionImpl(name, lists, properties or {})
+
+    @staticmethod
+    def identity(
+        name: Optional[str],
+        field_names: List[List[str]],
+        values: List[Literal[Any]],
+        properties: Optional[Dict[str, str]] = None,
+    ) -> IdentityPartition:
+        """
+        Creates an identity partition.
+
+        The `values` must correspond to the `field_names`.
+
+        Args:
+            name: The name of the partition.
+            field_names: The field names of the identity partition.
+            values: The value of the identity partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return IdentityPartitionImpl(name, field_names, values, properties or 
{})
+
+
+class RangePartitionImpl(RangePartition):
+    """
+    Represents a result of range partitioning.
+    """
+
+    def __init__(
+        self,
+        name: str,
+        upper: Literal[Any],
+        lower: Literal[Any],
+        properties: Optional[Dict[str, str]],
+    ):
+        self._name = name
+        self._upper = upper
+        self._lower = lower
+        self._properties = properties
+
+    def upper(self) -> Literal[Any]:
+        """Returns the upper bound of the partition."""
+        return self._upper
+
+    def lower(self) -> Literal[Any]:
+        """Returns the lower bound of the partition."""
+        return self._lower
+
+    def name(self) -> str:
+        return self._name
+
+    def properties(self) -> Dict[str, str]:
+        return self._properties
+
+    def __eq__(self, other: Any) -> bool:

Review Comment:
   We can not use `is` to compare objects, because it will be `True` only if 
they refer to the same object in memory.
   
   To verify it, use this simple script:
   
   ```
   class Hello: 
       def __init__(self, a: int, b: int) -> None:
           self.a = a
           self.b = b
   
   def main():
       objA = Hello(3, 2)
       objB = Hello(3, 2)
   
       print(objA is objB) # will be False
   
   
   if __name__ == "__main__":
       main()
   ```
   
   The correct way is to check if they belong to the same class first, and 
check equality of each fields.
   Just like what we did at 
[`catalog_change.py`](https://github.com/apache/gravitino/blob/main/clients/client-python/gravitino/api/catalog_change.py#L90-L102):
   
   ```
           def __eq__(self, other) -> bool:
               """Compares this SetProperty instance with another object for 
equality.
               Two instances are considered equal if they have the same 
property and value for the catalog.
   
               Args:
                   other: The object to compare with this instance.
   
               Returns:
                   true if the given object represents the same property 
setting; false otherwise.
               """
               if not isinstance(other, CatalogChange.SetProperty):
                   return False
               return self.property() == other.property() and self.value() == 
other.value()
   ```



##########
clients/client-python/gravitino/api/expressions/partitions/partitions.py:
##########
@@ -0,0 +1,231 @@
+# 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 typing import List, Dict, Any, Optional
+
+from gravitino.api.expressions.literals.literal import Literal
+from gravitino.api.expressions.partitions.identity_partition import 
IdentityPartition
+from gravitino.api.expressions.partitions.list_partition import ListPartition
+from gravitino.api.expressions.partitions.partition import Partition
+from gravitino.api.expressions.partitions.range_partition import RangePartition
+
+
+class Partitions:
+    """The helper class for partition expressions."""
+
+    EMPTY_PARTITIONS: List[Partition] = []
+    """
+    An empty array of partitions
+    """
+
+    @staticmethod
+    def range(
+        name: str,
+        upper: Literal[Any],
+        lower: Literal[Any],
+        properties: Optional[Dict[str, str]],
+    ) -> RangePartition:
+        """
+        Creates a range partition.
+
+        Args:
+            name: The name of the partition.
+            upper: The upper bound of the partition.
+            lower: The lower bound of the partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return RangePartitionImpl(name, upper, lower, properties)
+
+    @staticmethod
+    def list(
+        name: str,
+        lists: List[List[Literal[Any]]],
+        properties: Optional[Dict[str, str]],
+    ) -> ListPartition:
+        """
+        Creates a list partition.
+
+        Args:
+            name: The name of the partition.
+            lists: The values of the list partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return ListPartitionImpl(name, lists, properties or {})
+
+    @staticmethod
+    def identity(
+        name: Optional[str],
+        field_names: List[List[str]],
+        values: List[Literal[Any]],
+        properties: Optional[Dict[str, str]] = None,
+    ) -> IdentityPartition:
+        """
+        Creates an identity partition.
+
+        The `values` must correspond to the `field_names`.
+
+        Args:
+            name: The name of the partition.
+            field_names: The field names of the identity partition.
+            values: The value of the identity partition.
+            properties: The properties of the partition.
+
+        Returns:
+            The created partition.
+        """
+        return IdentityPartitionImpl(name, field_names, values, properties or 
{})
+
+
+class RangePartitionImpl(RangePartition):
+    """
+    Represents a result of range partitioning.
+    """
+
+    def __init__(
+        self,
+        name: str,
+        upper: Literal[Any],
+        lower: Literal[Any],
+        properties: Optional[Dict[str, str]],
+    ):
+        self._name = name
+        self._upper = upper
+        self._lower = lower
+        self._properties = properties
+
+    def upper(self) -> Literal[Any]:
+        """Returns the upper bound of the partition."""
+        return self._upper
+
+    def lower(self) -> Literal[Any]:
+        """Returns the lower bound of the partition."""
+        return self._lower
+
+    def name(self) -> str:
+        return self._name
+
+    def properties(self) -> Dict[str, str]:
+        return self._properties
+
+    def __eq__(self, other: Any) -> bool:

Review Comment:
   @xunliu We can not use `is` to compare objects, because it will be `True` 
only if they refer to the same object in memory.
   
   To verify it, use this simple script:
   
   ```
   class Hello: 
       def __init__(self, a: int, b: int) -> None:
           self.a = a
           self.b = b
   
   def main():
       objA = Hello(3, 2)
       objB = Hello(3, 2)
   
       print(objA is objB) # will be False
   
   
   if __name__ == "__main__":
       main()
   ```
   
   The correct way is to check if they belong to the same class first, and 
check equality of each fields.
   Just like what we did at 
[`catalog_change.py`](https://github.com/apache/gravitino/blob/main/clients/client-python/gravitino/api/catalog_change.py#L90-L102):
   
   ```
           def __eq__(self, other) -> bool:
               """Compares this SetProperty instance with another object for 
equality.
               Two instances are considered equal if they have the same 
property and value for the catalog.
   
               Args:
                   other: The object to compare with this instance.
   
               Returns:
                   true if the given object represents the same property 
setting; false otherwise.
               """
               if not isinstance(other, CatalogChange.SetProperty):
                   return False
               return self.property() == other.property() and self.value() == 
other.value()
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to