Copilot commented on code in PR #11948: URL: https://github.com/apache/gravitino/pull/11948#discussion_r3549220996
########## clients/client-python/gravitino/dto/responses/view_response.py: ########## @@ -0,0 +1,47 @@ +# 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 dataclasses_json import config + +from gravitino.dto.rel.view_dto import ViewDTO +from gravitino.dto.responses.base_response import BaseResponse +from gravitino.exceptions.base import IllegalArgumentException + + +@dataclass +class ViewResponse(BaseResponse): + """Response object for view-related operations.""" + + _view: ViewDTO = field(metadata=config(field_name="view")) + + def view(self) -> ViewDTO: + """Returns the view DTO.""" + return self._view + + def validate(self): + """Validates the response data.""" + super().validate() + if self._view is None: + raise IllegalArgumentException("view must not be null") + if not self._view.name(): + raise IllegalArgumentException("view 'name' must not be null or empty") + if self._view.audit_info() is None: + raise IllegalArgumentException("view 'audit' must not be null") + if not self._view.representations(): + raise IllegalArgumentException("view 'representations' must not be null") Review Comment: `ViewResponse.validate()` rejects empty `representations()`, but the error message says it "must not be null". This makes debugging harder because an empty list will produce a misleading message. ########## clients/client-python/gravitino/dto/requests/view_create_request.py: ########## @@ -0,0 +1,90 @@ +# 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 config + +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.rel.sql_representation_dto import SQLRepresentationDTO +from gravitino.rest.rest_message import RESTRequest +from gravitino.utils.precondition import Precondition + + +@dataclass +class ViewCreateRequest(RESTRequest): + """Represents a request to create a view.""" + + _name: str = field(metadata=config(field_name="name")) + _columns: Optional[list[ColumnDTO]] = field( + default=None, metadata=config(field_name="columns") + ) + _representations: list[RepresentationDTO] = field( + default=None, + metadata=config( + field_name="representations", + encoder=lambda items: [ + RepresentationSerdes.serialize(item) for item in items + ], + ), + ) + _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 validate(self): + Precondition.check_string_not_empty( + self._name, '"name" field is required and cannot be empty' + ) + Precondition.check_argument( + self._representations is not None and len(self._representations) > 0, + '"representations" field is required and cannot be empty', + ) + for representation in self._representations: + Precondition.check_argument( + representation is not None, "representation must not be null" + ) + representation.validate() + if self._columns: + for column in self._columns: + Precondition.check_argument( + column is not None, "column must not be null" + ) + column.validate() + ViewCreateRequest.validate_no_duplicate_dialects(self._representations) + + @staticmethod + def validate_no_duplicate_dialects(representations: list[RepresentationDTO]): + """Validate that SQL representations do not use duplicate dialects.""" + seen_dialects = set() + for representation in representations: + if isinstance(representation, SQLRepresentationDTO): + Precondition.check_argument( + representation.dialect() not in seen_dialects, + f"Duplicate SQL representation dialect: {representation.dialect()}", + ) + seen_dialects.add(representation.dialect()) Review Comment: Duplicate-dialect validation is currently case-sensitive (e.g., "TRINO" and "trino" are treated as different). Since `View.sql_for()` resolves dialects case-insensitively, this can allow ambiguous duplicate SQL representations; the duplicate check should normalize dialects before comparing. -- 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]
