Search in sources :

Example 1 with SetIntString

use of org.apache.hadoop.hive.serde2.thrift.test.SetIntString in project hive by apache.

the class TestThriftObjectInspectors method testThriftSetObjectInspector.

@SuppressWarnings("unchecked")
public void testThriftSetObjectInspector() throws Throwable {
    try {
        ObjectInspector oi1 = ObjectInspectorFactory.getReflectionObjectInspector(SetIntString.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
        ObjectInspector oi2 = ObjectInspectorFactory.getReflectionObjectInspector(SetIntString.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
        assertEquals(oi1, oi2);
        // metadata
        assertEquals(Category.STRUCT, oi1.getCategory());
        StructObjectInspector soi = (StructObjectInspector) oi1;
        List<? extends StructField> fields = soi.getAllStructFieldRefs();
        assertEquals(2, fields.size());
        assertEquals(fields.get(0), soi.getStructFieldRef("sIntString"));
        assertEquals(fields.get(1), soi.getStructFieldRef("aString"));
        // null
        for (int i = 0; i < fields.size(); i++) {
            assertNull(soi.getStructFieldData(null, fields.get(i)));
        }
        // real object
        IntString s1 = new IntString();
        s1.setMyint(1);
        s1.setMyString("test");
        s1.setUnderscore_int(2);
        Set<IntString> set1 = new HashSet<IntString>();
        set1.add(s1);
        SetIntString s = new SetIntString();
        s.setSIntString(set1);
        s.setAString("setString");
        assertEquals(set1, soi.getStructFieldData(s, fields.get(0)));
        assertEquals("setString", soi.getStructFieldData(s, fields.get(1)));
        // sub fields
        assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getReflectionObjectInspector(IntString.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT)), fields.get(0).getFieldObjectInspector());
        assertEquals(PrimitiveObjectInspectorFactory.javaStringObjectInspector, fields.get(1).getFieldObjectInspector());
        // compare set fields
        ListObjectInspector loi = (ListObjectInspector) fields.get(0).getFieldObjectInspector();
        assertEquals(1, loi.getListLength(set1));
        List<IntString> list = (List<IntString>) loi.getList(set1);
        assertEquals(1, list.size());
        s1 = (IntString) loi.getListElement(list, 0);
        assertEquals(1, s1.getMyint());
        assertEquals("test", s1.getMyString());
        assertEquals(2, s1.getUnderscore_int());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : SetIntString(org.apache.hadoop.hive.serde2.thrift.test.SetIntString) IntString(org.apache.hadoop.hive.serde2.thrift.test.IntString) SetIntString(org.apache.hadoop.hive.serde2.thrift.test.SetIntString) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IntString (org.apache.hadoop.hive.serde2.thrift.test.IntString)1 SetIntString (org.apache.hadoop.hive.serde2.thrift.test.SetIntString)1