Beispiel #1
0
        public static List <TypeInfo> typeInfosFromStructObjectInspector(
            StructObjectInspector structObjectInspector)
        {
            IList <StructField> fields       = structObjectInspector.getAllStructFieldRefs();
            List <TypeInfo>     typeInfoList = new List <TypeInfo>(fields.Count);

            foreach (StructField field in fields)
            {
                TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(
                    field.getFieldObjectInspector().getTypeName());
                typeInfoList.Add(typeInfo);
            }
            return(typeInfoList);
        }
Beispiel #2
0
        /**
         * Get the TypeInfo object from the ObjectInspector object by recursively
         * going into the ObjectInspector structure.
         */
        public static TypeInfo getTypeInfoFromObjectInspector(ObjectInspector oi)
        {
            // OPTIMIZATION for later.
            // if (oi instanceof TypeInfoBasedObjectInspector) {
            // TypeInfoBasedObjectInspector typeInfoBasedObjectInspector =
            // (ObjectInspector)oi;
            // return typeInfoBasedObjectInspector.getTypeInfo();
            // }
            if (oi == null)
            {
                return(null);
            }

            // Recursively going into ObjectInspector structure
            TypeInfo result = null;

            switch (oi.getCategory())
            {
            case ObjectInspectorCategory.PRIMITIVE:
            {
                PrimitiveObjectInspector poi = (PrimitiveObjectInspector)oi;
                result = poi.getTypeInfo();
                break;
            }

            case ObjectInspectorCategory.LIST:
            {
                ListObjectInspector loi = (ListObjectInspector)oi;
                result = TypeInfoFactory
                         .getListTypeInfo(getTypeInfoFromObjectInspector(loi
                                                                         .getListElementObjectInspector()));
                break;
            }

            case ObjectInspectorCategory.MAP:
            {
                MapObjectInspector moi = (MapObjectInspector)oi;
                result = TypeInfoFactory.getMapTypeInfo(
                    getTypeInfoFromObjectInspector(moi.getMapKeyObjectInspector()),
                    getTypeInfoFromObjectInspector(moi.getMapValueObjectInspector()));
                break;
            }

            case ObjectInspectorCategory.STRUCT:
            {
                StructObjectInspector soi            = (StructObjectInspector)oi;
                IList <StructField>   fields         = soi.getAllStructFieldRefs();
                List <String>         fieldNames     = new List <String>(fields.Count);
                List <TypeInfo>       fieldTypeInfos = new List <TypeInfo>(fields.Count);
                foreach (StructField f in fields)
                {
                    fieldNames.Add(f.getFieldName());
                    fieldTypeInfos.Add(getTypeInfoFromObjectInspector(f
                                                                      .getFieldObjectInspector()));
                }
                result = TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
                break;
            }

            case ObjectInspectorCategory.UNION:
            {
                UnionObjectInspector uoi             = (UnionObjectInspector)oi;
                List <TypeInfo>      objectTypeInfos = new List <TypeInfo>();
                foreach (ObjectInspector eoi in uoi.getObjectInspectors())
                {
                    objectTypeInfos.Add(getTypeInfoFromObjectInspector(eoi));
                }
                result = TypeInfoFactory.getUnionTypeInfo(objectTypeInfos);
                break;
            }

            default:
            {
                throw new InvalidOperationException("Unknown ObjectInspector category!");
            }
            }
            return(result);
        }