Skip to content

Commit

Permalink
Avoid batch reading of nested decimals as this reader is not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
denodo-research-labs committed Jan 28, 2025
1 parent 3da462f commit c725600
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,101 @@ public void testNestedArrays()
tester.testRoundTrip(objectInspector, values, values, type);
}

@Test
public void testNestedArraysDecimalBackedByINT32()
throws Exception
{
int precision = 1;
int scale = 0;
ObjectInspector objectInspector = getStandardListObjectInspector(javaIntObjectInspector);
Type type = new ArrayType(createDecimalType(precision, scale));
Iterable<List<Integer>> values = createTestArrays(intsBetween(1, 1_000));

List<List<SqlDecimal>> expectedValues = new ArrayList<>();
for (List<Integer> value : values) {
List<SqlDecimal> expectedDecimal = new ArrayList<>();
for (Integer valueInt : value) {
expectedDecimal.add(SqlDecimal.of(valueInt, precision, scale));
}
expectedValues.add(expectedDecimal);
}

MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
" optional group my_list (LIST){" +
" repeated group list {" +
" optional INT32 element (DECIMAL(%d, %d));" +
" }" +
" }" +
"} ", precision, scale));

tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
}

@Test
public void testNestedArraysDecimalBackedByINT64()
throws Exception
{
int precision = 10;
int scale = 2;
ObjectInspector objectInspector = getStandardListObjectInspector(javaLongObjectInspector);
Type type = new ArrayType(createDecimalType(precision, scale));
Iterable<List<Long>> values = createTestArrays(longsBetween(1, 1_000));

List<List<SqlDecimal>> expectedValues = new ArrayList<>();
for (List<Long> value : values) {
List<SqlDecimal> expectedDecimal = new ArrayList<>();
for (Long valueLong : value) {
expectedDecimal.add(SqlDecimal.of(valueLong, precision, scale));
}
expectedValues.add(expectedDecimal);
}

MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
" optional group my_list (LIST){" +
" repeated group list {" +
" optional INT64 element (DECIMAL(%d, %d));" +
" }" +
" }" +
"} ", precision, scale));
tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
}

@Test
public void testNestedArraysShortDecimalBackedByBinary()
throws Exception
{
int precision = 1;
int scale = 0;
ObjectInspector objectInspector = getStandardListObjectInspector(new JavaHiveDecimalObjectInspector(new DecimalTypeInfo(precision, scale)));
Type type = new ArrayType(createDecimalType(precision, scale));
ContiguousSet<BigInteger> bigIntegerValues = bigIntegersBetween(BigDecimal.valueOf(Math.pow(10, precision - 1)).toBigInteger(),
BigDecimal.valueOf(Math.pow(10, precision)).toBigInteger());
ImmutableList.Builder<HiveDecimal> writeValues = new ImmutableList.Builder<>();
for (BigInteger value : limit(bigIntegerValues, 1_000)) {
writeValues.add(HiveDecimal.create(value, scale));
}
Iterable<List<HiveDecimal>> values = createTestArrays(writeValues.build());

List<List<SqlDecimal>> expectedValues = new ArrayList<>();
for (List<HiveDecimal> value : values) {
List<SqlDecimal> expectedDecimal = new ArrayList<>();
for (HiveDecimal valueHiveDecimal : value) {
expectedDecimal.add(new SqlDecimal(valueHiveDecimal.unscaledValue(), precision, scale));
}
expectedValues.add(expectedDecimal);
}

MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
" optional group my_list (LIST){" +
" repeated group list {" +
" optional BINARY element (DECIMAL(%d, %d));" +
" }" +
" }" +
"} ", precision, scale));

tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
}

@Test
public void testSingleLevelSchemaNestedArrays()
throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private ColumnReaderFactory()

public static ColumnReader createReader(RichColumnDescriptor descriptor, boolean batchReadEnabled)
{
if (batchReadEnabled) {
final boolean isNested = descriptor.getPath().length > 1;
final boolean isNested = descriptor.getPath().length > 1;
if (batchReadEnabled && (!isNested || !isDecimalType(descriptor))) {
switch (descriptor.getPrimitiveType().getPrimitiveTypeName()) {
case BOOLEAN:
return isNested ? new BooleanNestedBatchReader(descriptor) : new BooleanFlatBatchReader(descriptor);
Expand Down

0 comments on commit c725600

Please sign in to comment.