You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/06/01 17:38:53 UTC

[GitHub] [iceberg] kbendick commented on a diff in pull request #4858: Python: Add generated classes from OpenAPI spec

kbendick commented on code in PR #4858:
URL: https://github.com/apache/iceberg/pull/4858#discussion_r883860738


##########
python/src/iceberg/openapi/rest_catalog.py:
##########
@@ -0,0 +1,503 @@
+# 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.
+# generated by datamodel-codegen:
+#   filename:  rest-catalog-open-api.yaml
+
+from __future__ import annotations
+
+from enum import Enum
+from typing import Any, Dict, List, Literal, Optional, Union
+
+from pydantic import BaseModel, Extra, Field
+
+
+class ErrorModel(BaseModel):
+    """
+    JSON error payload returned in a response with further details on the error
+    """
+
+    message: str = Field(..., description='Human-readable error message')
+    type: str = Field(
+        ...,
+        description='Internal type definition of the error',
+        example='NoSuchNamespaceException',
+    )
+    code: int = Field(
+        ..., description='HTTP response code', example=404, ge=400, le=600
+    )
+    stack: Optional[List[str]] = None
+
+
+class CatalogConfig(BaseModel):
+    """
+    Server-provided configuration for the catalog.
+    """
+
+    overrides: Dict[str, Any] = Field(
+        ...,
+        description='Properties that should be used to override client configuration; applied after defaults and client configuration.',
+    )
+    defaults: Dict[str, Any] = Field(
+        ...,
+        description='Properties that should be used as default configuration; applied before client configuration.',
+    )
+
+
+class Updates(BaseModel):
+    pass
+
+
+class UpdateNamespacePropertiesRequest(BaseModel):
+    removals: Optional[List[str]] = Field(
+        None, example=['department', 'access_group'], unique_items=True
+    )
+    updates: Optional[Union[List[str], Updates]] = Field(
+        None, example={'owner': 'Hank Bendickson'}, unique_items=True
+    )
+
+
+class Namespace(BaseModel):
+    """
+    Reference to one or more levels of a namespace
+    """
+
+    __root__: List[str] = Field(
+        ...,
+        description='Reference to one or more levels of a namespace',
+        example=['accounting', 'tax'],
+    )
+
+
+class TableIdentifier(BaseModel):
+    namespace: Namespace
+    name: str
+
+
+class PrimitiveType(BaseModel):
+    __root__: str = Field(..., example=['long', 'string', 'fixed[16]', 'decimal(10,2)'])
+
+
+class Transform(BaseModel):
+    __root__: str = Field(
+        ...,
+        example=[
+            'identity',
+            'year',
+            'month',
+            'day',
+            'hour',
+            'bucket[256]',
+            'truncate[16]',
+        ],
+    )
+
+
+class PartitionField(BaseModel):
+    field_id: Optional[int] = Field(None, alias='field-id')

Review Comment:
   We would need to use the proper name (kebab case `field-id`) any time it's serialized, be that stored in a file or sent over the network for things like the REST catalog etc.
   
   I don't personally think it's a good idea to start allowing for multiple forms accepted when stored in files or over the network, as we'll always have to support those then and it adds unnecessary complexity. We have some places where we have additional logic for things like 3-level lists in parquet (as their form changed during some versions before). So once those files are written, we _always_ have to support that alternative form or we have to make the choice to break people's existing tables (that they might have not touched for a while).
   
   So generally that's something we'd avoid when serializing within files or within REST requests.
   
   Otherwise, within the Python project and code itself, it is fine to use underscore and other things. E.g. Java doesn't allow for `field-id` as an identifier so we would generally use `fieldId`.
   
   We'd just want to be sure that we test that the JSON is always generated and used correctly (either via some helper that ensures `by_alias` is used when needed or just extensive testing).



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org