You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Fokko (via GitHub)" <gi...@apache.org> on 2023/06/01 10:42:14 UTC
[GitHub] [iceberg] Fokko opened a new pull request, #7751: Open-API: Add Python code as an example
Fokko opened a new pull request, #7751:
URL: https://github.com/apache/iceberg/pull/7751
This make it easier (at least for me), to see the impact on the code that's being generated. Polymorphism and Inheritance is not always clear to me from the spec, but it is from the Python code.
--
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
[GitHub] [iceberg] Fokko commented on pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1574741600
@dramaticlly Thanks for the suggestion. People won't directly use the Python code, nor I would expect a Java/Javascript version of it. It is more for the developer to see the impact on the code when making changes to the yaml. I think having everything in the same folder makes things simpler (otherwise I'd be inclined to add another `README.md` to the `open-api/` dir). I think adding the directory doesn't add much value other than adding more complexity to the directory structure. WDYT?
--
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
[GitHub] [iceberg] dramaticlly commented on pull request #7751: Open-API: Add Python code as an example
Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1577053405
> @dramaticlly Thanks for the suggestion. People won't directly use the Python code, nor I would expect a Java/Javascript version of it. It is more for the developer to see the impact on the code when making changes to the yaml. I think having everything in the same folder makes things simpler (otherwise I'd be inclined to add another `README.md` to the `open-api/` dir). I think adding the directory doesn't add much value other than adding more complexity to the directory structure. WDYT?
I see, thanks for the explanation. For those generated code, do we want every change in spec to kick off the python generation and include such in PR or do you plan to add some sort of git action to apply it automatically? Anyway, change LGTM
--
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
[GitHub] [iceberg] rdblue commented on pull request #7751: Open-API: Add Python code as an example
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1577333737
Why add the Python code? We could just have a README that explains how to generate it. I think it's a little confusing to have the code here, since it isn't used by the pyiceberg implementation.
--
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
[GitHub] [iceberg] Fokko commented on a diff in pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#discussion_r1213140553
##########
open-api/README.md:
##########
@@ -0,0 +1,23 @@
+# Open API spec
+
+The `rest-catalog-open-api.yaml` defines the REST catalog interface.
+
+## Lint
+
+To make sure that the open-api definition is valid, you can run the `lint` command:
+
+```sh
+make install
+make lint
+```
+
+## Generate Python code
+
+When reviewing changes in the spec, it helps to see what kind of code is being generated from the spec. We generate Python code to make this process easier. Before committing, make sure to run:
Review Comment:
Thanks :) I thought adding some context would help, but it might be obvious.
--
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
[GitHub] [iceberg] Fokko commented on pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1578307090
@dramaticlly Thanks. I would suggest doing the update by hand, for now, we can always automate stuff later on. I don't think it is a big hurdle since the open-api spec doesn't get updated very often.
--
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
[GitHub] [iceberg] Fokko commented on pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1578307592
Thanks @dramaticlly, @nastra and @rdblue for the review, much appreciated!
--
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
[GitHub] [iceberg] nastra commented on a diff in pull request #7751: Open-API: Add Python code as an example
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#discussion_r1213143889
##########
open-api/README.md:
##########
@@ -0,0 +1,42 @@
+<!--
+ - 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.
+ -->
+
+# Open API spec
+
+The `rest-catalog-open-api.yaml` defines the REST catalog interface.
+
+## Lint
+
+To make sure that the open-api definition is valid, you can run the `lint` command:
+
+```sh
+make install
+make lint
+```
+
+## Generate Python code
+
+When updating `rest-catalog-open-api.yaml`, make sure to update `rest-catalog-open-api.py` with the spec changes by running the following commands:
+
+```sh
+make install
+make generate
+```
+
+To update `rest-catalog-open-api.py` to the latest version.
Review Comment:
nit: I think this one can be removed now ;)
--
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
[GitHub] [iceberg] nastra commented on a diff in pull request #7751: Open-API: Add Python code as an example
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#discussion_r1213067357
##########
open-api/README.md:
##########
@@ -0,0 +1,23 @@
+# Open API spec
+
+The `rest-catalog-open-api.yaml` defines the REST catalog interface.
+
+## Lint
+
+To make sure that the open-api definition is valid, you can run the `lint` command:
+
+```sh
+make install
+make lint
+```
+
+## Generate Python code
+
+When reviewing changes in the spec, it helps to see what kind of code is being generated from the spec. We generate Python code to make this process easier. Before committing, make sure to run:
Review Comment:
I'm guessing you mean before committing changes to the Spec with `Before committing`? Maybe we can simplify/change this sentence to:
*When updating `rest-catalog-open-api.yaml`, make sure to update `rest-catalog-open-api.py` with the spec changes by running the following commands:*
```sh
make install
make generate
```
--
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
[GitHub] [iceberg] rdblue commented on pull request #7751: Open-API: Add Python code as an example
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1577575745
Makes sense to me! Can we also add a README explaining why there is code here? It's not like we actually think people would use this as a library, right?
--
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
[GitHub] [iceberg] Fokko commented on pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #7751:
URL: https://github.com/apache/iceberg/pull/7751#issuecomment-1577410577
@rdblue The idea is that you'll have the changes in the open-api spec and also the changes in the Python code alongside. Small changes can have a significant impact on the code itself.
Let's take https://github.com/apache/iceberg/pull/7710#discussion_r1216646858
```yaml
ReportMetricsRequest:
anyOf:
- $ref: '#/components/schemas/ScanReport'
- $ref: '#/components/schemas/CommitReport'
required:
- report-type
properties:
report-type:
type: string
```
Above is the the current code on master, and that generates:
```python
class ReportMetricsRequest(ScanReport):
report_type: str = Field(..., alias='report-type')
class ReportMetricsRequest1(CommitReport):
report_type: str = Field(..., alias='report-type')
class ReportMetricsRequest2(BaseModel):
__root__: Union[ReportMetricsRequest, ReportMetricsRequest1]
```
This looks weird, and it is. `ReportMetricsRequest` is `anyOf` (validates the value against any (one or more) of the subschemas) of both `ScanReport` and `CommitReport`. It is actually the other way around. `ScanReport` and `CommitReport` is `allOf` `ReportMetricsRequest`. And based on the `report-type` it is `oneOf` the subtypes based on the `report-type`:
```yaml
ReportMetricsRequest:
type: object
discriminator:
propertyName: report-type
mapping:
commit-report: '#/components/schemas/CommitReport'
scan-report: '#/components/schemas/ScanReport'
required:
- report-type
properties:
report-type:
type: string
```
The point that I'm trying to make here is that is very easy to get confused in the `allOf`, `anyOf`, and `oneOf`. And for me, it really helps to see the code alongside the PR. The idea is that we keep the Python code up to sync, and when you update the open-api code, you'll see the impact on the code. If you do it the other way around, you'll end up with:
```python
class ReportMetricsRequest(BaseModel):
report_type: str = Field(..., alias='report-type')
class CommitReport(ReportMetricsRequest):
report_type: Literal['commit-report'] = Field(..., alias='report-type')
table_name: str = Field(..., alias='table-name')
snapshot_id: int = Field(..., alias='snapshot-id')
sequence_number: int = Field(..., alias='sequence-number')
operation: str
metrics: Metrics
metadata: Optional[Dict[str, str]] = None
class ScanReport(ReportMetricsRequest):
report_type: Literal['scan-report'] = Field(..., alias='report-type')
table_name: str = Field(..., alias='table-name')
snapshot_id: int = Field(..., alias='snapshot-id')
filter: Expression
schema_id: int = Field(..., alias='schema-id')
projected_field_ids: List[int] = Field(..., alias='projected-field-ids')
projected_field_names: List[str] = Field(..., alias='projected-field-names')
metrics: Metrics
metadata: Optional[Dict[str, str]] = None
```
If we want to generate clients in other languages as well, it helps to keep the open-API as close to the supposed implementation as possible.
--
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
[GitHub] [iceberg] Fokko merged pull request #7751: Open-API: Add Python code as an example
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #7751:
URL: https://github.com/apache/iceberg/pull/7751
--
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