-
Notifications
You must be signed in to change notification settings - Fork 525
Hive metastore register table #1580
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
Changes from 4 commits
25beeb2
5cedb9a
e8f1c9c
b6b864a
b912fc7
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,116 @@ | ||||||||||||||||||||||||||||||||
| # 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 pytest | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| from pyiceberg.catalog import Catalog | ||||||||||||||||||||||||||||||||
| from pyiceberg.catalog.hive import ( | ||||||||||||||||||||||||||||||||
| HiveCatalog, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| from pyiceberg.exceptions import NoSuchTableError, TableAlreadyExistsError | ||||||||||||||||||||||||||||||||
| from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec | ||||||||||||||||||||||||||||||||
| from pyiceberg.schema import Schema | ||||||||||||||||||||||||||||||||
| from pyiceberg.table import Table | ||||||||||||||||||||||||||||||||
| from pyiceberg.types import ( | ||||||||||||||||||||||||||||||||
| BooleanType, | ||||||||||||||||||||||||||||||||
| DateType, | ||||||||||||||||||||||||||||||||
| IntegerType, | ||||||||||||||||||||||||||||||||
| NestedField, | ||||||||||||||||||||||||||||||||
| StringType, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| TABLE_SCHEMA = Schema( | ||||||||||||||||||||||||||||||||
| NestedField(field_id=1, name="foo", field_type=BooleanType(), required=False), | ||||||||||||||||||||||||||||||||
| NestedField(field_id=2, name="bar", field_type=StringType(), required=False), | ||||||||||||||||||||||||||||||||
| NestedField(field_id=4, name="baz", field_type=IntegerType(), required=False), | ||||||||||||||||||||||||||||||||
| NestedField(field_id=10, name="qux", field_type=DateType(), required=False), | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _create_table( | ||||||||||||||||||||||||||||||||
| session_catalog: Catalog, | ||||||||||||||||||||||||||||||||
| identifier: str, | ||||||||||||||||||||||||||||||||
| format_version: int, | ||||||||||||||||||||||||||||||||
| location: str, | ||||||||||||||||||||||||||||||||
| partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, | ||||||||||||||||||||||||||||||||
| schema: Schema = TABLE_SCHEMA, | ||||||||||||||||||||||||||||||||
| ) -> Table: | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| session_catalog.drop_table(identifier=identifier) | ||||||||||||||||||||||||||||||||
| except NoSuchTableError: | ||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return session_catalog.create_table( | ||||||||||||||||||||||||||||||||
| identifier=identifier, | ||||||||||||||||||||||||||||||||
| schema=schema, | ||||||||||||||||||||||||||||||||
| location=location, | ||||||||||||||||||||||||||||||||
| properties={"format-version": str(format_version)}, | ||||||||||||||||||||||||||||||||
| partition_spec=partition_spec, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @pytest.mark.integration | ||||||||||||||||||||||||||||||||
| def test_hive_register_table( | ||||||||||||||||||||||||||||||||
| session_catalog: HiveCatalog, | ||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+66
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. Thanks @JoniKet This is looking great, thanks for changing these tests 👍 The
Suggested change
It would be even better to test both:
Suggested change
This will run the test twice, once for the
Contributor
Author
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. Added a commit where the catalog is parametrised for the unit test. Cool, did not know it is possible to parametrise fixture that way with pytest |
||||||||||||||||||||||||||||||||
| identifier = "default.hive_register_table" | ||||||||||||||||||||||||||||||||
| location = "s3a://warehouse/default/hive_register_table" | ||||||||||||||||||||||||||||||||
| tbl = _create_table(session_catalog, identifier, 2, location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| session_catalog.drop_table(identifier=identifier) | ||||||||||||||||||||||||||||||||
| assert not session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| session_catalog.register_table(("default", "hive_register_table"), metadata_location=tbl.metadata_location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @pytest.mark.integration | ||||||||||||||||||||||||||||||||
| def test_hive_register_table_existing( | ||||||||||||||||||||||||||||||||
| session_catalog: HiveCatalog, | ||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||
| identifier = "default.hive_register_table_existing" | ||||||||||||||||||||||||||||||||
| location = "s3a://warehouse/default/hive_register_table_existing" | ||||||||||||||||||||||||||||||||
| tbl = _create_table(session_catalog, identifier, 2, location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| # Assert that registering the table again raises TableAlreadyExistsError | ||||||||||||||||||||||||||||||||
| with pytest.raises(TableAlreadyExistsError): | ||||||||||||||||||||||||||||||||
| session_catalog.register_table(("default", "hive_register_table_existing"), metadata_location=tbl.metadata_location) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @pytest.mark.integration | ||||||||||||||||||||||||||||||||
| def test_rest_register_table( | ||||||||||||||||||||||||||||||||
| session_catalog: Catalog, | ||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||
| identifier = "default.rest_register_table" | ||||||||||||||||||||||||||||||||
| location = "s3a://warehouse/default/rest_register_table" | ||||||||||||||||||||||||||||||||
| tbl = _create_table(session_catalog, identifier, 2, location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| session_catalog.drop_table(identifier=identifier) | ||||||||||||||||||||||||||||||||
| assert not session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| session_catalog.register_table(identifier=identifier, metadata_location=tbl.metadata_location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @pytest.mark.integration | ||||||||||||||||||||||||||||||||
| def test_rest_register_table_existing( | ||||||||||||||||||||||||||||||||
| session_catalog: Catalog, | ||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||
| identifier = "default.rest_register_table_existing" | ||||||||||||||||||||||||||||||||
| location = "s3a://warehouse/default/rest_register_table_existing" | ||||||||||||||||||||||||||||||||
| tbl = _create_table(session_catalog, identifier, 2, location) | ||||||||||||||||||||||||||||||||
| assert session_catalog.table_exists(identifier=identifier) | ||||||||||||||||||||||||||||||||
| # Assert that registering the table again raises TableAlreadyExistsError | ||||||||||||||||||||||||||||||||
| with pytest.raises(TableAlreadyExistsError): | ||||||||||||||||||||||||||||||||
| session_catalog.register_table(identifier=identifier, metadata_location=tbl.metadata_location) | ||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.