-
Notifications
You must be signed in to change notification settings - Fork 358
Improve LocationProvider
unit tests
#1511
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 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 |
---|---|---|
|
@@ -38,12 +38,18 @@ def new_data_location(self, data_file_name: str, partition_key: Optional[Partiti | |
return f"custom_location_provider/{data_file_name}" | ||
|
||
|
||
def test_default_location_provider() -> None: | ||
def test_simple_location_provider_no_partition() -> None: | ||
provider = load_location_provider(table_location="table_location", table_properties={"write.object-storage.enabled": "false"}) | ||
|
||
assert provider.new_data_location("my_file") == "table_location/data/my_file" | ||
|
||
|
||
def test_simple_location_provider_with_partition() -> None: | ||
provider = load_location_provider(table_location="table_location", table_properties={"write.object-storage.enabled": "false"}) | ||
|
||
assert provider.new_data_location("my_file", PARTITION_KEY) == "table_location/data/string_field=example_string/my_file" | ||
|
||
|
||
def test_custom_location_provider() -> None: | ||
qualified_name = CustomLocationProvider.__module__ + "." + CustomLocationProvider.__name__ | ||
provider = load_location_provider( | ||
|
@@ -65,7 +71,7 @@ def test_custom_location_provider_not_found() -> None: | |
) | ||
|
||
|
||
def test_object_storage_injects_entropy() -> None: | ||
def test_object_storage_no_partition() -> None: | ||
provider = load_location_provider(table_location="table_location", table_properties=EMPTY_DICT) | ||
|
||
location = provider.new_data_location("test.parquet") | ||
|
@@ -82,19 +88,18 @@ def test_object_storage_injects_entropy() -> None: | |
assert all(c in "01" for c in dir_name) | ||
|
||
|
||
@pytest.mark.parametrize("object_storage", [True, False]) | ||
def test_partition_value_in_path(object_storage: bool) -> None: | ||
def test_object_storage_with_partition() -> None: | ||
provider = load_location_provider( | ||
table_location="table_location", | ||
table_properties={ | ||
"write.object-storage.enabled": str(object_storage), | ||
}, | ||
table_properties={"write.object-storage.enabled": "true"}, | ||
) | ||
|
||
location = provider.new_data_location("test.parquet", PARTITION_KEY) | ||
partition_segment = location.split("/")[-2] | ||
|
||
assert partition_segment == "string_field=example_string" | ||
# Partition values AND entropy included in the path. Entropy differs to that in the test below because the partition | ||
# key AND the data file name are used as the hash input. This matches Java behaviour; the hash below is what the | ||
# Java implementation produces for this input too. | ||
Comment on lines
+100
to
+101
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. I've verified this. There's no test of this in https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/TestLocationProvider.java that we can take the hash from sadly. I like testing this here. It's not obvious that both partition key and file name are used as hash input. |
||
assert location == "table_location/data/0001/0010/1001/00000011/string_field=example_string/test.parquet" | ||
|
||
|
||
# NB: We test here with None partition key too because disabling partitioned paths still replaces final / with - even in | ||
|
Uh oh!
There was an error while loading. Please reload this page.