use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaIntObjectInspector 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;
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaIntObjectInspector in project cdap by caskdata.
the class StandardObjectInspectorsTest method testStandardMapObjectInspector.
@Test
public void testStandardMapObjectInspector() throws Throwable {
try {
StandardMapObjectInspector moi1 = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaIntObjectInspector);
StandardMapObjectInspector moi2 = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaIntObjectInspector);
Assert.assertEquals(moi1, moi2);
// metadata
Assert.assertEquals(Category.MAP, moi1.getCategory());
Assert.assertEquals(moi1.getMapKeyObjectInspector(), PrimitiveObjectInspectorFactory.javaStringObjectInspector);
Assert.assertEquals(moi2.getMapValueObjectInspector(), PrimitiveObjectInspectorFactory.javaIntObjectInspector);
// null
Assert.assertNull(moi1.getMap(null));
Assert.assertNull(moi1.getMapValueElement(null, null));
Assert.assertNull(moi1.getMapValueElement(null, "nokey"));
Assert.assertEquals(-1, moi1.getMapSize(null));
Assert.assertEquals("map<" + PrimitiveObjectInspectorFactory.javaStringObjectInspector.getTypeName() + "," + PrimitiveObjectInspectorFactory.javaIntObjectInspector.getTypeName() + ">", moi1.getTypeName());
// HashMap
HashMap<String, Integer> map = new HashMap<>();
map.put("one", 1);
map.put("two", 2);
map.put("three", 3);
Assert.assertEquals(map, moi1.getMap(map));
Assert.assertEquals(3, moi1.getMapSize(map));
Assert.assertEquals(1, moi1.getMapValueElement(map, "one"));
Assert.assertEquals(2, moi1.getMapValueElement(map, "two"));
Assert.assertEquals(3, moi1.getMapValueElement(map, "three"));
Assert.assertNull(moi1.getMapValueElement(map, null));
Assert.assertNull(moi1.getMapValueElement(map, "null"));
// Settable
Object map3 = moi1.create();
moi1.put(map3, "one", 1);
moi1.put(map3, "two", 2);
moi1.put(map3, "three", 3);
Assert.assertEquals(map, map3);
moi1.clear(map3);
Assert.assertEquals(0, moi1.getMapSize(map3));
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
}
Aggregations