You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "tsungchih (via GitHub)" <gi...@apache.org> on 2025/06/08 15:37:48 UTC
[PR] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
tsungchih opened a new pull request, #7357:
URL: https://github.com/apache/gravitino/pull/7357
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
This is the second part (totally 4 planned) of implementation to the following classes from Java to support Column and its default value, including:
- ColumnDTO
- LiteralDTO
- FunctionArg
- PartitionUtils
We implemented the above four classes in one single PR since they have tight dependency to each other.
**NOTE** that we haven't implemented the serdes for `ColumnDTO.default_value` which will be included in the future PR. Its serdes now are dummy ones to always serialize `ColumnDTO.default_value` to `None` and deserialize `ColiumnDTO.default_value` as `Column.DEFAULT_VALUE_NOT_SET`.
### Why are the changes needed?
We need to support Column and its default value in python client.
#5202
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Unit tests
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #7357:
URL: https://github.com/apache/gravitino/pull/7357
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2140342111
##########
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:
`SerdesUtils.TYPES` embraces only primitive and null `Type`s instead of all of the `Type`s. I set up this supported types to test each built-in 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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#issuecomment-2957063328
@mchades can you please also take a look?
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#issuecomment-2996245780
@jerryshao LGTM.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#issuecomment-2954634382
@tsungchih Okay, I'll take a look.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2140354585
##########
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:
I think I could give it a try. Do you prefer the refactor in this PR for `ColumnDTO`?
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2144420585
##########
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:
I prefer doing this in next PR.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2140367846
##########
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:
I'll align the behavior in Python and Java when proceeding the refactor of builder method.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2160024962
##########
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:
I think this should be aligned in this PR, because I don't want the behavior be different between Python and Java.
##########
clients/client-python/gravitino/dto/rel/partition_utils.py:
##########
@@ -0,0 +1,57 @@
+# 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 itertools import filterfalse
+from typing import TYPE_CHECKING, List
+
+from gravitino.utils.precondition import Precondition
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class PartitionUtils:
+ """Validates the existence of the partition field in the table."""
+
+ @staticmethod
+ def validate_field_existence(
+ columns: List["ColumnDTO"], field_name: List[str]
+ ) -> None:
+ """Validates the existence of the partition field in the table.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+ field_name (List[str]): The name of the field to validate.
+
+ Raises:
+ IllegalArgumentException: If the field does not exist in the table, this exception is thrown.
+ """
+ Precondition.check_argument(
Review Comment:
ok
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2160042515
##########
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:
The Precondition for `name` in the current builder implementation has been aligned with the one in Java client. Please take review on this when you're available. Thanks!
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2147408842
##########
clients/client-python/gravitino/dto/rel/expressions/function_arg.py:
##########
@@ -0,0 +1,73 @@
+# 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 abc import abstractmethod
+from enum import Enum, unique
+from typing import TYPE_CHECKING, ClassVar, List
+
+from gravitino.api.expressions.expression import Expression
+from gravitino.dto.rel.partition_utils import PartitionUtils
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class FunctionArg(Expression):
+ """An argument of a function."""
+
+ EMPTY_ARGS: ClassVar[List[FunctionArg]] = []
+
+ @abstractmethod
+ def arg_type(self) -> ArgType:
+ """Arguments type of the function.
+
+ Returns:
+ ArgType: The type of this argument.
+ """
+ pass
+
+ def validate(self, columns: List[ColumnDTO]) -> None:
+ """Validates the function argument.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+
+ Raises:
+ IllegalArgumentException: If the function argument is invalid.
+ """
+ validate_field_existence = PartitionUtils.validate_field_existence
+ for ref in self.references():
+ validate_field_existence(columns, ref.field_name())
Review Comment:
Two intentions here not to directly call to `PartitionUtils.validate_field_existence`, one is to reduce the length of the line (it's more readable for me) and on the other hand is to speed up the for loop by reducing overhead of function lookups in the class.
Here's the test results on my laptop using `timeit` to show the overhead of function lookups in the class.
```shell
Profiling calling classmethod directly for running 100000 times for 5 iterations...
Min: 0.018136 seconds, Max: 0.018823, Avg: 0.018469
Profiling calling classmethod via variable for running 100000 times for 5 iterations...
Min: 0.011842 seconds, Max: 0.012436, Avg: 0.012046
```
The setup statement is listed as follows.
```python
import random
class TestClass:
@classmethod
def get_random(cls) -> float:
return random.random()
get_random = TestClass.get_random
```
And the statement for each test case is `TestClass.get_random()` and `get_random()` respectively.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#issuecomment-2954142805
@xunliu @unknowntpo @jerryshao Could you please help with reviewing this PR when you are available? I would greatly appreciate any feedback from you. Thanks.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2144420585
##########
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:
I prefer doing this in a specific **Improvement** PR.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2160025031
##########
clients/client-python/gravitino/dto/rel/expressions/function_arg.py:
##########
@@ -0,0 +1,73 @@
+# 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 abc import abstractmethod
+from enum import Enum, unique
+from typing import TYPE_CHECKING, ClassVar, List
+
+from gravitino.api.expressions.expression import Expression
+from gravitino.dto.rel.partition_utils import PartitionUtils
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class FunctionArg(Expression):
+ """An argument of a function."""
+
+ EMPTY_ARGS: ClassVar[List[FunctionArg]] = []
+
+ @abstractmethod
+ def arg_type(self) -> ArgType:
+ """Arguments type of the function.
+
+ Returns:
+ ArgType: The type of this argument.
+ """
+ pass
+
+ def validate(self, columns: List[ColumnDTO]) -> None:
+ """Validates the function argument.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+
+ Raises:
+ IllegalArgumentException: If the function argument is invalid.
+ """
+ validate_field_existence = PartitionUtils.validate_field_existence
+ for ref in self.references():
+ validate_field_existence(columns, ref.field_name())
Review Comment:
Nice!
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2144436841
##########
clients/client-python/gravitino/dto/rel/expressions/function_arg.py:
##########
@@ -0,0 +1,73 @@
+# 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 abc import abstractmethod
+from enum import Enum, unique
+from typing import TYPE_CHECKING, ClassVar, List
+
+from gravitino.api.expressions.expression import Expression
+from gravitino.dto.rel.partition_utils import PartitionUtils
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class FunctionArg(Expression):
+ """An argument of a function."""
+
+ EMPTY_ARGS: ClassVar[List[FunctionArg]] = []
+
+ @abstractmethod
+ def arg_type(self) -> ArgType:
+ """Arguments type of the function.
+
+ Returns:
+ ArgType: The type of this argument.
+ """
+ pass
+
+ def validate(self, columns: List[ColumnDTO]) -> None:
+ """Validates the function argument.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+
+ Raises:
+ IllegalArgumentException: If the function argument is invalid.
+ """
+ validate_field_existence = PartitionUtils.validate_field_existence
+ for ref in self.references():
+ validate_field_existence(columns, ref.field_name())
Review Comment:
Why not just calling `PartitionUtils.validate_field_existence` ?
```
PartitionUtils.validate_field_existence(columns, ref.field_name())
```
##########
clients/client-python/gravitino/dto/rel/partition_utils.py:
##########
@@ -0,0 +1,57 @@
+# 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 itertools import filterfalse
+from typing import TYPE_CHECKING, List
+
+from gravitino.utils.precondition import Precondition
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class PartitionUtils:
+ """Validates the existence of the partition field in the table."""
+
+ @staticmethod
+ def validate_field_existence(
+ columns: List["ColumnDTO"], field_name: List[str]
+ ) -> None:
+ """Validates the existence of the partition field in the table.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+ field_name (List[str]): The name of the field to validate.
+
+ Raises:
+ IllegalArgumentException: If the field does not exist in the table, this exception is thrown.
+ """
+ Precondition.check_argument(
Review Comment:
I think it will be great to keep implementation of `PartitionUtils.validate_field_existence` the same as `Java`.
```
public static void validateFieldExistence(ColumnDTO[] columns, String[] fieldName)
throws IllegalArgumentException {
Preconditions.checkArgument(ArrayUtils.isNotEmpty(columns), "columns cannot be null or empty");
List<ColumnDTO> partitionColumn =
Arrays.stream(columns)
// (TODO) Need to consider the case sensitivity issues.
// To be optimized.
.filter(c -> c.name().equalsIgnoreCase(fieldName[0]))
.collect(Collectors.toList());
Preconditions.checkArgument(
partitionColumn.size() == 1, "Field '%s' not found in table", fieldName[0]);
// TODO: should validate nested fieldName after column type support namedStruct
}
```
, for example:
```
@staticmethod
def validate_field_existence(
columns: List["ColumnDTO"], field_name: List[str]
) -> None:
"""Validates the existence of the partition field in the table.
Args:
columns (List[ColumnDTO]): The columns of the table.
field_name (List[str]): The name of the field to validate.
Raises:
IllegalArgumentException: If the field does not exist in the table, this exception is thrown.
"""
Precondition.check_argument(
columns is not None and len(columns) > 0,
"columns cannot be null or empty"
)
# Filter columns that match the first field name (case-insensitive)
# TODO: Need to consider the case sensitivity issues. To be optimized.
partition_column = [
c for c in columns
if c.name().lower() == field_name[0].lower()
]
Precondition.check_argument(
len(partition_column) == 1,
f"Field '{field_name[0]}' not found in table"
)
# TODO: should validate nested fieldName after column type support namedStruct
```
which is more intuitive in my opinion.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2159823438
##########
clients/client-python/gravitino/dto/rel/partition_utils.py:
##########
@@ -0,0 +1,57 @@
+# 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 itertools import filterfalse
+from typing import TYPE_CHECKING, List
+
+from gravitino.utils.precondition import Precondition
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class PartitionUtils:
+ """Validates the existence of the partition field in the table."""
+
+ @staticmethod
+ def validate_field_existence(
+ columns: List["ColumnDTO"], field_name: List[str]
+ ) -> None:
+ """Validates the existence of the partition field in the table.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+ field_name (List[str]): The name of the field to validate.
+
+ Raises:
+ IllegalArgumentException: If the field does not exist in the table, this exception is thrown.
+ """
+ Precondition.check_argument(
Review Comment:
@unknowntpo I've made the corresponding changes. Please take review on it when you're available. Thanks!
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "tsungchih (via GitHub)" <gi...@apache.org>.
tsungchih commented on code in PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#discussion_r2147409180
##########
clients/client-python/gravitino/dto/rel/partition_utils.py:
##########
@@ -0,0 +1,57 @@
+# 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 itertools import filterfalse
+from typing import TYPE_CHECKING, List
+
+from gravitino.utils.precondition import Precondition
+
+if TYPE_CHECKING:
+ from gravitino.dto.rel.column_dto import ColumnDTO
+
+
+class PartitionUtils:
+ """Validates the existence of the partition field in the table."""
+
+ @staticmethod
+ def validate_field_existence(
+ columns: List["ColumnDTO"], field_name: List[str]
+ ) -> None:
+ """Validates the existence of the partition field in the table.
+
+ Args:
+ columns (List[ColumnDTO]): The columns of the table.
+ field_name (List[str]): The name of the field to validate.
+
+ Raises:
+ IllegalArgumentException: If the field does not exist in the table, this exception is thrown.
+ """
+ Precondition.check_argument(
Review Comment:
I'll keep the implementation aligned with the Java one. Thanks for the comments.
--
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] [#5202] feat(client-python): Add ColumnDTO related classes [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #7357:
URL: https://github.com/apache/gravitino/pull/7357#issuecomment-2996167852
@unknowntpo would you please help to review again, thanks.
--
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