adamreeve commented on code in PR #292:
URL: https://github.com/apache/arrow-dotnet/pull/292#discussion_r2978618411
##########
src/Apache.Arrow/Arrays/Decimal128Array.cs:
##########
@@ -147,6 +147,24 @@ public Decimal128Array(ArrayData data)
return DecimalUtility.GetDecimal(ValueBuffer, Offset + index,
Scale, ByteWidth);
}
+ public bool TryGetValue(int index, out decimal? value)
Review Comment:
It would be good to have some documentation added on this and `GetValue`
(and the 256 bit variant) to explain when they can fail.
##########
test/Apache.Arrow.Tests/Decimal128ArrayTests.cs:
##########
@@ -459,6 +459,62 @@ public void AppendRangeSqlDecimal()
}
}
+ public class HighPrecisionGetValue
+ {
+ [Fact]
+ public void GetValueWithHighScale()
+ {
+ // Decimal128 supports up to precision 38, scale 38
+ var array = new Decimal128Array.Builder(new Decimal128Type(38,
20))
+ .Append(2422.85527600000m)
+ .Build();
+
+ Assert.Equal(2422.85527600000m, array.GetValue(0));
+ }
+
+ [Fact]
+ public void GetValueWithMaxScaleFractionalOnly()
+ {
+ var array = new Decimal128Array.Builder(new Decimal128Type(38,
30))
+ .Append(0.12345678m)
+ .Build();
+
+ Assert.Equal(0.12345678m, array.GetValue(0));
+ }
+
+ [Fact]
+ public void GetValueWithHighScaleNegative()
+ {
+ var array = new Decimal128Array.Builder(new Decimal128Type(38,
20))
+ .Append(-2422.85527600000m)
+ .Build();
+
+ Assert.Equal(-2422.85527600000m, array.GetValue(0));
+ }
+
+ [Fact]
+ public void TryGetValueReturnsTrue()
Review Comment:
Can we have a test cases covering paths where this fails and returns false?
--
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]