You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Fokko (via GitHub)" <gi...@apache.org> on 2025/05/08 09:52:42 UTC
[PR] Write small decimals as INTs [iceberg-python]
Fokko opened a new pull request, #1983:
URL: https://github.com/apache/iceberg-python/pull/1983
# Rationale for this change
Resolves https://github.com/apache/iceberg-python/issues/1979
# Are these changes tested?
# Are there any user-facing changes?
<!-- In the case of user-facing changes, please add the changelog label. -->
--
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] Write small decimals as INTs [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu merged PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983
--
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] Write small decimals as INTs [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983#issuecomment-2869148157
@kevinjqliu Good call, looking at the code, it seems like it will automatically map it to INT32/INT64: https://github.com/apache/arrow/blob/598938711a8376cbfdceaf5c77ab0fd5057e6c02/cpp/src/parquet/arrow/schema.cc#L380-L392
--
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] Write small decimals as INTs [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983#discussion_r2083285244
##########
pyiceberg/io/pyarrow.py:
##########
@@ -636,7 +636,13 @@ def visit_fixed(self, fixed_type: FixedType) -> pa.DataType:
return pa.binary(len(fixed_type))
def visit_decimal(self, decimal_type: DecimalType) -> pa.DataType:
- return pa.decimal128(decimal_type.precision, decimal_type.scale)
+ return (
+ pa.decimal32(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 9
+ else pa.decimal64(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 18
+ else pa.decimal128(decimal_type.precision, decimal_type.scale)
Review Comment:
Thanks for checking. This inspired me to change the code to throw on precision >38.
--
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] Write small decimals as INTs [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983#issuecomment-2864053383
CI failing due to the release of snowballstemmer: https://pypi.org/project/snowballstemmer/#history
--
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] Write small decimals as INTs [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on code in PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983#discussion_r2081953874
##########
pyiceberg/io/pyarrow.py:
##########
@@ -636,7 +636,13 @@ def visit_fixed(self, fixed_type: FixedType) -> pa.DataType:
return pa.binary(len(fixed_type))
def visit_decimal(self, decimal_type: DecimalType) -> pa.DataType:
- return pa.decimal128(decimal_type.precision, decimal_type.scale)
+ return (
+ pa.decimal32(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 9
+ else pa.decimal64(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 18
+ else pa.decimal128(decimal_type.precision, decimal_type.scale)
Review Comment:
"""
Scale is fixed, precision must be 38 or less
"""
from https://iceberg.apache.org/spec/#primitive-types

##########
pyiceberg/io/pyarrow.py:
##########
@@ -2442,7 +2448,9 @@ def write_parquet(task: WriteTask) -> DataFile:
)
fo = io.new_output(file_path)
with fo.create(overwrite=True) as fos:
- with pq.ParquetWriter(fos, schema=arrow_table.schema, **parquet_writer_kwargs) as writer:
+ with pq.ParquetWriter(
+ fos, schema=arrow_table.schema, store_decimal_as_integer=True, **parquet_writer_kwargs
Review Comment:
"""
By default, this is DISABLED and all decimal types annotate fixed_len_byte_array. When enabled, the writer will use the following physical types to store decimals:
- int32: for 1 <= precision <= 9.
- int64: for 10 <= precision <= 18.
- fixed_len_byte_array: for precision > 18.
"""
from https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetWriter.html

##########
pyiceberg/io/pyarrow.py:
##########
@@ -636,7 +636,13 @@ def visit_fixed(self, fixed_type: FixedType) -> pa.DataType:
return pa.binary(len(fixed_type))
def visit_decimal(self, decimal_type: DecimalType) -> pa.DataType:
- return pa.decimal128(decimal_type.precision, decimal_type.scale)
+ return (
+ pa.decimal32(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 9
+ else pa.decimal64(decimal_type.precision, decimal_type.scale)
+ if decimal_type.precision <= 18
+ else pa.decimal128(decimal_type.precision, decimal_type.scale)
Review Comment:
pyarrow.decimal128 supports up to precision 38
https://arrow.apache.org/docs/python/generated/pyarrow.decimal128.html#pyarrow-decimal128
##########
pyiceberg/io/pyarrow.py:
##########
@@ -2442,7 +2448,9 @@ def write_parquet(task: WriteTask) -> DataFile:
)
fo = io.new_output(file_path)
with fo.create(overwrite=True) as fos:
- with pq.ParquetWriter(fos, schema=arrow_table.schema, **parquet_writer_kwargs) as writer:
+ with pq.ParquetWriter(
+ fos, schema=arrow_table.schema, store_decimal_as_integer=True, **parquet_writer_kwargs
Review Comment:
this matches the parquet data type mapping for decimal
https://iceberg.apache.org/spec/#parquet

--
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] Write small decimals as INTs [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on PR #1983:
URL: https://github.com/apache/iceberg-python/pull/1983#issuecomment-2867050506
> FAILED tests/io/test_pyarrow_stats.py::test_metrics_primitive_types - pyarrow.lib.ArrowNotImplementedError: Unhandled type for Arrow to Parquet schema conversion: decimal32(5, 2)
Looks like arrow doesnt have decimal32 support yet
https://github.com/apache/arrow/issues/25483
https://github.com/apache/arrow/issues/43956
--
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