You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "redpheonixx (via GitHub)" <gi...@apache.org> on 2025/03/24 16:58:59 UTC

[PR] decimal physicial type mapping [iceberg-python]

redpheonixx opened a new pull request, #1839:
URL: https://github.com/apache/iceberg-python/pull/1839

   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`.
   
   This pull request is associated with issue #1789 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Fix decimal physicial type mapping [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839#issuecomment-2766266153

   Thanks for fixing this @redpheonixx 🙌 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] decimal physicial type mapping [iceberg-python]

Posted by "redpheonixx (via GitHub)" <gi...@apache.org>.
redpheonixx commented on PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839#issuecomment-2748836848

   Hi @kevinjqliu @Fokko 
   I have updated the code as per previous PR #1799  comments
   please note that
   
   1. We need Decimal as to create pa.array of decimal 128 type it accepts only integer and decimal values and not float values. 
   2. I tried without this parameter `store_decimal_as_integer=True` (ParquetWriter) but then the physical type for decimal(5, 2) will be FIXED_LEN_BYTE_ARRAY. 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] decimal physicial type mapping [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839#discussion_r2021041283


##########
pyiceberg/io/pyarrow.py:
##########
@@ -2350,8 +2351,19 @@ def data_file_statistics_from_parquet_metadata(
                             stats_col.iceberg_type, statistics.physical_type, stats_col.mode.length
                         )
 
-                    col_aggs[field_id].update_min(statistics.min)
-                    col_aggs[field_id].update_max(statistics.max)
+                    if isinstance(stats_col.iceberg_type, DecimalType) and statistics.physical_type != "FIXED_LEN_BYTE_ARRAY":
+                        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()
+                        )

Review Comment:
   Thanks, that looks great 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Fix decimal physicial type mapping [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] decimal physicial type mapping [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839#discussion_r2020991374


##########
pyiceberg/io/pyarrow.py:
##########
@@ -2350,8 +2351,19 @@ def data_file_statistics_from_parquet_metadata(
                             stats_col.iceberg_type, statistics.physical_type, stats_col.mode.length
                         )
 
-                    col_aggs[field_id].update_min(statistics.min)
-                    col_aggs[field_id].update_max(statistics.max)
+                    if isinstance(stats_col.iceberg_type, DecimalType) and statistics.physical_type != "FIXED_LEN_BYTE_ARRAY":
+                        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()
+                        )

Review Comment:
   I think we can simplify this into:
   ```suggestion
                           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`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] decimal physicial type mapping [iceberg-python]

Posted by "redpheonixx (via GitHub)" <gi...@apache.org>.
redpheonixx commented on code in PR #1839:
URL: https://github.com/apache/iceberg-python/pull/1839#discussion_r2021037350


##########
pyiceberg/io/pyarrow.py:
##########
@@ -2350,8 +2351,19 @@ def data_file_statistics_from_parquet_metadata(
                             stats_col.iceberg_type, statistics.physical_type, stats_col.mode.length
                         )
 
-                    col_aggs[field_id].update_min(statistics.min)
-                    col_aggs[field_id].update_max(statistics.max)
+                    if isinstance(stats_col.iceberg_type, DecimalType) and statistics.physical_type != "FIXED_LEN_BYTE_ARRAY":
+                        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()
+                        )

Review Comment:
   Hi @Fokko , 
   thanks for the comment
   I have updated the code and used unscale_to_decimal now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org