-
Notifications
You must be signed in to change notification settings - Fork 270
Allow non-string typed values in table properties #469
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
Fokko
merged 6 commits into
apache:main
from
kevinjqliu:kevinjqliu/property-value-coerce-to-string
Feb 29, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import pytest | ||
import pytz | ||
from pyarrow.fs import S3FileSystem | ||
from pydantic_core import ValidationError | ||
from pyspark.sql import SparkSession | ||
from pytest_mock.plugin import MockerFixture | ||
|
||
|
@@ -403,7 +404,7 @@ def test_data_files(spark: SparkSession, session_catalog: Catalog, arrow_table_w | |
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize("format_version", ["1", "2"]) | ||
@pytest.mark.parametrize("format_version", [1, 2]) | ||
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. Nice :) |
||
@pytest.mark.parametrize( | ||
"properties, expected_compression_name", | ||
[ | ||
|
@@ -419,7 +420,7 @@ def test_write_parquet_compression_properties( | |
spark: SparkSession, | ||
session_catalog: Catalog, | ||
arrow_table_with_null: pa.Table, | ||
format_version: str, | ||
format_version: int, | ||
properties: Dict[str, Any], | ||
expected_compression_name: str, | ||
) -> None: | ||
|
@@ -654,3 +655,37 @@ def test_write_and_evolve(session_catalog: Catalog, format_version: int) -> None | |
with txn.update_snapshot().fast_append() as snapshot_update: | ||
for data_file in _dataframe_to_data_files(table_metadata=txn.table_metadata, df=pa_table_with_column, io=tbl.io): | ||
snapshot_update.append_data_file(data_file) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize("format_version", [1, 2]) | ||
def test_table_properties_int_value( | ||
session_catalog: Catalog, | ||
arrow_table_with_null: pa.Table, | ||
format_version: int, | ||
) -> None: | ||
# table properties can be set to int, but still serialized to string | ||
property_with_int = {"property_name": 42} | ||
identifier = "default.test_table_properties_int_value" | ||
|
||
tbl = _create_table( | ||
session_catalog, identifier, {"format-version": format_version, **property_with_int}, [arrow_table_with_null] | ||
) | ||
assert isinstance(tbl.properties["property_name"], str) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize("format_version", [1, 2]) | ||
def test_table_properties_raise_for_none_value( | ||
session_catalog: Catalog, | ||
arrow_table_with_null: pa.Table, | ||
format_version: int, | ||
) -> None: | ||
property_with_none = {"property_name": None} | ||
identifier = "default.test_table_properties_raise_for_none_value" | ||
|
||
with pytest.raises(ValidationError) as exc_info: | ||
_ = _create_table( | ||
session_catalog, identifier, {"format-version": format_version, **property_with_none}, [arrow_table_with_null] | ||
) | ||
assert "None type is not a supported value in properties: property_name" in str(exc_info.value) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect an exception being thrown by the field validator, instead of Pydantic itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Pydantic catches the underlying error and reraise a ValidationError
from the docs,
"""
Pydantic will raise a ValidationError whenever it finds an error in the data it's validating.
Note
Validation code should not raise ValidationError itself, but rather raise a ValueError or AssertionError (or subclass thereof) which will be caught and used to populate ValidationError.
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I wasn't aware of that. Looks like
ValidationError
extendsValueError
, so we're good here. Thanks!