Skip to content

Commit c725600

Browse files
Avoid batch reading of nested decimals as this reader is not implemented
1 parent 3da462f commit c725600

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

presto-hive/src/test/java/com/facebook/presto/hive/parquet/AbstractTestParquetReader.java

+95
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,101 @@ public void testNestedArrays()
181181
tester.testRoundTrip(objectInspector, values, values, type);
182182
}
183183

184+
@Test
185+
public void testNestedArraysDecimalBackedByINT32()
186+
throws Exception
187+
{
188+
int precision = 1;
189+
int scale = 0;
190+
ObjectInspector objectInspector = getStandardListObjectInspector(javaIntObjectInspector);
191+
Type type = new ArrayType(createDecimalType(precision, scale));
192+
Iterable<List<Integer>> values = createTestArrays(intsBetween(1, 1_000));
193+
194+
List<List<SqlDecimal>> expectedValues = new ArrayList<>();
195+
for (List<Integer> value : values) {
196+
List<SqlDecimal> expectedDecimal = new ArrayList<>();
197+
for (Integer valueInt : value) {
198+
expectedDecimal.add(SqlDecimal.of(valueInt, precision, scale));
199+
}
200+
expectedValues.add(expectedDecimal);
201+
}
202+
203+
MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
204+
" optional group my_list (LIST){" +
205+
" repeated group list {" +
206+
" optional INT32 element (DECIMAL(%d, %d));" +
207+
" }" +
208+
" }" +
209+
"} ", precision, scale));
210+
211+
tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
212+
}
213+
214+
@Test
215+
public void testNestedArraysDecimalBackedByINT64()
216+
throws Exception
217+
{
218+
int precision = 10;
219+
int scale = 2;
220+
ObjectInspector objectInspector = getStandardListObjectInspector(javaLongObjectInspector);
221+
Type type = new ArrayType(createDecimalType(precision, scale));
222+
Iterable<List<Long>> values = createTestArrays(longsBetween(1, 1_000));
223+
224+
List<List<SqlDecimal>> expectedValues = new ArrayList<>();
225+
for (List<Long> value : values) {
226+
List<SqlDecimal> expectedDecimal = new ArrayList<>();
227+
for (Long valueLong : value) {
228+
expectedDecimal.add(SqlDecimal.of(valueLong, precision, scale));
229+
}
230+
expectedValues.add(expectedDecimal);
231+
}
232+
233+
MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
234+
" optional group my_list (LIST){" +
235+
" repeated group list {" +
236+
" optional INT64 element (DECIMAL(%d, %d));" +
237+
" }" +
238+
" }" +
239+
"} ", precision, scale));
240+
tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
241+
}
242+
243+
@Test
244+
public void testNestedArraysShortDecimalBackedByBinary()
245+
throws Exception
246+
{
247+
int precision = 1;
248+
int scale = 0;
249+
ObjectInspector objectInspector = getStandardListObjectInspector(new JavaHiveDecimalObjectInspector(new DecimalTypeInfo(precision, scale)));
250+
Type type = new ArrayType(createDecimalType(precision, scale));
251+
ContiguousSet<BigInteger> bigIntegerValues = bigIntegersBetween(BigDecimal.valueOf(Math.pow(10, precision - 1)).toBigInteger(),
252+
BigDecimal.valueOf(Math.pow(10, precision)).toBigInteger());
253+
ImmutableList.Builder<HiveDecimal> writeValues = new ImmutableList.Builder<>();
254+
for (BigInteger value : limit(bigIntegerValues, 1_000)) {
255+
writeValues.add(HiveDecimal.create(value, scale));
256+
}
257+
Iterable<List<HiveDecimal>> values = createTestArrays(writeValues.build());
258+
259+
List<List<SqlDecimal>> expectedValues = new ArrayList<>();
260+
for (List<HiveDecimal> value : values) {
261+
List<SqlDecimal> expectedDecimal = new ArrayList<>();
262+
for (HiveDecimal valueHiveDecimal : value) {
263+
expectedDecimal.add(new SqlDecimal(valueHiveDecimal.unscaledValue(), precision, scale));
264+
}
265+
expectedValues.add(expectedDecimal);
266+
}
267+
268+
MessageType hiveSchema = parseMessageType(format("message hive_list_decimal {" +
269+
" optional group my_list (LIST){" +
270+
" repeated group list {" +
271+
" optional BINARY element (DECIMAL(%d, %d));" +
272+
" }" +
273+
" }" +
274+
"} ", precision, scale));
275+
276+
tester.testRoundTrip(objectInspector, values, expectedValues, "my_list", type, Optional.of(hiveSchema));
277+
}
278+
184279
@Test
185280
public void testSingleLevelSchemaNestedArrays()
186281
throws Exception

presto-parquet/src/main/java/com/facebook/presto/parquet/ColumnReaderFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ private ColumnReaderFactory()
6363

6464
public static ColumnReader createReader(RichColumnDescriptor descriptor, boolean batchReadEnabled)
6565
{
66-
if (batchReadEnabled) {
67-
final boolean isNested = descriptor.getPath().length > 1;
66+
final boolean isNested = descriptor.getPath().length > 1;
67+
if (batchReadEnabled && (!isNested || !isDecimalType(descriptor))) {
6868
switch (descriptor.getPrimitiveType().getPrimitiveTypeName()) {
6969
case BOOLEAN:
7070
return isNested ? new BooleanNestedBatchReader(descriptor) : new BooleanFlatBatchReader(descriptor);

0 commit comments

Comments
 (0)