Skip to content

Commit

Permalink
Cover wider range of values in testDecimalBackedByFixedLenByteArray
Browse files Browse the repository at this point in the history
At higher precisions the current logic was testing only negative values
  • Loading branch information
raunaqmorarka authored and sopel39 committed Nov 2, 2021
1 parent a6e70a0 commit 8c5c5c2
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,13 @@ public void testDecimalBackedByFixedLenByteArray()
{
for (int precision = 1; precision < MAX_PRECISION; precision++) {
int scale = ThreadLocalRandom.current().nextInt(precision);
ContiguousSet<BigInteger> values = bigIntegersBetween(BigDecimal.valueOf(Math.pow(10, precision - 1)).negate().toBigInteger(), BigDecimal.valueOf(Math.pow(10, precision)).toBigInteger());
ImmutableList.Builder<SqlDecimal> expectedValues = new ImmutableList.Builder<>();
ImmutableList.Builder<HiveDecimal> writeValues = new ImmutableList.Builder<>();
for (BigInteger value : limit(values, 1_000)) {

BigInteger start = BigDecimal.valueOf(Math.pow(10, precision - 1)).negate().toBigInteger();
BigInteger end = BigDecimal.valueOf(Math.pow(10, precision)).toBigInteger();
BigInteger step = BigInteger.valueOf(1).max(end.subtract(start).divide(BigInteger.valueOf(1_000)));
for (BigInteger value = start; value.compareTo(end) < 0; value = value.add(step)) {
writeValues.add(HiveDecimal.create(value, scale));
expectedValues.add(new SqlDecimal(value, precision, scale));
}
Expand Down Expand Up @@ -1690,11 +1693,6 @@ private static ContiguousSet<Long> longsBetween(long lowerInclusive, long upperE
return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.longs());
}

private static ContiguousSet<BigInteger> bigIntegersBetween(BigInteger lowerInclusive, BigInteger upperExclusive)
{
return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.bigIntegers());
}

private <F> List<List<?>> createTestStructs(Iterable<F> fieldValues)
{
checkArgument(fieldValues.iterator().hasNext(), "struct field values cannot be empty");
Expand Down

0 comments on commit 8c5c5c2

Please sign in to comment.