gedaliakliger opened a new pull request, #4420: URL: https://github.com/apache/iceberg-python/pull/4420
# Rationale for this change `to_json` for a `DecimalType` returns `str(val)`, and Python renders a small `Decimal` in scientific notation. A `decimal(20, 8)` column with a default of zero gets `"initial-default": "0E-8"` in the table metadata, and `0.00000010` becomes `1.0E-7`. The spec's [JSON single-value serialization](https://iceberg.apache.org/spec/#json-single-value-serialization) uses the number of digits to the right of the decimal point to indicate a positive scale, and keeps scientific notation for negative scales. Java's `SingleValueParser.toJson` does the same: `toPlainString()` when `scale() >= 0`, otherwise `toString()`. This writes the plain form when the exponent is zero or negative and leaves the other cases as they are. ## Are these changes tested? Three new cases in `test_json_single_serialization` (`tests/test_conversions.py`). They fail on `main` (`0E-8`, `-1.2E-7`, `1E-18`) and pass with this change. Ran locally: `pytest tests/test_conversions.py tests/test_types.py -m unit`, and `prek run ruff ruff-format mypy` on the two changed files. The full unit and integration suites are left to CI. ## Are there any user-facing changes? Decimal `initial-default` and `write-default` values with a small magnitude are written in plain notation. Metadata that already holds the scientific form still reads. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
