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


##########
clients/client-python/gravitino/dto/rel/column_dto.py:
##########
@@ -0,0 +1,163 @@
+# 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, field
+from typing import List, Optional, Union, cast
+
+from dataclasses_json import DataClassJsonMixin, config
+
+from gravitino.api.column import Column
+from gravitino.api.expressions.expression import Expression
+from gravitino.api.types.json_serdes.type_serdes import TypeSerdes
+from gravitino.api.types.type import Type
+from gravitino.api.types.types import Types
+from gravitino.dto.rel.expressions.literal_dto import LiteralDTO
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass
+class ColumnDTO(Column, DataClassJsonMixin):
+    """Represents a Model DTO (Data Transfer Object)."""
+
+    _name: str = field(metadata=config(field_name="name"))
+    """The name of the column."""
+
+    _data_type: Type = field(
+        metadata=config(
+            field_name="type",
+            encoder=TypeSerdes.serialize,
+            decoder=TypeSerdes.deserialize,
+        )
+    )
+    """The data type of the column."""
+
+    _comment: str = field(metadata=config(field_name="comment"))
+    """The comment associated with the column."""
+
+    # TODO: We shall specify encoder/decoder in the future PR. They're now 
dummy serdes.
+    _default_value: Optional[Union[Expression, List[Expression]]] = field(
+        default_factory=lambda: Column.DEFAULT_VALUE_NOT_SET,
+        metadata=config(
+            field_name="defaultValue",
+            encoder=lambda _: None,
+            decoder=lambda _: Column.DEFAULT_VALUE_NOT_SET,
+            exclude=lambda value: value is None
+            or value is Column.DEFAULT_VALUE_NOT_SET,
+        ),
+    )
+    """The default value of the column."""
+
+    _nullable: bool = field(default=True, 
metadata=config(field_name="nullable"))
+    """Whether the column value can be null."""
+
+    _auto_increment: bool = field(
+        default=False, metadata=config(field_name="autoIncrement")
+    )
+    """Whether the column is an auto-increment column."""
+
+    def name(self) -> str:
+        return self._name
+
+    def data_type(self) -> Type:
+        return self._data_type
+
+    def comment(self) -> str:
+        return self._comment
+
+    def nullable(self) -> bool:
+        return self._nullable
+
+    def auto_increment(self) -> bool:
+        return self._auto_increment
+
+    def default_value(self) -> Union[Expression, List[Expression]]:
+        return self._default_value
+
+    def validate(self) -> None:
+        Precondition.check_string_not_empty(
+            self._name, "Column name cannot be null or empty."
+        )
+        Precondition.check_argument(
+            self._data_type is not None, "Column data type cannot be null."
+        )
+        non_nullable_condition = (
+            not self._nullable
+            and isinstance(self._default_value, LiteralDTO)
+            and cast(LiteralDTO, self._default_value).data_type()
+            == Types.NullType.get()
+        )
+        Precondition.check_argument(
+            not non_nullable_condition,
+            f"Column cannot be non-nullable with a null default value: 
{self._name}.",
+        )
+
+    @classmethod
+    def builder(
+        cls,
+        name: str,
+        data_type: Type,
+        comment: str,
+        nullable: bool = True,
+        auto_increment: bool = False,
+        default_value: Optional[Expression] = None,
+    ) -> ColumnDTO:
+        Precondition.check_string_not_empty(

Review Comment:
   In java client: `ColumnDTO::Builder.build`, the Precondition for `name` is 
   
   ```
         Preconditions.checkNotNull(name, "Column name cannot be null");
   ```
   
   **It allow us to provide empty `name`,**
   
   and in `ColumnDTO.validate`, we have an assertion the make `name` not null 
or empty. 
   
   ```
       if (name() == null || name().isEmpty()) {
         throw new IllegalArgumentException("Column name cannot be null or 
empty.");
       }
   ```
   
   I think we should keep the behavior the same in python and java.
   
   



##########
clients/client-python/gravitino/dto/rel/column_dto.py:
##########
@@ -0,0 +1,163 @@
+# 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, field
+from typing import List, Optional, Union, cast
+
+from dataclasses_json import DataClassJsonMixin, config
+
+from gravitino.api.column import Column
+from gravitino.api.expressions.expression import Expression
+from gravitino.api.types.json_serdes.type_serdes import TypeSerdes
+from gravitino.api.types.type import Type
+from gravitino.api.types.types import Types
+from gravitino.dto.rel.expressions.literal_dto import LiteralDTO
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass
+class ColumnDTO(Column, DataClassJsonMixin):
+    """Represents a Model DTO (Data Transfer Object)."""
+
+    _name: str = field(metadata=config(field_name="name"))
+    """The name of the column."""
+
+    _data_type: Type = field(
+        metadata=config(
+            field_name="type",
+            encoder=TypeSerdes.serialize,
+            decoder=TypeSerdes.deserialize,
+        )
+    )
+    """The data type of the column."""
+
+    _comment: str = field(metadata=config(field_name="comment"))
+    """The comment associated with the column."""
+
+    # TODO: We shall specify encoder/decoder in the future PR. They're now 
dummy serdes.
+    _default_value: Optional[Union[Expression, List[Expression]]] = field(
+        default_factory=lambda: Column.DEFAULT_VALUE_NOT_SET,
+        metadata=config(
+            field_name="defaultValue",
+            encoder=lambda _: None,
+            decoder=lambda _: Column.DEFAULT_VALUE_NOT_SET,
+            exclude=lambda value: value is None
+            or value is Column.DEFAULT_VALUE_NOT_SET,
+        ),
+    )
+    """The default value of the column."""
+
+    _nullable: bool = field(default=True, 
metadata=config(field_name="nullable"))
+    """Whether the column value can be null."""
+
+    _auto_increment: bool = field(
+        default=False, metadata=config(field_name="autoIncrement")
+    )
+    """Whether the column is an auto-increment column."""
+
+    def name(self) -> str:
+        return self._name
+
+    def data_type(self) -> Type:
+        return self._data_type
+
+    def comment(self) -> str:
+        return self._comment
+
+    def nullable(self) -> bool:
+        return self._nullable
+
+    def auto_increment(self) -> bool:
+        return self._auto_increment
+
+    def default_value(self) -> Union[Expression, List[Expression]]:
+        return self._default_value
+
+    def validate(self) -> None:
+        Precondition.check_string_not_empty(
+            self._name, "Column name cannot be null or empty."
+        )
+        Precondition.check_argument(
+            self._data_type is not None, "Column data type cannot be null."
+        )
+        non_nullable_condition = (
+            not self._nullable
+            and isinstance(self._default_value, LiteralDTO)
+            and cast(LiteralDTO, self._default_value).data_type()
+            == Types.NullType.get()
+        )
+        Precondition.check_argument(
+            not non_nullable_condition,
+            f"Column cannot be non-nullable with a null default value: 
{self._name}.",
+        )
+
+    @classmethod
+    def builder(

Review Comment:
   There's a small flaw on this builder function, actually, builder should be 
used with some additional methods.
   
   e.g. for `CatalogDTO` in java:
   
   ```java
             ColumnDTO.builder()
                 .withName("rider")
                 .withDataType(Types.StringType.get())
                 .withComment("")
                 .build(),
   ```
   
   But in current implementation of `CatalogDTO`, we simply has a `builder` 
method.
   
   Maybe we can refactor this in future PR, and keep the implementation in 
`CatalogDTO` and `ColumnDTO` the same for now.



##########
clients/client-python/tests/unittests/dto/rel/test_column_dto.py:
##########
@@ -0,0 +1,186 @@
+# 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 json
+import unittest
+
+from gravitino.api.column import Column
+from gravitino.api.types.json_serdes import TypeSerdes
+from gravitino.api.types.json_serdes._helper.serdes_utils import SerdesUtils
+from gravitino.api.types.types import Types
+from gravitino.dto.rel.column_dto import ColumnDTO
+from gravitino.dto.rel.expressions.literal_dto import LiteralDTO
+from gravitino.exceptions.base import IllegalArgumentException
+
+
+class TestColumnDTO(unittest.TestCase):
+    @classmethod
+    def setUpClass(cls):
+        cls._supported_types = [
+            *SerdesUtils.TYPES.values(),
+            Types.DecimalType.of(10, 2),

Review Comment:
   Why supported types is not just `SerdesUtils.TYPES` ?



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