lidavidm commented on code in PR #37731:
URL: https://github.com/apache/arrow/pull/37731#discussion_r1348794675
##########
csharp/src/Apache.Arrow/DecimalUtility.cs:
##########
@@ -52,7 +52,11 @@ internal static decimal GetDecimal(in ArrowBuffer
valueBuffer, int index, int sc
BigInteger integerPart = BigInteger.DivRem(integerValue,
scaleBy, out BigInteger fractionalPart);
if (integerPart > _maxDecimal || integerPart < _minDecimal) //
decimal overflow, not much we can do here - C# needs a BigDecimal
{
- throw new OverflowException($"Value: {integerPart} too big
or too small to be represented as a decimal");
+ throw new OverflowException($"Value: {integerValue} is too
big or too small to be represented as a decimal");
+ }
+ if (fractionalPart > _maxDecimal || fractionalPart <
_minDecimal) // decimal overflow, not much we can do here - C# needs a
BigDecimal
+ {
+ throw new OverflowException($"Value: {integerValue} is too
big or too small to be represented as a decimal");
Review Comment:
The test cases confused me, but looking at it, it's not necessarily about
too big or too small, but rather too precise?
Arrow represents 7.89 in `decimal256(76,38)` as
`789000000000000000000000000000000000000`
integerPart is then `7`
fractionalPart is `89000000000000000000000000000000000000`
and that's just too many digits of precision for `decimal`?
Which, it is literally too big, but that's a bit confusing unless you are
thinking about the representation.
##########
csharp/src/Apache.Arrow/DecimalUtility.cs:
##########
@@ -52,7 +52,11 @@ internal static decimal GetDecimal(in ArrowBuffer
valueBuffer, int index, int sc
BigInteger integerPart = BigInteger.DivRem(integerValue,
scaleBy, out BigInteger fractionalPart);
if (integerPart > _maxDecimal || integerPart < _minDecimal) //
decimal overflow, not much we can do here - C# needs a BigDecimal
{
- throw new OverflowException($"Value: {integerPart} too big
or too small to be represented as a decimal");
+ throw new OverflowException($"Value: {integerValue} is too
big or too small to be represented as a decimal");
+ }
+ if (fractionalPart > _maxDecimal || fractionalPart <
_minDecimal) // decimal overflow, not much we can do here - C# needs a
BigDecimal
+ {
+ throw new OverflowException($"Value: {integerValue} is too
big or too small to be represented as a decimal");
Review Comment:
Separately, I think it would be useful to differentiate the error messages
here and possibly include the problematic value
--
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]