Skip to content
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

Hive metastore register table #1580

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

JoniKet
Copy link
Contributor

@JoniKet JoniKet commented Jan 27, 2025

Added the register_table operation for Hive metastore. Had use case where there were existing tables in AWS S3, which needed to be registered to Hive metastore. Registering table with PyIceberg was not possible yet in Hive metastore.

Testing

Tested with the attached unit tests and also against remote hive metastore leveraging PyIceberg.

@@ -204,6 +204,87 @@ def test_check_number_of_namespaces(table_schema_simple: Schema) -> None:
catalog.create_table("table", schema=table_schema_simple)


@pytest.mark.parametrize("hive2_compatible", [True, False])
@patch("time.time", MagicMock(return_value=12345))
def test_register_table(
Copy link
Contributor

Choose a reason for hiding this comment

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

How would you feel about moving this test to tests/integration/test_register_table.py? We can do a test both for Hive and the Rest catalog. The big upside here is that we don't have to mock everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Integration test against real local Hivemetastore is better, I'll try to implement this. Did not notice the great integration test coverage before.

Comment on lines 65 to 68
@pytest.mark.integration
def test_hive_register_table(
session_catalog: HiveCatalog,
) -> None:
Copy link
Contributor

@Fokko Fokko Jan 30, 2025

Choose a reason for hiding this comment

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

Thanks @JoniKet This is looking great, thanks for changing these tests 👍

The session_catalog is a RestCatalog, instead you want to use:

Suggested change
@pytest.mark.integration
def test_hive_register_table(
session_catalog: HiveCatalog,
) -> None:
@pytest.mark.integration
def test_hive_register_table(
session_catalog_hive: HiveCatalog,
) -> None:

It would be even better to test both:

Suggested change
@pytest.mark.integration
def test_hive_register_table(
session_catalog: HiveCatalog,
) -> None:
@pytest.mark.integration
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])
def test_hive_register_table(catalog: Catalog) -> None:

This will run the test twice, once for the RestCatalog, and once for the HiveCatalog. This way we don't have to duplicate the tests for each of the catalog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM

@kevinjqliu kevinjqliu requested a review from Fokko January 31, 2025 23:57
@kevinjqliu kevinjqliu added this to the PyIceberg 0.9.0 release milestone Feb 1, 2025
Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

Perfect, thanks @JoniKet for adding this, and thanks @kevinjqliu for the reviews! 🚀

@Fokko Fokko merged commit 5018efc into apache:main Feb 3, 2025
7 checks passed
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.

3 participants