Exemple #1
0
        public static List <TypeInfo> typeInfosFromTypeNames(List <String> typeNames)
        {
            List <TypeInfo> result = new List <TypeInfo>(typeNames.Count);

            for (int i = 0; i < typeNames.Count; i++)
            {
                TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(typeNames[i]);
                result.Add(typeInfo);
            }
            return(result);
        }
Exemple #2
0
        /**
         * Given two types, determine whether conversion needs to occur to compare the two types.
         * This is needed for cases like varchar, where the TypeInfo for varchar(10) != varchar(5),
         * but there would be no need to have to convert to compare these values.
         * @param typeA
         * @param typeB
         * @return
         */
        public static bool isConversionRequiredForComparison(TypeInfo typeA, TypeInfo typeB)
        {
            if (typeA.Equals(typeB))
            {
                return(false);
            }

            if (TypeInfoUtils.doPrimitiveCategoriesMatch(typeA, typeB))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
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);
        }
Exemple #4
0
        /**
         * Get the parameter TypeInfo for a method.
         *
         * @param size
         *          In case the last parameter of Method is an array, we will try to
         *          return a List<TypeInfo> with the specified size by repeating the
         *          element of the array at the end. In case the size is smaller than
         *          the minimum possible number of arguments for the method, null will
         *          be returned.
         */
        public static List <TypeInfo> getParameterTypeInfos(MethodInfo m, int size)
        {
            Type[] methodParameterTypes = m.GetParameters().Select(p => p.ParameterType).ToArray();

            // Whether the method takes variable-length arguments
            // Whether the method takes an array like Object[],
            // or String[] etc in the last argument.
            Type lastParaElementType = TypeInfoUtils
                                       .getArrayElementType(methodParameterTypes.Length == 0 ? null
                : methodParameterTypes[methodParameterTypes.Length - 1]);
            bool isVariableLengthArgument = (lastParaElementType != null);

            List <TypeInfo> typeInfos = null;

            if (!isVariableLengthArgument)
            {
                // Normal case, no variable-length arguments
                if (size != methodParameterTypes.Length)
                {
                    return(null);
                }
                typeInfos = new List <TypeInfo>(methodParameterTypes.Length);
                foreach (Type methodParameterType in methodParameterTypes)
                {
                    typeInfos.Add(getExtendedTypeInfoFromJavaType(methodParameterType, m));
                }
            }
            else
            {
                // Variable-length arguments
                if (size < methodParameterTypes.Length - 1)
                {
                    return(null);
                }
                typeInfos = new List <TypeInfo>(size);
                for (int i = 0; i < methodParameterTypes.Length - 1; i++)
                {
                    typeInfos.Add(getExtendedTypeInfoFromJavaType(methodParameterTypes[i],
                                                                  m));
                }
                for (int i = methodParameterTypes.Length - 1; i < size; i++)
                {
                    typeInfos.Add(getExtendedTypeInfoFromJavaType(lastParaElementType, m));
                }
            }
            return(typeInfos);
        }
Exemple #5
0
        /**
         * Return the extended TypeInfo from a Java type. By extended TypeInfo, we
         * allow unknownType for java.lang.Object.
         *
         * @param t
         *          The Java type.
         * @param m
         *          The method, only used for generating error messages.
         */
        private static TypeInfo getExtendedTypeInfoFromJavaType(Type t, MethodInfo m)
        {
            if (t == typeof(object))
            {
                return(TypeInfoFactory.unknownTypeInfo);
            }

            if (t.IsGenericType)
            {
                Type   bt = t.GetGenericTypeDefinition();
                Type[] pt = t.GenericTypeArguments;

                // List?
                if (bt == typeof(List <>))
                {
                    return(TypeInfoFactory.getListTypeInfo(getExtendedTypeInfoFromJavaType(
                                                               pt[0], m)));
                }
                // Map?
                if (bt == typeof(Dictionary <,>))
                {
                    return(TypeInfoFactory.getMapTypeInfo(
                               getExtendedTypeInfoFromJavaType(pt[0], m),
                               getExtendedTypeInfoFromJavaType(pt[1], m)));
                }
            }

            // Java Primitive Type?
            if (PrimitiveObjectInspectorUtils.isPrimitiveJavaType(t))
            {
                return(TypeInfoUtils
                       .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
                                                       .getPrimitiveJavaObjectInspector(PrimitiveObjectInspectorUtils
                                                                                        .getTypeEntryFromPrimitiveJavaType(t).primitiveCategory)));
            }

            // Java Primitive Class?
            if (PrimitiveObjectInspectorUtils.isPrimitiveJavaClass(t))
            {
                return(TypeInfoUtils
                       .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
                                                       .getPrimitiveJavaObjectInspector(PrimitiveObjectInspectorUtils
                                                                                        .getTypeEntryFromPrimitiveJavaClass(t).primitiveCategory)));
            }

            // Primitive Writable class?
            if (PrimitiveObjectInspectorUtils.isPrimitiveWritableClass(t))
            {
                return(TypeInfoUtils
                       .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
                                                       .getPrimitiveWritableObjectInspector(PrimitiveObjectInspectorUtils
                                                                                            .getTypeEntryFromPrimitiveWritableClass(t).primitiveCategory)));
            }

            // Must be a struct
            FieldInfo[]     fields         = ObjectInspectorUtils.getDeclaredNonStaticFields(t);
            List <string>   fieldNames     = new List <string>(fields.Length);
            List <TypeInfo> fieldTypeInfos = new List <TypeInfo>(fields.Length);

            foreach (FieldInfo field in fields)
            {
                fieldNames.Add(field.Name);
                fieldTypeInfos.Add(getExtendedTypeInfoFromJavaType(
                                       field.FieldType, m));
            }
            return(TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos));
        }