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/05/25 16:45:26 UTC

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

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


##########
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:
   You can't use a `-` in a variable in Python, therefore it uses the alias. When going back and forth between dicts and json you can explicitly tell it to use the alias:
   ```python
   ➜  iceberg git:(fd-open-api) ✗ python3
   Python 3.9.13 (main, May 19 2022, 13:48:47) 
   [Clang 13.1.6 (clang-1316.0.21.2)] on darwin
   Type "help", "copyright", "credits" or "license" for more information.
   >>> from pydantic import BaseModel, Field
   >>> 
   >>> class BarModel(BaseModel):
   ...     what_ever: int = Field(alias='what-ever')
   ... 
   >>> BarModel(**{'what-ever': 123})
   BarModel(what_ever=123)
   >>> model = BarModel(**{'what-ever': 123})
   >>> model.dict()
   {'what_ever': 123}
   >>> model.dict(by_alias=True)
   {'what-ever': 123}
   >>> model.json(by_alias=True)
   '{"what-ever": 123}'
   ```



-- 
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