kevinw66 commented on code in PR #12090: URL: https://github.com/apache/gravitino/pull/12090#discussion_r3613979340
########## clients/client-python/gravitino/dto/rel/view_dto.py: ########## @@ -0,0 +1,105 @@ +# 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.column import Column +from gravitino.api.rel.representation import Representation +from gravitino.api.rel.view import View +from gravitino.dto.audit_dto import AuditDTO +from gravitino.dto.rel.column_dto import ColumnDTO +from gravitino.dto.rel.json_serdes.representation_serdes import RepresentationSerdes +from gravitino.dto.rel.representation_dto import RepresentationDTO +from gravitino.dto.util.dto_converters import DTOConverters +from gravitino.utils.precondition import Precondition + + +@dataclass +class ViewDTO(View, DataClassJsonMixin): # pylint: disable=too-many-instance-attributes + """Represents a View DTO.""" + + _name: str = field(metadata=config(field_name="name")) + _columns: Optional[list[ColumnDTO]] = field( + default=None, metadata=config(field_name="columns") + ) + _representations: Optional[list[RepresentationDTO]] = field( + default=None, + metadata=config( + field_name="representations", + encoder=lambda items: [ + RepresentationSerdes.serialize(item) for item in items + ], + decoder=lambda values: [ + RepresentationSerdes.deserialize(value) for value in values + ], + ), + ) + _audit: Optional[AuditDTO] = field( + default=None, metadata=config(field_name="audit") + ) + _comment: Optional[str] = field(default=None, metadata=config(field_name="comment")) + _default_catalog: Optional[str] = field( + default=None, metadata=config(field_name="defaultCatalog") + ) + _default_schema: Optional[str] = field( + default=None, metadata=config(field_name="defaultSchema") + ) + _properties: Optional[dict[str, str]] = field( + default=None, metadata=config(field_name="properties") + ) + + def __post_init__(self): + if self._columns is None: + self._columns = [] + Precondition.check_string_not_empty(self._name, "name cannot be null or empty") + Precondition.check_argument(self._audit is not None, "audit cannot be null") + Precondition.check_argument( + self._representations is not None and len(self._representations) > 0, + "representations cannot be null or empty", + ) Review Comment: This behavior intentionally mirrors the Java `ViewDTO`: the backing properties field remains nullable, while properties() returns an empty map when it is null. ```java // Class ViewDTO private ViewDTO( String name, @Nullable String comment, ColumnDTO[] columns, RepresentationDTO[] representations, @Nullable String defaultCatalog, @Nullable String defaultSchema, @Nullable Map<String, String> properties, AuditDTO audit) { this.name = name; this.comment = comment; this.columns = columns; this.representations = representations; this.defaultCatalog = defaultCatalog; this.defaultSchema = defaultSchema; this.properties = properties; this.audit = audit; } ... @Override public Map<String, String> properties() { return properties == null ? Collections.emptyMap() : properties; } ``` -- 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]
