-
Notifications
You must be signed in to change notification settings - Fork 485
Write small decimals as INTs #1983
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 4 commits
c2eec90
ea22749
e5c41c7
24fb388
ca845bd
963a599
8ededbf
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 |
|---|---|---|
|
|
@@ -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) | ||
| ) | ||
|
|
||
| def visit_boolean(self, _: BooleanType) -> pa.DataType: | ||
| return pa.bool_() | ||
|
|
@@ -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 | ||
|
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. """
from https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetWriter.html
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. this matches the parquet data type mapping for decimal |
||
| ) as writer: | ||
| writer.write(arrow_table, row_group_size=row_group_size) | ||
| statistics = data_file_statistics_from_parquet_metadata( | ||
| parquet_metadata=writer.writer.metadata, | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.