unknowntpo commented on code in PR #8763: URL: https://github.com/apache/gravitino/pull/8763#discussion_r2412421652
########## clients/client-python/gravitino/dto/rel/table_dto.py: ########## @@ -0,0 +1,140 @@ +# 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 dataclasses import dataclass, field +from typing import Optional + +from dataclasses_json import DataClassJsonMixin, config + +from gravitino.api.rel.expressions.distributions.distribution import Distribution +from gravitino.api.rel.expressions.transforms.transform import Transform +from gravitino.api.rel.indexes.index import Index +from gravitino.api.rel.table import Table +from gravitino.dto.audit_dto import AuditDTO +from gravitino.dto.rel.column_dto import ColumnDTO +from gravitino.dto.rel.distribution_dto import DistributionDTO +from gravitino.dto.rel.indexes.index_dto import IndexDTO +from gravitino.dto.rel.indexes.json_serdes.index_serdes import IndexSerdes +from gravitino.dto.rel.json_serdes.distribution_serdes import DistributionSerDes +from gravitino.dto.rel.json_serdes.sort_order_serdes import SortOrderSerdes +from gravitino.dto.rel.partitioning.json_serdes.partitioning_serdes import ( + PartitioningSerdes, +) +from gravitino.dto.rel.partitioning.partitioning import Partitioning +from gravitino.dto.rel.sort_order_dto import SortOrderDTO +from gravitino.utils.precondition import Precondition + + +@dataclass +class TableDTO(Table, DataClassJsonMixin): # pylint: disable=R0902 + """Represents a Table DTO (Data Transfer Object).""" + + _name: Optional[str] = field(default=None, metadata=config(field_name="name")) + _columns: Optional[list[ColumnDTO]] = field( + default=None, metadata=config(field_name="columns") + ) + _audit: Optional[AuditDTO] = field( + default=None, metadata=config(field_name="audit") + ) + _comment: Optional[str] = field( + default=None, + metadata=config(field_name="comment", exclude=lambda value: value is None), + ) + _distribution: Optional[DistributionDTO] = field( + default=None, + metadata=config( + field_name="distribution", + encoder=DistributionSerDes.serialize, + decoder=DistributionSerDes.deserialize, + exclude=lambda value: value is None, + ), + ) + _sort_orders: Optional[list[SortOrderDTO]] = field( + default=None, + metadata=config( + field_name="sortOrders", + encoder=lambda items: [SortOrderSerdes.serialize(item) for item in items], + decoder=lambda values: [ + SortOrderSerdes.deserialize(value) for value in values + ], + exclude=lambda value: value is None, + ), + ) + _partitioning: Optional[list[Partitioning]] = field( + default=None, + metadata=config( + field_name="partitioning", + encoder=lambda items: [ + PartitioningSerdes.serialize(item) for item in items + ], + decoder=lambda values: [ + PartitioningSerdes.deserialize(value) for value in values + ], + exclude=lambda value: value is None, + ), + ) + _indexes: Optional[list[IndexDTO]] = field( + default=None, + metadata=config( + field_name="indexes", + encoder=lambda items: [IndexSerdes.serialize(item) for item in items], + decoder=lambda values: [IndexSerdes.deserialize(value) for value in values], + exclude=lambda value: value is None, + ), + ) + _properties: Optional[dict[str, str]] = field( + default=None, + metadata=config(field_name="properties", exclude=lambda value: value is None), + ) + + def __post_init__(self): + Precondition.check_argument( + self._name is not None and self._name.strip() != "", Review Comment: Why we need to strip name before checking empty ? ########## clients/client-python/gravitino/api/rel/table.py: ########## @@ -0,0 +1,112 @@ +# 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 abc import abstractmethod +from typing import Optional + +from gravitino.api.auditable import Auditable +from gravitino.api.rel.column import Column +from gravitino.api.rel.expressions.distributions.distribution import Distribution +from gravitino.api.rel.expressions.distributions.distributions import Distributions +from gravitino.api.rel.expressions.sorts.sort_order import SortOrder +from gravitino.api.rel.expressions.transforms.transform import Transform +from gravitino.api.rel.expressions.transforms.transforms import Transforms +from gravitino.api.rel.indexes.index import Index +from gravitino.api.rel.indexes.indexes import Indexes + + +class Table(Auditable): + """An interface representing a table in a `Namespace`. + + It defines the basic properties of a table. A catalog implementation with `TableCatalog` + should implement this interface. + """ + + @abstractmethod + def name(self) -> str: + """Gets name of the table. + + Returns: + str: Name of the table. + """ + + @abstractmethod + def columns(self) -> list[Column]: + """Gets the columns of the table. + + Returns: + list[Column]: The columns of the table. + """ + + def partitioning(self) -> list[Transform]: + """Gets the physical partitioning of the table. + + Returns: + list[Transform]: The physical partitioning of the table. + """ + + return Transforms.EMPTY_TRANSFORM + + def sort_order(self) -> list[SortOrder]: + """Gets the sort order of the table. + + Returns: + list[SortOrder]: + The sort order of the table. If no sort order is specified, an empty list is returned. + """ + + return [] + + def distribution(self) -> Distribution: + """Gets the bucketing of the table. + + Returns: + Distribution: + The bucketing of the table. If no bucketing is specified, `Distribution.NONE` is returned. + """ + + return Distributions.NONE + + def index(self) -> list[Index]: + """Gets the indexes of the table. + + Returns: + list[Index]: + The indexes of the table. If no indexes are specified, `Indexes.EMPTY_INDEXES` is returned. + """ + + return Indexes.EMPTY_INDEXES + + def comment(self) -> Optional[str]: + """Gets the comment of the table. + + Returns: + str (optional): + The comment of the table. `None` is returned if no comment is set. + """ + + return None + + def properties(self) -> dict[str, str]: + """Gets the properties of the table. + + Returns: + dict[str, str]: + The properties of the table. Empty dictionary is returned if no properties are set. + """ + + return {} Review Comment: Where do we implement `supportPartitions`, `supportsTags`, `supportsPolicies`, `supportsRoles` ? `supportsStatistics`, `supportsPartitionStatistics` default 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
