@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 1) { throw new UDFArgumentLengthException( "The function PRINTF(String format, Obj... args) needs at least one arguments."); if (arguments[0].getCategory() == ObjectInspector.Category.PRIMITIVE) { PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) arguments[0]); if (poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.STRING || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.CHAR || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.VARCHAR || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.VOID) { converterFormat = ObjectInspectorConverters.getConverter(arguments[0], resultOI); } else { throw new UDFArgumentTypeException(0, "Argument 1" + " of function PRINTF must be \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[0].getTypeName() + "\" was found."); throw new UDFArgumentTypeException(0, "Argument 1" + " of function PRINTF must be \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[0].getTypeName() + "\" was found."); if (!arguments[i].getCategory().equals(Category.PRIMITIVE)){ throw new UDFArgumentTypeException(i, "Argument " + (i + 1) + " of function PRINTF must be \"" + Category.PRIMITIVE + "\", but \"" + arguments[i].getTypeName() + "\" was found.");
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentException(opName + " requires one argument."); } Category category = arguments[0].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); } inputOI = (PrimitiveObjectInspector) arguments[0]; if (!FunctionRegistry.isNumericType(inputOI.getTypeInfo()) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalDayTimeTypeInfo) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalYearMonthTypeInfo)) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to be a " + "numeric or interval type, but " + inputOI.getTypeName() + " is found"); } PrimitiveTypeInfo resultTypeInfo = deriveResultTypeInfo(inputOI.getTypeInfo()); resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(resultTypeInfo); converter = ObjectInspectorConverters.getConverter(inputOI, resultOI); return resultOI; }
List<ColumnDescriptor> descriptors = getAllColumnDescriptorByType(depth, type, columnDescriptors); switch (typeInfo.getCategory()) { case PRIMITIVE: if (columnDescriptors == null || columnDescriptors.isEmpty()) { throw new RuntimeException( "Fail to build Parquet vectorized reader based on Hive type " + fieldTypes.get(i) .getTypeName() + " and Parquet type" + types.get(i).toString()); case UNION: default: throw new RuntimeException("Unsupported category " + typeInfo.getCategory().name());
if (oi1.getCategory() != oi2.getCategory()) { return oi1.getCategory().compareTo(oi2.getCategory()); PrimitiveObjectInspector poi1 = ((PrimitiveObjectInspector) oi1); PrimitiveObjectInspector poi2 = ((PrimitiveObjectInspector) oi2); if (poi1.getPrimitiveCategory() != poi2.getPrimitiveCategory()) { return poi1.getPrimitiveCategory().compareTo( poi2.getPrimitiveCategory());
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "The function SIZE only accepts 1 argument."); } Category category = arguments[0].getCategory(); String typeName = arguments[0].getTypeName(); if (category != Category.MAP && category != Category.LIST && !typeName.equals(serdeConstants.VOID_TYPE_NAME)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function SIZE, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } returnOI = arguments[0]; return PrimitiveObjectInspectorFactory.writableIntObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "The function INSTR accepts exactly 2 arguments."); } for (int i = 0; i < arguments.length; i++) { Category category = arguments[i].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of function INSTR is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); } } converters = new ObjectInspectorConverters.Converter[arguments.length]; for (int i = 0; i < arguments.length; i++) { converters[i] = ObjectInspectorConverters.getConverter(arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); } return PrimitiveObjectInspectorFactory.writableIntObjectInspector; }
private static void validateValueBoundaryExprType(ObjectInspector OI) throws SemanticException { if (!OI.getCategory().equals(Category.PRIMITIVE)) { throw new SemanticException( String.format( "Value Boundary expression must be of primitive type. Found: %s", OI.getTypeName())); PrimitiveCategory pC = pOI.getPrimitiveCategory();
throw new UDFArgumentException( "The function " + FUNC_NAME + " accepts " + ARG_COUNT + " arguments."); if (!arguments[ARRAY_IDX].getCategory().equals(Category.LIST)) { throw new UDFArgumentTypeException(ARRAY_IDX, "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" " + "expected at function ARRAY_CONTAINS, but " + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" " + "is found"); throw new UDFArgumentTypeException(VALUE_IDX, "\"" + arrayElementOI.getTypeName() + "\"" + " expected at function ARRAY_CONTAINS, but " + "\"" + valueOI.getTypeName() + "\"" throw new UDFArgumentException("The function " + FUNC_NAME + " does not support comparison for " + "\"" + valueOI.getTypeName() + "\""
private ObjectInspector getObjectInspector( TypeInfo typeInfo, TypeInfo prunedTypeInfo) { if (typeInfo.equals(TypeInfoFactory.doubleTypeInfo)) { return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; } else if (typeInfo.equals(TypeInfoFactory.booleanTypeInfo)) { return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; } else if (typeInfo.equals(TypeInfoFactory.floatTypeInfo)) { return PrimitiveObjectInspectorFactory.writableFloatObjectInspector; } else if (typeInfo.equals(TypeInfoFactory.intTypeInfo)) { } else if (typeInfo instanceof DecimalTypeInfo) { return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector((DecimalTypeInfo) typeInfo); } else if (typeInfo.getCategory().equals(Category.STRUCT)) { return new ArrayWritableObjectInspector(false, (StructTypeInfo) typeInfo, (StructTypeInfo) prunedTypeInfo); } else if (typeInfo.getCategory().equals(Category.LIST)) { final TypeInfo subTypeInfo = ((ListTypeInfo) typeInfo).getListElementTypeInfo(); return new ParquetHiveArrayInspector(getObjectInspector(subTypeInfo, null)); } else if (typeInfo.getCategory().equals(Category.MAP)) { final TypeInfo keyTypeInfo = ((MapTypeInfo) typeInfo).getMapKeyTypeInfo(); final TypeInfo valueTypeInfo = ((MapTypeInfo) typeInfo).getMapValueTypeInfo();
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException("The function MAP_VALUES only accepts 1 argument."); } else if (!(arguments[0] instanceof MapObjectInspector)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" is expected at function MAP_VALUES, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } mapOI = (MapObjectInspector) arguments[0]; ObjectInspector mapValueOI = mapOI.getMapValueObjectInspector(); return ObjectInspectorFactory.getStandardListObjectInspector(mapValueOI); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); checkArgsSize(arguments, 1, 1); switch(arguments[0].getCategory()) { case LIST: if(!((ListObjectInspector)(arguments[0])).getListElementObjectInspector() .getCategory().equals(ObjectInspector.Category.UNION)) { break; } default: throw new UDFArgumentTypeException(0, "Argument 1" + " of function SORT_ARRAY must be " + serdeConstants.LIST_TYPE_NAME + ", and element type should be either primitive, list, struct, or map, " + "but " + arguments[0].getTypeName() + " was found."); } ObjectInspector elementObjectInspector = ((ListObjectInspector)(arguments[0])).getListElementObjectInspector(); argumentOIs = arguments; converters = new Converter[arguments.length]; ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector); converters[0] = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI); return ObjectInspectorFactory.getStandardListObjectInspector(returnOI); }
public static HiveFieldConverter create(TypeInfo typeInfo) throws IllegalAccessException, InstantiationException { switch (typeInfo.getCategory()) { case PRIMITIVE: final PrimitiveCategory pCat = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory(); Class<? extends HiveFieldConverter> clazz = primMap.get(pCat); if (clazz != null) { return clazz.newInstance(); } throwUnsupportedHiveDataTypeError(pCat.toString()); break; case LIST: case MAP: case STRUCT: case UNION: default: throwUnsupportedHiveDataTypeError(typeInfo.getCategory().toString()); } return null; }
private String describeOi(String desc, ObjectInspector keyOi) { for (StructField field : ((StructObjectInspector)keyOi).getAllStructFieldRefs()) { ObjectInspector oi = field.getFieldObjectInspector(); String cat = oi.getCategory().toString(); if (oi.getCategory() == Category.PRIMITIVE) { cat = ((PrimitiveObjectInspector)oi).getPrimitiveCategory().toString(); } desc += field.getFieldName() + ":" + cat + ", "; } return desc; } }
/** * Checks that an inspector matches the category indicated as a parameter. * @param inspector The object inspector to check * @param category The category to match * @throws IllegalArgumentException if inspector does not match the category */ private void checkInspectorCategory(ObjectInspector inspector, ObjectInspector.Category category) { if (!inspector.getCategory().equals(category)) { throw new IllegalArgumentException("Invalid data type: expected " + category + " type, but found: " + inspector.getCategory()); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "The function INDEX accepts exactly 2 arguments."); mapOI = null; } else { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function INDEX, but \"" + arguments[0].getTypeName() + "\" is found"); throw new UDFArgumentTypeException(1, "Primitive Type is expected but " + arguments[1].getTypeName() + "\" is found"); ObjectInspector indexOI; if (mapOI != null) { indexOI = ObjectInspectorConverters.getConvertedOI( inputOI, mapOI.getMapKeyObjectInspector()); returnOI = mapOI.getMapValueObjectInspector(); returnOI = listOI.getListElementObjectInspector(); converter = ObjectInspectorConverters.getConverter(inputOI, indexOI);
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "minhashes() has 2 arguments: array<string> features, boolean noWeight"); } // Check argument types switch (arguments[0].getCategory()) { case LIST: featuresOI = (ListObjectInspector) arguments[0]; ObjectInspector elmOI = featuresOI.getListElementObjectInspector(); if (elmOI.getCategory().equals(Category.PRIMITIVE)) { if (((PrimitiveObjectInspector) elmOI).getPrimitiveCategory() == PrimitiveCategory.STRING) { break; } } default: throw new UDFArgumentTypeException(0, "Type mismatch: features"); } noWeightOI = (PrimitiveObjectInspector) arguments[1]; if (noWeightOI.getPrimitiveCategory() != PrimitiveCategory.BOOLEAN) { throw new UDFArgumentException("Type mismatch: noWeight"); } return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( PrimitiveCategory.INT)); }
/** * Parameters are event date, event count, event uniques, asof date, period array , */ @Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { for (int i = 0; i < parameters.length; ++i) { LOG.info("Type " + i + " == " + parameters[i].getTypeName() + " category " + parameters[i].getCategory().name()); } if (parameters.length != 5) { throw new UDFArgumentTypeException(parameters.length - 1, "multiday_count takes date, count, array, date, array "); } if (parameters[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(parameters.length - 1, "multiday_count takes date, count, array, date, array "); } return new MultiDayAggUDAFEvaluator(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentException( "The function FIELD(str, str1, str2, ...) needs at least two arguments."); } argumentOIs = arguments; for (int i = 0; i < arguments.length; i++) { Category category = arguments[i].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of function FIELD is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); } } return PrimitiveObjectInspectorFactory.writableIntObjectInspector; }
private void prepareInSet(DeferredObject[] arguments) throws HiveException { constantInSet = new HashSet<Object>(); if (compareOI.getCategory().equals(ObjectInspector.Category.PRIMITIVE)) { for (int i = 1; i < arguments.length; ++i) { constantInSet.add(((PrimitiveObjectInspector) compareOI) .getPrimitiveJavaObject(conversionHelper .convertIfNecessary(arguments[i].get(), argumentOIs[i]))); } } else { for (int i = 1; i < arguments.length; ++i) { constantInSet.add(((ConstantObjectInspector) argumentOIs[i]).getWritableConstantValue()); } } }
throws UDFArgumentException { if (arguments.length != 1 && arguments.length != 2) { throw new UDFArgumentException("Usage : json_split( jsonstring, optional typestring) "); if (!arguments[0].getCategory().equals(Category.PRIMITIVE) || ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() != PrimitiveCategory.STRING) { throw new UDFArgumentException("Usage : json_split( jsonstring, optional typestring) "); if (!arguments[1].getCategory().equals(Category.PRIMITIVE) || ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() != PrimitiveCategory.STRING) { throw new UDFArgumentException("Usage : json_split( jsonstring, optional typestring) ");