nacz0 opened a new pull request, #41707:
URL: https://github.com/apache/beam/pull/41707

   fixes #41706
   
   `DecimalCoderImpl` used `Decimal.scaleb()` to build the unscaled integer on 
encode and the value on decode. `scaleb()`
   rounds to the thread's `decimal` context, which has a precision of 28 
significant digits by default. Decimals with
   more digits, such as SQL `NUMERIC(38, s)` values, therefore lost their 
trailing digits without an error, in both
   directions.
   
   The coder now builds the unscaled integer from `value.as_tuple()` and builds 
the decoded value from the integer's
   digits with `-scale` as exponent. Neither step depends on the context.
   
   Compatibility:
   - The wire format is unchanged. For every value the old coder already 
handled exactly, the new code writes identical
     bytes and decodes the old bytes to the identical value. We checked 20,000 
random values of up to 120 digits at
     precisions 5, 28 and 60. The existing base64 encodings in 
`test_decimal_coder` stay the same.
   - `-0` still decodes as `0`, and NaN and infinity still raise, as before.
   
   Tests: `test_decimal_coder_keeps_digits_beyond_context_precision` 
round-trips two 38-digit values, a 61-digit value,
   and positive-exponent values (including a 36-digit one) in both unnested and 
nested mode under precision 28, verifies
   both encode and decode for the 38-digit value against Java's 
`BigDecimalCoder` wire encoding, checks `-0`/`-0.00` and
   non-finite values (`NaN`, `sNaN`, `±Infinity`), and checks encode and decode 
independently across precisions 28 and 60.
   It fails without the change.
   


-- 
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]

Reply via email to