redpheonixx commented on code in PR #1799:
URL: https://github.com/apache/iceberg-python/pull/1799#discussion_r2001296080


##########
pyiceberg/io/pyarrow.py:
##########
@@ -2335,9 +2340,18 @@ def data_file_statistics_from_parquet_metadata(
                         col_aggs[field_id] = StatsAggregator(
                             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)
+                    matches=DECIMAL_REGEX.search(str(stats_col.iceberg_type))
+                    if matches and statistics.physical_type != 
"FIXED_LEN_BYTE_ARRAY":
+                        precision=int(matches.group(1))
+                        scale=int(matches.group(2))
+                        local_context = Context(prec=precision)
+                        decoded_min = 
local_context.create_decimal(Decimal(statistics.min_raw)/ (10 ** scale))
+                        decoded_max = 
local_context.create_decimal(Decimal(statistics.max_raw)/ (10 ** scale))
+                        col_aggs[field_id].update_min(decoded_min)
+                        col_aggs[field_id].update_max(decoded_max)
+                    else:
+                        col_aggs[field_id].update_min(statistics.min)
+                        col_aggs[field_id].update_max(statistics.max)

Review Comment:
   I have updated above  as below
   ```
   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())
                       else:
                           col_aggs[field_id].update_min(statistics.min)
                           col_aggs[field_id].update_max(statistics.max)
   ```
   



-- 
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-unsubscr...@iceberg.apache.org

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


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

Reply via email to