-
Notifications
You must be signed in to change notification settings - Fork 414
handle decimal physicial type mapping #1799
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 |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ | |
| StringType, | ||
| ) | ||
| from pyiceberg.utils.datetime import date_to_days, datetime_to_micros, time_to_micros | ||
|
|
||
| from decimal import Decimal | ||
|
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. i think we should use pyarrow.decimal128 instead
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. Hi @kevinjqliu , |
||
|
|
||
| @dataclass(frozen=True) | ||
| class TestStruct: | ||
|
|
@@ -446,6 +446,9 @@ def construct_test_table_primitive_types() -> Tuple[pq.FileMetaData, Union[Table | |
| {"id": 10, "name": "strings", "required": False, "type": "string"}, | ||
| {"id": 11, "name": "uuids", "required": False, "type": "uuid"}, | ||
| {"id": 12, "name": "binaries", "required": False, "type": "binary"}, | ||
| {"id": 13, "name": "decimal8", "required": False, "type": "decimal(8, 2)"}, | ||
| {"id": 14, "name": "decimal16", "required": False, "type": "decimal(16, 6)"}, | ||
| {"id": 15, "name": "decimal32", "required": False, "type": "decimal(20, 6)"}, | ||
| ], | ||
| }, | ||
| ], | ||
|
|
@@ -470,6 +473,9 @@ def construct_test_table_primitive_types() -> Tuple[pq.FileMetaData, Union[Table | |
| strings = ["hello", "world"] | ||
| uuids = [uuid.uuid3(uuid.NAMESPACE_DNS, "foo").bytes, uuid.uuid3(uuid.NAMESPACE_DNS, "bar").bytes] | ||
| binaries = [b"hello", b"world"] | ||
| decimal8 = [Decimal("123.45"), Decimal("678.91")] | ||
| decimal16 = [Decimal("123456789.123456"), Decimal("678912345.678912")] | ||
| decimal32 = [Decimal("12345678901234.123456"), Decimal("98765432109870.654321")] | ||
|
Comment on lines
+476
to
+478
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. these should use the proper precision for decimal128
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.
@kevinjqliu pls check if we can go with this as this have now proper precision and scale |
||
|
|
||
| table = pa.Table.from_pydict( | ||
| { | ||
|
|
@@ -485,14 +491,17 @@ def construct_test_table_primitive_types() -> Tuple[pq.FileMetaData, Union[Table | |
| "strings": strings, | ||
| "uuids": uuids, | ||
| "binaries": binaries, | ||
| "decimal8": decimal8, | ||
| "decimal16": decimal16, | ||
| "decimal32": decimal32, | ||
| }, | ||
| schema=arrow_schema, | ||
| ) | ||
|
|
||
| metadata_collector: List[Any] = [] | ||
|
|
||
| with pa.BufferOutputStream() as f: | ||
| with pq.ParquetWriter(f, table.schema, metadata_collector=metadata_collector) as writer: | ||
| with pq.ParquetWriter(f, table.schema, metadata_collector=metadata_collector, store_decimal_as_integer=True) as writer: | ||
|
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. do we need
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. I tried without this parameter but then the physical type for decimal(8, 2) will be FIXED_LEN_BYTE_ARRAY. There is a check for this as below |
||
| writer.write_table(table) | ||
|
|
||
| return metadata_collector[0], table_metadata | ||
|
|
@@ -510,13 +519,13 @@ def test_metrics_primitive_types() -> None: | |
| ) | ||
| datafile = DataFile(**statistics.to_serialized_dict()) | ||
|
|
||
| assert len(datafile.value_counts) == 12 | ||
| assert len(datafile.null_value_counts) == 12 | ||
| assert len(datafile.value_counts) == 15 | ||
| assert len(datafile.null_value_counts) == 15 | ||
| assert len(datafile.nan_value_counts) == 0 | ||
|
|
||
| tz = timezone(timedelta(seconds=19800)) | ||
|
|
||
| assert len(datafile.lower_bounds) == 12 | ||
| assert len(datafile.lower_bounds) == 15 | ||
| assert datafile.lower_bounds[1] == STRUCT_BOOL.pack(False) | ||
| assert datafile.lower_bounds[2] == STRUCT_INT32.pack(23) | ||
| assert datafile.lower_bounds[3] == STRUCT_INT64.pack(2) | ||
|
|
@@ -529,8 +538,12 @@ def test_metrics_primitive_types() -> None: | |
| assert datafile.lower_bounds[10] == b"he" | ||
| assert datafile.lower_bounds[11] == uuid.uuid3(uuid.NAMESPACE_DNS, "foo").bytes | ||
| assert datafile.lower_bounds[12] == b"he" | ||
| assert int.from_bytes(datafile.lower_bounds[13], byteorder="big", signed=True) == int(12345) | ||
| assert int.from_bytes(datafile.lower_bounds[14], byteorder="big", signed=True) == int(123456789123456) | ||
| assert int.from_bytes(datafile.lower_bounds[15], byteorder="big", signed=True) == int(12345678901234123456) | ||
|
Comment on lines
+541
to
+543
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. we should test the physical type, such as
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. This I am updating as below |
||
|
|
||
|
|
||
| assert len(datafile.upper_bounds) == 12 | ||
| assert len(datafile.upper_bounds) == 15 | ||
| assert datafile.upper_bounds[1] == STRUCT_BOOL.pack(True) | ||
| assert datafile.upper_bounds[2] == STRUCT_INT32.pack(89) | ||
| assert datafile.upper_bounds[3] == STRUCT_INT64.pack(54) | ||
|
|
@@ -543,6 +556,9 @@ def test_metrics_primitive_types() -> None: | |
| assert datafile.upper_bounds[10] == b"wp" | ||
| assert datafile.upper_bounds[11] == uuid.uuid3(uuid.NAMESPACE_DNS, "bar").bytes | ||
| assert datafile.upper_bounds[12] == b"wp" | ||
| assert int.from_bytes(datafile.upper_bounds[13], byteorder="big", signed=True) == int(67891) | ||
| assert int.from_bytes(datafile.upper_bounds[14], byteorder="big", signed=True) == int(678912345678912) | ||
| assert int.from_bytes(datafile.upper_bounds[15], byteorder="big", signed=True) == int(98765432109870654321) | ||
|
|
||
|
|
||
| def construct_test_table_invalid_upper_bound() -> Tuple[pq.FileMetaData, Union[TableMetadataV1, TableMetadataV2]]: | ||
|
|
||
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.
im confused why we need to use the regex here
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.
When we
isinstanceofthestats_col.iceberg_Typeas aDecimalType, then we have access to thescaleandprecision.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 have updated above as below