sungwy commented on code in PR #2154:
URL: https://github.com/apache/iceberg-python/pull/2154#discussion_r2178796429


##########
pyiceberg/view/metadata.py:
##########
@@ -0,0 +1,89 @@
+# 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 __future__ import annotations
+
+from typing import Dict, List, Literal, Optional
+
+from pydantic import Field, field_validator
+
+from pyiceberg.schema import Schema
+from pyiceberg.typedef import IcebergBaseModel, Properties
+from pyiceberg.types import transform_dict_value_to_str
+
+
+class SQLViewRepresentation(IcebergBaseModel):
+    """Represents the SQL query that defines the view."""
+
+    type: Literal["sql"] = Field()
+    """A string that indicates the type of representation. Must be `sql`"""
+    sql: str = Field()
+    """A string that contains the SQL text of the view definition."""
+    dialect: str = Field()
+    """The dialect of the SQL, e.g. `spark`, `trino`, `presto`."""
+
+
+class ViewVersion(IcebergBaseModel):
+    """A version of the view definition."""
+
+    version_id: int = Field(alias="version-id")
+    """ID for the version"""
+    schema_id: int = Field(alias="schema-id")
+    """ID of the schema for the view version"""
+    timestamp_ms: int = Field(alias="timestamp-ms")
+    """Timestamp when the version was created (ms from epoch)"""
+    summary: Dict[str, str] = Field()
+    """A string to string map of summary metadata about the version"""
+    representations: List[SQLViewRepresentation] = Field()

Review Comment:
   I think we'd want to align more closely with the Open API Spec and represent 
this as a list of `ViewRepresentation` instead: 
https://github.com/apache/iceberg/blob/dfecabc76c5b82ecdde7d61abdf540d43ee14f59/open-api/rest-catalog-open-api.yaml#L2643



