[Bugfix] return null for the null list in OrcStruct (#4590) (#4590)

This commit is contained in:
Yuusaku Taniguchi 2017-07-26 02:31:31 +09:00 committed by Gian Merlino
parent 3d6f409fc8
commit 525b5f2723
2 changed files with 7 additions and 2 deletions

View File

@ -131,6 +131,9 @@ public class OrcHadoopInputRowParser implements InputRowParser<OrcStruct>
private List getListObject(ListObjectInspector listObjectInspector, Object listObject)
{
if (listObjectInspector.getListLength(listObject) < 0) {
return null;
}
List objectList = listObjectInspector.getList(listObject);
List list = null;
ObjectInspector child = listObjectInspector.getListElementObjectInspector();

View File

@ -144,7 +144,7 @@ public class OrcHadoopInputRowParserTest
@Test
public void testParse()
{
final String typeString = "struct<timestamp:string,col1:string,col2:array<string>,col3:float,col4:bigint,col5:decimal>";
final String typeString = "struct<timestamp:string,col1:string,col2:array<string>,col3:float,col4:bigint,col5:decimal,col6:array<string>>";
final OrcHadoopInputRowParser parser = new OrcHadoopInputRowParser(
new TimeAndDimsParseSpec(
new TimestampSpec("timestamp", "auto", null),
@ -157,13 +157,14 @@ public class OrcHadoopInputRowParserTest
TypeInfoUtils.getTypeInfoFromTypeString(typeString)
);
final OrcStruct struct = (OrcStruct) oi.create();
struct.setNumFields(6);
struct.setNumFields(7);
oi.setStructFieldData(struct, oi.getStructFieldRef("timestamp"), new Text("2000-01-01"));
oi.setStructFieldData(struct, oi.getStructFieldRef("col1"), new Text("foo"));
oi.setStructFieldData(struct, oi.getStructFieldRef("col2"), ImmutableList.of(new Text("foo"), new Text("bar")));
oi.setStructFieldData(struct, oi.getStructFieldRef("col3"), new FloatWritable(1));
oi.setStructFieldData(struct, oi.getStructFieldRef("col4"), new LongWritable(2));
oi.setStructFieldData(struct, oi.getStructFieldRef("col5"), new HiveDecimalWritable(3));
oi.setStructFieldData(struct, oi.getStructFieldRef("col6"), null);
final InputRow row = parser.parse(struct);
Assert.assertEquals("timestamp", new DateTime("2000-01-01"), row.getTimestamp());
@ -172,5 +173,6 @@ public class OrcHadoopInputRowParserTest
Assert.assertEquals("col3", 1.0f, row.getRaw("col3"));
Assert.assertEquals("col4", 2L, row.getRaw("col4"));
Assert.assertEquals("col5", 3.0d, row.getRaw("col5"));
Assert.assertNull("col6", row.getRaw("col6"));
}
}