-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[Python] Add a symlink to the OpenAPI rest catalog spec and package it with the python library #4545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Python] Add a symlink to the OpenAPI rest catalog spec and package it with the python library #4545
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../open-api/rest-catalog-open-api.yaml |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| # 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. | ||||||
|
|
||||||
| import os | ||||||
| from functools import lru_cache | ||||||
|
|
||||||
| import yaml | ||||||
|
|
||||||
| from iceberg import assets | ||||||
|
|
||||||
|
|
||||||
| @cache | ||||||
| def read_yaml_file(path: str): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return yaml.safe_load(open(path)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If something happens, we'll clean up the connection: with open(path) as f:
return yaml.safe_load(f |
||||||
|
|
||||||
|
|
||||||
| def load_openapi_spec(): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return read_yaml_file(os.path.join(list(assets.__path__)[0], "rest-catalog-open-api.yaml")) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # 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. | ||
|
|
||
| import os | ||
| import tempfile | ||
|
|
||
| import yaml | ||
|
|
||
| from iceberg.utils import openapi | ||
|
|
||
|
|
||
| def test_reading_a_yaml_file(): | ||
| with tempfile.TemporaryDirectory() as tmpdirname: | ||
| data = {"foo": "bar"} | ||
| file_location = os.path.join(tmpdirname, "foo.yaml") | ||
| with open(file_location, "w") as f: | ||
| yaml.dump(data, f) | ||
| assert openapi.read_yaml_file(file_location) == {"foo": "bar"} | ||
|
|
||
|
|
||
| def test_loading_rest_catalog_openapi_spec(): | ||
| rest_catalog_openapi_spec = openapi.load_openapi_spec() | ||
| assert rest_catalog_openapi_spec["info"]["title"] == "Apache Iceberg REST Catalog API" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make pyyaml a dependency of the library itself? If so, is there anyway to make it just a “test” dependency or something or will we need it at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need it at runtime. Specifically in the
TableMetadataclass which hasn't been merged in yet but the idea is that reading in a table metadata file will be validated against the open api spec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we gonna do that for every file on every read? Or just as a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a great question and I think we can decide on that later. The TableMetadata PR is still a WIP but that class includes this validate method. So we may have certain paths where we don't validate (loading a metadata file from a path we got from a catalog) and other paths where we do validate (like before writing+committing a new metadata file), just as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to pin it on a version. Currently it will just install the latest greatest, but there might be breaking changes (happens all the time in Python land :)