use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project cdap by caskdata.
the class StandardObjectInspectorsTest method testStandardSetObjectInspector.
@Test
public void testStandardSetObjectInspector() throws Throwable {
try {
ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Set<Integer>>() {
}.getType());
Assert.assertTrue(oi instanceof StandardListObjectInspector);
StandardListObjectInspector loi = (StandardListObjectInspector) oi;
// metadata
Assert.assertEquals(Category.LIST, loi.getCategory());
Assert.assertEquals(PrimitiveObjectInspectorFactory.javaIntObjectInspector, loi.getListElementObjectInspector());
// Test set inspection
HashSet<Integer> set = new HashSet<>();
set.add(0);
set.add(1);
set.add(2);
set.add(3);
Assert.assertEquals(4, loi.getList(set).size());
Assert.assertEquals(4, loi.getListLength(set));
Assert.assertEquals(0, loi.getListElement(set, 0));
Assert.assertEquals(3, loi.getListElement(set, 3));
Assert.assertNull(loi.getListElement(set, -1));
Assert.assertNull(loi.getListElement(set, 4));
// Settable
List<String> list = (List<String>) loi.set(set, 0, 5);
Assert.assertFalse(set.contains(5));
Assert.assertTrue(list.contains(5));
list = (List<String>) loi.resize(set, 5);
Assert.assertEquals(4, set.size());
Assert.assertEquals(5, list.size());
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector in project cdap by caskdata.
the class StandardObjectInspectorsTest method testStandardQueueObjectInspector.
@Test
public void testStandardQueueObjectInspector() throws Throwable {
try {
ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Queue<Integer>>() {
}.getType());
Assert.assertTrue(oi instanceof StandardListObjectInspector);
StandardListObjectInspector loi = (StandardListObjectInspector) oi;
// metadata
Assert.assertEquals(Category.LIST, loi.getCategory());
Assert.assertEquals(PrimitiveObjectInspectorFactory.javaIntObjectInspector, loi.getListElementObjectInspector());
// Test queue inspection
Queue<Integer> queue = new ArrayDeque<>();
queue.add(0);
queue.add(1);
queue.add(2);
queue.add(3);
Assert.assertEquals(4, loi.getList(queue).size());
Assert.assertEquals(4, loi.getListLength(queue));
Assert.assertEquals(0, loi.getListElement(queue, 0));
Assert.assertEquals(3, loi.getListElement(queue, 3));
Assert.assertNull(loi.getListElement(queue, -1));
Assert.assertNull(loi.getListElement(queue, 4));
// Settable
List<String> list = (List<String>) loi.set(queue, 0, 5);
Assert.assertFalse(queue.contains(5));
Assert.assertTrue(list.contains(5));
list = (List<String>) loi.resize(queue, 5);
Assert.assertEquals(4, queue.size());
Assert.assertEquals(5, list.size());
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
}
Aggregations