Skip to content

Add support for registering views#3288

Open
ebyhr wants to merge 2 commits intoapache:mainfrom
ebyhr:ebi/register_view
Open

Add support for registering views#3288
ebyhr wants to merge 2 commits intoapache:mainfrom
ebyhr:ebi/register_view

Conversation

@ebyhr
Copy link
Copy Markdown
Member

@ebyhr ebyhr commented Apr 26, 2026

Rationale for this change

Are these changes tested?

tests/catalog/test_rest.py contains new tests.

Are there any user-facing changes?

This PR adds a new register_view method to catalog.

try:
response.raise_for_status()
except HTTPError as exc:
_handle_non_200_response(exc, {409: ViewAlreadyExistsError})
Copy link
Copy Markdown
Contributor

@gabeiglio gabeiglio Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if here we can catch a TableAlreadyExists if there is a table already registered with the same identifier?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, this behavior is seen in the java impl:

https://github.com/apache/iceberg/blob/b0f022ff29945fe70f51485a1f1cda3d35eed8ca/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java#L310-L316

This is also what the rest spec defines

https://github.com/apache/iceberg/blob/b0f022ff29945fe70f51485a1f1cda3d35eed8ca/open-api/rest-catalog-open-api.yaml#L1927-L1935

Following your implementation you're making a register view requests w/o the existence checks which makes it hard to tell if the 409 came from table or view.

Copy link
Copy Markdown
Member Author

@ebyhr ebyhr Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if here we can catch a TableAlreadyExists if there is a table already registered with the same identifier?

The ViewAlreadyExistsError in the YAML file is just an example. The actual exception type may differ in each REST catalog implementation.

If we want to distinguish between tables and views, we should use self.table_exists instead of relying on an exception-driven approach, as Drew already said.

try:
response.raise_for_status()
except HTTPError as exc:
_handle_non_200_response(exc, {409: ViewAlreadyExistsError})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, this behavior is seen in the java impl:

https://github.com/apache/iceberg/blob/b0f022ff29945fe70f51485a1f1cda3d35eed8ca/core/src/main/java/org/apache/iceberg/view/BaseMetastoreViewCatalog.java#L310-L316

This is also what the rest spec defines

https://github.com/apache/iceberg/blob/b0f022ff29945fe70f51485a1f1cda3d35eed8ca/open-api/rest-catalog-open-api.yaml#L1927-L1935

Following your implementation you're making a register view requests w/o the existence checks which makes it hard to tell if the 409 came from table or view.

Comment thread pyiceberg/catalog/rest/__init__.py Outdated
@retry(**_RETRY_ARGS)
def register_view(self, identifier: str | Identifier, metadata_location: str) -> View:
self._check_endpoint(Capability.V1_REGISTER_VIEW)
namespace_and_view = self._split_identifier_for_path(identifier)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._split_identifier_for_path(identifier, IdentifierKind.VIEW) here?

Then you can do:

namespace_and_view = self._split_identifier_for_path(identifier, IdentifierKind.VIEW)
request = RegisterViewRequest(name=namespace_and_view["view"], metadata_location=metadata_location)

Comment thread tests/catalog/test_rest.py Outdated
identifier=("default", "registered_view"),
metadata=ViewMetadata(**example_view_metadata_rest_json["metadata"]),
)
assert actual.metadata.model_dump() == expected.metadata.model_dump()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can follow the test from test_create_view_200 and just do a assert actual == expected since the __eq__ already passes

@rambleraptor
Copy link
Copy Markdown
Contributor

Does the REST fixture support register_view? An integration test on this would be great.

@ebyhr
Copy link
Copy Markdown
Member Author

ebyhr commented Apr 28, 2026

@rambleraptor No, the current test target 1.10.x doesn't support the endpoint.

@ebyhr ebyhr force-pushed the ebi/register_view branch 2 times, most recently from cd7d26a to f389b33 Compare April 28, 2026 02:57
@ebyhr ebyhr force-pushed the ebi/register_view branch from f389b33 to af7a73c Compare April 28, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants