[ https://issues.apache.org/jira/browse/AVRO-2620?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ryan Skraba updated AVRO-2620: ------------------------------ Description: A decimal logical type with an underlying fixed bytes type is invalid if the precision is greater than can be contained in the fixed bytes. The calculation for [max precision|https://github.com/apache/avro/blob/a2098bd88361b5ff9298c462a2dccafbb0c2c508/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java#L262] can return a wrong value when the fixed bytes size is greater than 128. For a fixed size of *129*, the {{Math.pow(2, 8 * size - 1)}} part of this formula will return {{Double.INFINITY}}, and the max precision will be considered {{Long.MAX_VALUE}}. The expected value is 310 digits precision. We can apply the log power rule to avoid overflow, or some bit-twiddling approximation (like [java.math.BigDecimal|https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/math/BigDecimal.java#L3779]. was: A decimal logical type with an underlying fixed bytes type is invalid if the precision is greater than can be contained in the fixed bytes. The calculation for [max precision|https://github.com/apache/avro/blob/a2098bd88361b5ff9298c462a2dccafbb0c2c508/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java#L262] can return a wrong value when the fixed bytes size is greater than 128. For a fixed size of *129*, the `Math.pow(2, 8 * size - 1)` part of this formula will return `Double.INFINITY`, and the max precision will be considered `Long.MAX_VALUE`. The expected value is 310 digits precision. We can apply the log power rule to avoid overflow, or some bit-twiddling approximation (like [java.math.BigDecimal|https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/math/BigDecimal.java#L3779]. > Max precision on decimal/fixed LogicalType is wrong > --------------------------------------------------- > > Key: AVRO-2620 > URL: https://issues.apache.org/jira/browse/AVRO-2620 > Project: Apache Avro > Issue Type: Bug > Components: java > Reporter: Ryan Skraba > Priority: Minor > > A decimal logical type with an underlying fixed bytes type is invalid if the > precision is greater than can be contained in the fixed bytes. The > calculation for > [max > precision|https://github.com/apache/avro/blob/a2098bd88361b5ff9298c462a2dccafbb0c2c508/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java#L262] > can return a wrong value when the fixed bytes size is greater than 128. > For a fixed size of *129*, the {{Math.pow(2, 8 * size - 1)}} part of this > formula will return {{Double.INFINITY}}, and the max precision will be > considered {{Long.MAX_VALUE}}. The expected value is 310 digits precision. > We can apply the log power rule to avoid overflow, or some bit-twiddling > approximation (like > [java.math.BigDecimal|https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/math/BigDecimal.java#L3779]. -- This message was sent by Atlassian Jira (v8.3.4#803005)