##########
pyiceberg/catalog/rest/__init__.py:
##########
@@ -172,6 +182,18 @@ def transform_properties_dict_value_to_str(cls, 
properties: Properties) -> Dict[
         return transform_dict_value_to_str(properties)
 
 
+class CreateViewRequest(IcebergBaseModel):
+    name: str = Field()
+    location: Optional[str] = Field()
+    view_schema: Schema = Field(alias="schema")
+    view_version: ViewVersion = Field(alias="view-version")
+    properties: Dict[str, str] = Field(default_factory=dict)

Review Comment:
   nit:
   ```suggestion
       properties: Properties = Field(default_factory=dict)
   ```



##########
pyiceberg/view/metadata.py:
##########
@@ -0,0 +1,89 @@
+# 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 __future__ import annotations
+
+from typing import Dict, List, Literal, Optional
+
+from pydantic import Field, field_validator
+
+from pyiceberg.schema import Schema
+from pyiceberg.typedef import IcebergBaseModel, Properties
+from pyiceberg.types import transform_dict_value_to_str
+
+
+class SQLViewRepresentation(IcebergBaseModel):
+    """Represents the SQL query that defines the view."""
+
+    type: Literal["sql"] = Field()
+    """A string that indicates the type of representation. Must be `sql`"""
+    sql: str = Field()
+    """A string that contains the SQL text of the view definition."""
+    dialect: str = Field()
+    """The dialect of the SQL, e.g. `spark`, `trino`, `presto`."""
+
+

Review Comment:
   Suggestion to define `ViewRepresentation` and use it in the below 
`ViewVersion` class
   
   ```suggestion
   
   
   class ViewRepresentation(BaseModel):
       __root__: SQLViewRepresentation
       
       
   ```



##########
pyiceberg/view/metadata.py:
##########
@@ -0,0 +1,89 @@
+# 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 __future__ import annotations
+
+from typing import Dict, List, Literal, Optional
+
+from pydantic import Field, field_validator
+
+from pyiceberg.schema import Schema
+from pyiceberg.typedef import IcebergBaseModel, Properties
+from pyiceberg.types import transform_dict_value_to_str
+
+
+class SQLViewRepresentation(IcebergBaseModel):
+    """Represents the SQL query that defines the view."""
+
+    type: Literal["sql"] = Field()
+    """A string that indicates the type of representation. Must be `sql`"""
+    sql: str = Field()
+    """A string that contains the SQL text of the view definition."""
+    dialect: str = Field()
+    """The dialect of the SQL, e.g. `spark`, `trino`, `presto`."""
+
+
+class ViewVersion(IcebergBaseModel):
+    """A version of the view definition."""
+
+    version_id: int = Field(alias="version-id")
+    """ID for the version"""
+    schema_id: int = Field(alias="schema-id")
+    """ID of the schema for the view version"""
+    timestamp_ms: int = Field(alias="timestamp-ms")
+    """Timestamp when the version was created (ms from epoch)"""
+    summary: Dict[str, str] = Field()
+    """A string to string map of summary metadata about the version"""
+    representations: List[SQLViewRepresentation] = Field()
+    """A list of representations for the view definition"""
+    default_catalog: Optional[str] = Field(alias="default-catalog", 
default=None)
+    """Catalog name to use when a reference in the SELECT does not contain a 
catalog"""
+    default_namespace: List[str] = Field(alias="default-namespace")
+    """Namespace to use when a reference in the SELECT is a single 
identifier"""
+
+
+class ViewVersionLogEntry(IcebergBaseModel):

Review Comment:
   nit: is there a reason why we are using a different name than the 
[spec](https://github.com/apache/iceberg/blob/f24f0c093e55743c291b5835cd19931d1ca787d0/open-api/rest-catalog-open-api.yaml#L2606C5-L2606C21)?
   ```suggestion
   class ViewHistoryEntry(IcebergBaseModel):
   ```



##########
pyiceberg/view/metadata.py:
##########
@@ -0,0 +1,89 @@
+# 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 __future__ import annotations
+
+from typing import Dict, List, Literal, Optional
+
+from pydantic import Field, field_validator
+
+from pyiceberg.schema import Schema
+from pyiceberg.typedef import IcebergBaseModel, Properties
+from pyiceberg.types import transform_dict_value_to_str
+
+
+class SQLViewRepresentation(IcebergBaseModel):
+    """Represents the SQL query that defines the view."""
+
+    type: Literal["sql"] = Field()
+    """A string that indicates the type of representation. Must be `sql`"""
+    sql: str = Field()
+    """A string that contains the SQL text of the view definition."""
+    dialect: str = Field()
+    """The dialect of the SQL, e.g. `spark`, `trino`, `presto`."""
+
+
+class ViewVersion(IcebergBaseModel):
+    """A version of the view definition."""
+
+    version_id: int = Field(alias="version-id")
+    """ID for the version"""
+    schema_id: int = Field(alias="schema-id")
+    """ID of the schema for the view version"""
+    timestamp_ms: int = Field(alias="timestamp-ms")
+    """Timestamp when the version was created (ms from epoch)"""
+    summary: Dict[str, str] = Field()
+    """A string to string map of summary metadata about the version"""
+    representations: List[SQLViewRepresentation] = Field()
+    """A list of representations for the view definition"""
+    default_catalog: Optional[str] = Field(alias="default-catalog", 
default=None)
+    """Catalog name to use when a reference in the SELECT does not contain a 
catalog"""
+    default_namespace: List[str] = Field(alias="default-namespace")
+    """Namespace to use when a reference in the SELECT is a single 
identifier"""
+
+
+class ViewVersionLogEntry(IcebergBaseModel):
+    """A log entry of a view version change."""
+
+    timestamp_ms: int = Field(alias="timestamp-ms")
+    """Timestamp when the version was created (ms from epoch)"""
+    version_id: int = Field(alias="version-id")
+    """ID for the version"""
+
+
+class ViewMetadata(IcebergBaseModel):
+    """The metadata for a view."""
+
+    view_uuid: str = Field(alias="view-uuid")
+    """A UUID that identifies the view, generated when the view is created."""
+    format_version: Literal[1] = Field(alias="format-version")

Review Comment:
   nit:
   ```suggestion
       format_version: int = Field(alias='format-version', ge=1, le=1)
   ```



##########
pyiceberg/view/metadata.py:
##########
@@ -0,0 +1,89 @@
+# 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 __future__ import annotations
+
+from typing import Dict, List, Literal, Optional
+
+from pydantic import Field, field_validator
+
+from pyiceberg.schema import Schema
+from pyiceberg.typedef import IcebergBaseModel, Properties
+from pyiceberg.types import transform_dict_value_to_str
+
+
+class SQLViewRepresentation(IcebergBaseModel):
+    """Represents the SQL query that defines the view."""
+
+    type: Literal["sql"] = Field()
+    """A string that indicates the type of representation. Must be `sql`"""
+    sql: str = Field()
+    """A string that contains the SQL text of the view definition."""
+    dialect: str = Field()
+    """The dialect of the SQL, e.g. `spark`, `trino`, `presto`."""
+
+
+class ViewVersion(IcebergBaseModel):
+    """A version of the view definition."""
+
+    version_id: int = Field(alias="version-id")
+    """ID for the version"""
+    schema_id: int = Field(alias="schema-id")
+    """ID of the schema for the view version"""
+    timestamp_ms: int = Field(alias="timestamp-ms")
+    """Timestamp when the version was created (ms from epoch)"""
+    summary: Dict[str, str] = Field()
+    """A string to string map of summary metadata about the version"""
+    representations: List[SQLViewRepresentation] = Field()
+    """A list of representations for the view definition"""
+    default_catalog: Optional[str] = Field(alias="default-catalog", 
default=None)
+    """Catalog name to use when a reference in the SELECT does not contain a 
catalog"""
+    default_namespace: List[str] = Field(alias="default-namespace")

Review Comment:
   We should use the existing Namespace class here instead
   
   ```suggestion
       default_namespace: Namespace = Field(alias="default-namespace")
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to