private Converter checkTextArguments(ObjectInspector[] arguments, int i) throws UDFArgumentException { if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "Only primitive type arguments are accepted but " + arguments[i].getTypeName() + " is passed."); } Converter converter = ObjectInspectorConverters.getConverter((PrimitiveObjectInspector) arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); return converter; }
public static ObjectInspector getConvertedOI( ObjectInspector inputOI, ObjectInspector outputOI, Map<ObjectInspector, Boolean> oiSettableProperties ) { return getConvertedOI(inputOI, outputOI, oiSettableProperties, true); }
@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; }
protected void obtainIntConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); switch (inputType) { case BYTE: case SHORT: case INT: case VOID: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + inputType); } Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableIntObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { for (int idx = 0; idx < Math.min(arguments.length, 3); ++idx) { if (arguments[idx].getCategory() != Category.PRIMITIVE || PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory()) != PrimitiveGrouping.STRING_GROUP) { throw new UDFArgumentException("All argument should be string/character type"); } } soi_text = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.javaStringObjectInspector); if (arguments.length > 1) { soi_de1 = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } if (arguments.length > 2) { soi_de2 = ObjectInspectorConverters.getConverter(arguments[2], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } return ObjectInspectorFactory.getStandardMapObjectInspector( PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector); }
protected void obtainStringConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentException(opName + " requires two arguments."); Category category = arguments[i].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( deriveResultTypeInfo()); converterLeft = ObjectInspectorConverters.getConverter(leftOI, resultOI); converterRight = ObjectInspectorConverters.getConverter(rightOI, resultOI);
switch (outputOI.getCategory()) { case PRIMITIVE: primOutputOI.getTypeInfo()); case STRUCT: StructObjectInspector structOutputOI = (StructObjectInspector) outputOI; structFieldObjectInspectors.add(getConvertedOI(listField.getFieldObjectInspector(), listField.getFieldObjectInspector(), oiSettableProperties, false)); getConvertedOI(listOutputOI.getListElementObjectInspector(), listOutputOI.getListElementObjectInspector(), oiSettableProperties, false)); case MAP: getConvertedOI(mapOutputOI.getMapKeyObjectInspector(), mapOutputOI.getMapKeyObjectInspector(), oiSettableProperties, false), getConvertedOI(mapOutputOI.getMapValueObjectInspector(), mapOutputOI.getMapValueObjectInspector(), oiSettableProperties, false)); case UNION: for (ObjectInspector listField : unionListFields) { unionFieldObjectInspectors.add(getConvertedOI(listField, listField, oiSettableProperties, false)); + inputOI.getTypeName() + " to " + outputOI.getTypeName() + " not supported yet.");
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length > 2) { throw new UDFArgumentLengthException( "Invalid scalar subquery expression. Subquery count check expected two argument but received: " + arguments.length); } converters[0] = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableLongObjectInspector); ObjectInspector outputOI = null; outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector; return outputOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); for (int i = 0; i < arguments.length; i++) { if (!returnOIResolver.update(arguments[i])) { throw new UDFArgumentTypeException(i, "Argument type \"" + arguments[i].getTypeName() + "\" is different from preceding arguments. " + "Previous type was \"" + arguments[i - 1].getTypeName() + "\""); } } converters = new Converter[arguments.length]; ObjectInspector returnOI = returnOIResolver.get(PrimitiveObjectInspectorFactory.javaStringObjectInspector); for (int i = 0; i < arguments.length; i++) { converters[i] = ObjectInspectorConverters.getConverter(arguments[i], returnOI); } return ObjectInspectorFactory.getStandardListObjectInspector(returnOI); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException("The like all operator requires at least one pattern for matching, got " + (arguments.length - 1)); } inputTypes = new PrimitiveCategory[arguments.length]; converters = new Converter[arguments.length]; /**expects string or null arguments */ for (int idx = 0; idx < arguments.length; idx++) { checkArgPrimitive(arguments, idx); checkArgGroups(arguments, idx, inputTypes, PrimitiveGrouping.STRING_GROUP, PrimitiveGrouping.VOID_GROUP); PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory(); if (arguments[idx] instanceof ConstantObjectInspector && idx != 0) { Object constValue = ((ConstantObjectInspector) arguments[idx]).getWritableConstantValue(); if (!isConstantNullPatternContain && constValue == null) { isConstantNullPatternContain = true; } } else if (idx != 0 && isAllPatternsConstant) { isAllPatternsConstant = false; } converters[idx] = ObjectInspectorConverters.getConverter(arguments[idx], getOutputOI(inputType)); inputTypes[idx] = inputType; } return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
public UnionConverter(ObjectInspector inputOI, SettableUnionObjectInspector outputOI) { if (inputOI instanceof UnionObjectInspector) { this.inputOI = (UnionObjectInspector)inputOI; this.outputOI = outputOI; inputTagsOIs = this.inputOI.getObjectInspectors(); outputTagsOIs = outputOI.getObjectInspectors(); // If the output has some extra fields, set them to NULL in convert(). int minFields = Math.min(inputTagsOIs.size(), outputTagsOIs.size()); fieldConverters = new ArrayList<Converter>(minFields); for (int f = 0; f < minFields; f++) { fieldConverters.add(getConverter(inputTagsOIs.get(f), outputTagsOIs.get(f))); } // Create an empty output object which will be populated when convert() is invoked. output = outputOI.create(); } else if (!(inputOI instanceof VoidObjectInspector)) { throw new RuntimeException("Hive internal error: conversion of " + inputOI.getTypeName() + " to " + outputOI.getTypeName() + "not supported yet."); } }
partitionOI = getStructOI(partitionDeserializer); finalOI = (StructObjectInspector)ObjectInspectorConverters.getConvertedOI(partitionOI, tableOI); partTblObjectInspectorConverter = ObjectInspectorConverters.getConverter(partitionOI, finalOI); job.setInputFormat(HiveUtilities.getInputFormatClass(job, partition.getSd(), table)); HiveUtilities.verifyAndAddTransactionalProperties(job, partition.getSd()); ObjectInspector fieldOI = fieldRef.getFieldObjectInspector(); TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(fieldOI.getTypeName()); selectedColumnObjInspectors.get(i).getTypeName(), selectedColumnObjInspectors.get(i).getClass().getName(), selectedColumnTypes.get(i).toString(),
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentException("Invalid number of arguments."); } converterArg0 = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableStringObjectInspector); converterArg1 = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.writableStringObjectInspector); return ObjectInspectorFactory .getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector); }
protected void getStringConverter(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { textConverters[i] = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentException(opName + " requires two arguments."); if (!FunctionRegistry.isNumericType(baseOI.getTypeInfo())) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + "numeric type, but " + baseOI.getTypeName() + " is found"); if (!FunctionRegistry.isNumericType(powerOI.getTypeInfo())) { throw new UDFArgumentTypeException(1, "The " + GenericUDFUtils.getOrdinal(2) + " argument of " + opName + " is expected to a " baseConverter = ObjectInspectorConverters.getConverter(baseOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); powerConverter = ObjectInspectorConverters.getConverter(powerOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); return resultOI;
protected void obtainTimestampConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); ObjectInspector outOi; switch (inputType) { case STRING: case VARCHAR: case CHAR: case TIMESTAMP: case DATE: case TIMESTAMPLOCALTZ: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType); } outOi = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector; converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi); inputTypes[i] = inputType; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { for (int idx = 0; idx < Math.min(arguments.length, 3); ++idx) { if (arguments[idx].getCategory() != Category.PRIMITIVE || PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory()) != PrimitiveGrouping.STRING_GROUP) { throw new UDFArgumentException("All argument should be string/character type"); } } soi_text = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.javaStringObjectInspector); if (arguments.length > 1) { soi_de1 = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } if (arguments.length > 2) { soi_de2 = ObjectInspectorConverters.getConverter(arguments[2], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } return ObjectInspectorFactory.getStandardMapObjectInspector( PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector); }
protected void obtainDoubleConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentException(opName + " requires two arguments."); Category category = arguments[i].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( deriveResultTypeInfo()); converterLeft = ObjectInspectorConverters.getConverter(leftOI, resultOI); converterRight = ObjectInspectorConverters.getConverter(rightOI, resultOI);