-
Notifications
You must be signed in to change notification settings - Fork 414
Fix decimal physicial type mapping #1839
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
Fix decimal physicial type mapping #1839
Conversation
|
Hi @kevinjqliu @Fokko
|
Fokko
left a comment
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.
Thanks @redpheonixx for working on this! 🙌 I think we're very close, I left one comment to simplify it a bit further. Let me know what you think!
pyiceberg/io/pyarrow.py
Outdated
| precision = stats_col.iceberg_type.precision | ||
| scale = stats_col.iceberg_type.scale | ||
| decimal_type = pa.decimal128(precision, scale) | ||
| col_aggs[field_id].update_min( | ||
| pa.array([Decimal(statistics.min_raw) / (10**scale)], decimal_type)[0].as_py() | ||
| ) | ||
| col_aggs[field_id].update_max( | ||
| pa.array([Decimal(statistics.max_raw) / (10**scale)], decimal_type)[0].as_py() | ||
| ) |
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 think we can simplify this into:
| precision = stats_col.iceberg_type.precision | |
| scale = stats_col.iceberg_type.scale | |
| decimal_type = pa.decimal128(precision, scale) | |
| col_aggs[field_id].update_min( | |
| pa.array([Decimal(statistics.min_raw) / (10**scale)], decimal_type)[0].as_py() | |
| ) | |
| col_aggs[field_id].update_max( | |
| pa.array([Decimal(statistics.max_raw) / (10**scale)], decimal_type)[0].as_py() | |
| ) | |
| scale = stats_col.iceberg_type.scale | |
| col_aggs[field_id].update_min(unscaled_to_decimal(statistics.min_raw, scale)) | |
| col_aggs[field_id].update_max(unscaled_to_decimal(statistics.max_raw, scale)) |
We already have the unscale_to_decimal that we can import from pyiceberg.utils.decimal.
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.
Hi @Fokko ,
thanks for the comment
I have updated the code and used unscale_to_decimal now
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.
Thanks, that looks great 👍
|
Thanks for fixing this @redpheonixx 🙌 |
This pull request addresses the handling of decimal physical type matching in Parquet. It implements rules such that: For precision ≤ 9, values are stored as `int32`. For precision ≤ 18, values are stored as `int64`. For higher precision, values are stored as a `FIXED_LEN_BYTE_ARRAY`. Closes #1789 --------- Co-authored-by: redpheonixx <amitsingh@192.168.1.5> Co-authored-by: redpheonixx <amitsingh@192.168.1.10>
This pull request addresses the handling of decimal physical type matching in Parquet. It implements rules such that: For precision ≤ 9, values are stored as `int32`. For precision ≤ 18, values are stored as `int64`. For higher precision, values are stored as a `FIXED_LEN_BYTE_ARRAY`. Closes apache#1789 --------- Co-authored-by: redpheonixx <amitsingh@192.168.1.5> Co-authored-by: redpheonixx <amitsingh@192.168.1.10>
<!--
Thanks for opening a pull request!
-->
<!-- In the case this PR will resolve an issue, please replace
${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
<!-- Closes #${GITHUB_ISSUE_ID} -->
# Rationale for this change
Fix for #2057. It looks
like the initial fix #1839
might have missed updating here to handle. I could use feedback on if
this is the best fix, it is at least simple.
## Are these changes tested?
- [x] added unit tests
## Are there any user-facing changes?
No
<!-- In the case of user-facing changes, please add the changelog label.
-->
This pull request addresses the handling of decimal physical type matching in Parquet. It implements rules such that:
For precision ≤ 9, values are stored as
int32.For precision ≤ 18, values are stored as
int64.For higher precision, values are stored as a
FIXED_LEN_BYTE_ARRAY.Closes #1789