context.getAllocator();
returns(new DirectBufferAllocator());
}
};
JSONRecordReader jr = new JSONRecordReader(context,
FileUtils.getResourceAsFile("/scan_json_test_2.json").toURI().toString(),
FileSystem.getLocal(new Configuration()),
64, null); // batch only fits 1 int
MockOutputMutator mutator = new MockOutputMutator();
List<ValueVector> addFields = mutator.getAddFields();
List<MaterializedField> removedFields = mutator.getRemovedFields();
jr.setup(mutator);
assertEquals(1, jr.next());
assertEquals(5, addFields.size());
assertField(addFields.get(0), 0, MinorType.INT, 123, "test");
assertField(addFields.get(1), 0, MinorType.INT, 1, "b");
assertField(addFields.get(2), 0, MinorType.FLOAT4, (float) 2.15, "c");
assertField(addFields.get(3), 0, MinorType.BIT, true, "bool");
assertField(addFields.get(4), 0, MinorType.VARCHAR, "test1".getBytes(UTF_8), "str1");
assertTrue(removedFields.isEmpty());
assertEquals(1, jr.next());
assertEquals(6, addFields.size());
assertField(addFields.get(0), 0, MinorType.INT, 1234, "test");
assertField(addFields.get(1), 0, MinorType.INT, 3, "b");
assertField(addFields.get(3), 0, MinorType.BIT, false, "bool");
assertField(addFields.get(4), 0, MinorType.VARCHAR, "test2".getBytes(UTF_8), "str1");
assertField(addFields.get(5), 0, MinorType.INT, 4, "d");
assertEquals(1, removedFields.size());
assertEquals("c", removedFields.get(0).getName());
removedFields.clear();
assertEquals(1, jr.next());
assertEquals(7, addFields.size()); // The reappearing of field 'c' is also included
assertField(addFields.get(0), 0, MinorType.INT, 12345, "test");
assertField(addFields.get(3), 0, MinorType.BIT, true, "bool");
assertField(addFields.get(5), 0, MinorType.INT, 6, "d");
assertField(addFields.get(2), 0, MinorType.FLOAT4, (float) 5.16, "c");
assertField(addFields.get(6), 0, MinorType.VARCHAR, "test3".getBytes(UTF_8), "str2");
assertEquals(2, removedFields.size());
Iterables.find(removedFields, new Predicate<MaterializedField>() {
@Override
public boolean apply(MaterializedField materializedField) {
return materializedField.getName().equals("str1");
}
});
Iterables.find(removedFields, new Predicate<MaterializedField>() {
@Override
public boolean apply(MaterializedField materializedField) {
return materializedField.getName().equals("b");
}
});
assertEquals(0, jr.next());
}