@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "ASSERT_TRUE() expects one argument."); } if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Argument to ASSERT_TRUE() should be primitive."); } conditionConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); return PrimitiveObjectInspectorFactory.writableVoidObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "The function GenericUDFReflect2(arg0,method[,arg1[,arg2]...])" + " accepts 2 or more arguments."); if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(1, "The target instance should be a primitive type."); throw new UDFArgumentTypeException(1, "The method name should be string type."); throw new UDFArgumentTypeException(1, "The method name should be a constant."); targetOI.getPrimitiveCategory()).primitiveJavaClass; returnOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( typeEntry.primitiveCategory); returnObj = (Writable) returnOI.getPrimitiveWritableClass().newInstance(); } catch (Exception e) { throw new UDFArgumentException(e);
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException("The function MAP_KEYS only accepts one argument."); } else if (!(arguments[0] instanceof MapObjectInspector)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" is expected at function MAP_KEYS, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } mapOI = (MapObjectInspector) arguments[0]; ObjectInspector mapKeyOI = mapOI.getMapKeyObjectInspector(); return ObjectInspectorFactory.getStandardListObjectInspector(mapKeyOI); }
@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; }
/** * Initialize UDF */ @Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length == 0) { throw new UDFArgumentLengthException("At least one argument must be specified"); } if (!(arguments[0] instanceof StringObjectInspector)) { throw new UDFArgumentException("First argument must be a string"); } queryOI = (StringObjectInspector)arguments[0]; argumentsOI = arguments; return PrimitiveObjectInspectorFactory.javaStringObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException("Invalid number of arguments"); } conditionConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "The function IN requires at least two arguments, got " + arguments.length); StringBuilder sb = new StringBuilder(); sb.append("The arguments for IN should be the same type! Types are: {"); sb.append(arguments[0].getTypeName()); sb.append(" IN ("); for(int i=1; i<arguments.length; i++) { sb.append(", "); sb.append(arguments[i].getTypeName()); throw new UDFArgumentException(sb.toString());
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 1) { throw new UDFArgumentLengthException( "The function CAST as TIMESTAMP WITH LOCAL TIME ZONE requires at least one argument, got " + arguments.length); } try { argumentOI = (PrimitiveObjectInspector) arguments[0]; switch (argumentOI.getPrimitiveCategory()) { case CHAR: case VARCHAR: case STRING: case DATE: case TIMESTAMP: case TIMESTAMPLOCALTZ: break; default: throw new UDFArgumentException("CAST as TIMESTAMP WITH LOCAL TIME ZONE only allows" + "string/date/timestamp/timestamp with time zone types"); } } catch (ClassCastException e) { throw new UDFArgumentException( "The function CAST as TIMESTAMP WITH LOCAL TIME ZONE takes only primitive types"); } SettableTimestampLocalTZObjectInspector outputOI = (SettableTimestampLocalTZObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo); converter = new TimestampLocalTZConverter(argumentOI, outputOI); return outputOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "IN_FILE() accepts exactly 2 arguments."); } strObjectInspector = arguments[0]; fileObjectInspector = arguments[1]; if (!isTypeCompatible(strObjectInspector)) { throw new UDFArgumentTypeException(0, "The first " + "argument of function IN_FILE must be a string, " + "char or varchar but " + strObjectInspector.toString() + " was given."); } if (((PrimitiveObjectInspector) fileObjectInspector).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING || !ObjectInspectorUtils.isConstantObjectInspector(fileObjectInspector)) { throw new UDFArgumentTypeException(1, "The second " + "argument of IN_FILE() must be a constant string but " + fileObjectInspector.toString() + " was given."); } return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "datediff() requires 2 argument, got " + arguments.length); } inputConverter1 = checkArguments(arguments, 0); inputConverter2 = checkArguments(arguments, 1); inputType1 = ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory(); inputType2 = ((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory(); ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector; return outputOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "The operator NOT only accepts 1 argument."); } boi = (BooleanObjectInspector) arguments[0]; return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
} catch (UDFArgumentTypeException e) { throw new SemanticException(ErrorMsg.INVALID_ARGUMENT_TYPE.getMsg(expr .getChild(childrenBegin + e.getArgumentId()), e.getMessage()), e); } catch (UDFArgumentLengthException e) { throw new SemanticException(ErrorMsg.INVALID_ARGUMENT_LENGTH.getMsg( expr, e.getMessage()), e); } catch (UDFArgumentException e) { throw new SemanticException(ErrorMsg.INVALID_ARGUMENT.getMsg(expr, e .getMessage()), e);
public void testLevenshteinWrongLength() throws HiveException { @SuppressWarnings("resource") GenericUDFLevenshtein udf = new GenericUDFLevenshtein(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector; ObjectInspector[] arguments = { valueOI0 }; try { udf.initialize(arguments); assertTrue("levenshtein test. UDFArgumentLengthException is expected", false); } catch (UDFArgumentLengthException e) { assertEquals("levenshtein test", "levenshtein requires 2 argument(s), got 1", e.getMessage()); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "The function GenericUDFReflect2(arg0,method[,arg1[,arg2]...])" + " accepts 2 or more arguments."); if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(1, "The target instance should be a primitive type."); throw new UDFArgumentTypeException(1, "The method name should be string type."); throw new UDFArgumentTypeException(1, "The method name should be a constant."); targetOI.getPrimitiveCategory()).primitiveJavaClass; returnOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( typeEntry.primitiveCategory); returnObj = (Writable) returnOI.getPrimitiveWritableClass().newInstance(); } catch (Exception e) { throw new UDFArgumentException(e);
@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 { if (arguments.length < 2) { throw new UDFArgumentLengthException("The like any operator requires at least one pattern for matching, got " + (arguments.length - 1)); } inputTypes = new PrimitiveCategory[arguments.length]; converters = new Converter[arguments.length]; /**expects string and 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; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 1) { throw new UDFArgumentLengthException( "The function INTERVAL_DAY_TIME requires at least one argument, got " + arguments.length); } try { argumentOI = (PrimitiveObjectInspector) arguments[0]; } catch (ClassCastException e) { throw new UDFArgumentException( "The function INTERVAL_DAY_TIME takes only primitive types"); } tc = new HiveIntervalDayTimeConverter(argumentOI, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector); return PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector; }
@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 { if (arguments.length < 1) { throw new UDFArgumentLengthException( "The function CAST as DATE requires at least one argument, got " + arguments.length); } try { argumentOI = (PrimitiveObjectInspector) arguments[0]; PrimitiveCategory pc = argumentOI.getPrimitiveCategory(); PrimitiveGrouping pg = PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pc); switch (pg) { case DATE_GROUP: case STRING_GROUP: case VOID_GROUP: break; default: throw new UDFArgumentException( "CAST as DATE only allows date,string, or timestamp types"); } } catch (ClassCastException e) { throw new UDFArgumentException( "The function CAST as DATE takes only primitive types"); } dc = new DateConverter(argumentOI, PrimitiveObjectInspectorFactory.writableDateObjectInspector); return PrimitiveObjectInspectorFactory.writableDateObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "IN_FILE() accepts exactly 2 arguments."); } strObjectInspector = arguments[0]; fileObjectInspector = arguments[1]; if (!isTypeCompatible(strObjectInspector)) { throw new UDFArgumentTypeException(0, "The first " + "argument of function IN_FILE must be a string, " + "char or varchar but " + strObjectInspector.toString() + " was given."); } if (((PrimitiveObjectInspector) fileObjectInspector).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING || !ObjectInspectorUtils.isConstantObjectInspector(fileObjectInspector)) { throw new UDFArgumentTypeException(1, "The second " + "argument of IN_FILE() must be a constant string but " + fileObjectInspector.toString() + " was given."); } return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector; }