-
Notifications
You must be signed in to change notification settings - Fork 140
fix: Iceberg warehouse path mismatch between Python and Java/Scala catalogs #4409
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14f25ed
init
aglinxinyuan 85ef8d2
add unit test
aglinxinyuan ff672ad
fix fmt
aglinxinyuan cdea138
Merge branch 'main' into xinyuan-fix-python-warehouse
aglinxinyuan 9b63a96
Merge branch 'main' into xinyuan-fix-python-warehouse
aglinxinyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
amber/src/main/python/core/storage/iceberg/test_iceberg_utils_catalog.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # 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. | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from core.storage.iceberg import iceberg_utils | ||
| from core.storage.iceberg.iceberg_utils import create_postgres_catalog | ||
|
|
||
|
|
||
| class TestCreatePostgresCatalog: | ||
| """ | ||
| Regression tests for `create_postgres_catalog`. | ||
|
|
||
| The Scala side (`IcebergUtil.createPostgresCatalog`) initializes the JDBC | ||
| catalog with a plain filesystem warehouse path (no URI scheme). PyIceberg | ||
| persists the `warehouse` property into table metadata, so if the Python | ||
| side registers the catalog with a `file://`-prefixed value, Iceberg tables | ||
| written from Python UDFs become unreadable from the Scala/Java engine | ||
| (and vice versa). These tests pin the Python side to the same plain-path | ||
| convention used on the Scala side. | ||
| """ | ||
|
|
||
| def test_warehouse_is_passed_without_file_scheme(self): | ||
| """`warehouse` must be forwarded as-is, without a `file://` prefix.""" | ||
| warehouse_path = "/tmp/texera/iceberg-warehouse" | ||
|
|
||
| with patch.object(iceberg_utils, "SqlCatalog") as mock_sql_catalog: | ||
| create_postgres_catalog( | ||
| catalog_name="texera_iceberg", | ||
| warehouse_path=warehouse_path, | ||
| uri_without_scheme="localhost:5432/texera_iceberg_catalog", | ||
| username="texera", | ||
| password="password", | ||
| ) | ||
|
|
||
| assert mock_sql_catalog.call_count == 1 | ||
| _, kwargs = mock_sql_catalog.call_args | ||
| assert kwargs["warehouse"] == warehouse_path | ||
| assert not kwargs["warehouse"].startswith("file://") | ||
|
|
||
| def test_windows_style_warehouse_is_passed_verbatim(self): | ||
| """ | ||
| The Scala side strips the Windows drive colon (e.g. `C:/x` -> `C/x`) | ||
| before registering the catalog so PyArrow can parse the path. The | ||
| Python side should forward whatever it receives verbatim, so the two | ||
| runtimes agree on the warehouse string stored in Iceberg metadata. | ||
| """ | ||
| warehouse_path = "C/Users/texera/iceberg-warehouse" | ||
|
|
||
| with patch.object(iceberg_utils, "SqlCatalog") as mock_sql_catalog: | ||
| create_postgres_catalog( | ||
| catalog_name="texera_iceberg", | ||
| warehouse_path=warehouse_path, | ||
| uri_without_scheme="localhost:5432/texera_iceberg_catalog", | ||
| username="texera", | ||
| password="password", | ||
| ) | ||
|
|
||
| _, kwargs = mock_sql_catalog.call_args | ||
| assert kwargs["warehouse"] == warehouse_path | ||
| assert "file://" not in kwargs["warehouse"] | ||
|
|
||
| def test_postgres_uri_is_built_with_pg8000_scheme(self): | ||
| """The JDBC URI should be prefixed with `postgresql+pg8000://` and | ||
| include credentials; nothing about that should bleed into `warehouse`. | ||
| """ | ||
| warehouse_path = "/var/lib/texera/warehouse" | ||
|
|
||
| with patch.object(iceberg_utils, "SqlCatalog") as mock_sql_catalog: | ||
| create_postgres_catalog( | ||
| catalog_name="texera_iceberg", | ||
| warehouse_path=warehouse_path, | ||
| uri_without_scheme="db.internal:5432/texera_iceberg_catalog", | ||
| username="texera", | ||
| password="s3cret", | ||
| ) | ||
|
|
||
| args, kwargs = mock_sql_catalog.call_args | ||
| assert args == ("texera_iceberg",) | ||
| assert kwargs["uri"] == ( | ||
| "postgresql+pg8000://texera:s3cret@db.internal:5432/texera_iceberg_catalog" | ||
| ) | ||
| # And warehouse is still the plain path. | ||
| assert kwargs["warehouse"] == warehouse_path |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.