Search in sources :

Example 11 with StandardListObjectInspector

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;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with StandardListObjectInspector

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;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)9 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)9 Test (org.junit.Test)8 StandardListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector)6 List (java.util.List)5 LinkedList (java.util.LinkedList)4 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)4 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)4 TypeToken (com.google.common.reflect.TypeToken)3 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)3 Schema (org.apache.avro.Schema)2 GenericData (org.apache.avro.generic.GenericData)2 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)2 JavaStringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaStringObjectInspector)2 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Queue (java.util.Queue)1 ColumnInfo (org.apache.hadoop.hive.ql.exec.ColumnInfo)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 RowResolver (org.apache.hadoop.hive.ql.parse.RowResolver)1