Refine search
@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 { int numFields = arguments.length; if (numFields % 2 == 1) { throw new UDFArgumentLengthException( "NAMED_STRUCT expects an even number of arguments."); } ret = new Object[numFields / 2]; ArrayList<String> fname = new ArrayList<String>(numFields / 2); ArrayList<ObjectInspector> retOIs = new ArrayList<ObjectInspector>(numFields / 2); for (int f = 0; f < numFields; f+=2) { if (!(arguments[f] instanceof ConstantObjectInspector)) { throw new UDFArgumentTypeException(f, "Even arguments" + " to NAMED_STRUCT must be a constant STRING." + arguments[f].toString()); } ConstantObjectInspector constantOI = (ConstantObjectInspector)arguments[f]; fname.add(constantOI.getWritableConstantValue().toString()); retOIs.add(arguments[f + 1]); } StructObjectInspector soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, retOIs); return soi; }
@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 { int numFields = arguments.length; if (numFields % 2 == 1) { throw new UDFArgumentLengthException( "NAMED_STRUCT expects an even number of arguments."); } ret = new Object[numFields / 2]; ArrayList<String> fname = new ArrayList<String>(numFields / 2); ArrayList<ObjectInspector> retOIs = new ArrayList<ObjectInspector>(numFields / 2); for (int f = 0; f < numFields; f+=2) { if (!(arguments[f] instanceof ConstantObjectInspector)) { throw new UDFArgumentTypeException(f, "Even arguments" + " to NAMED_STRUCT must be a constant STRING." + arguments[f].toString()); } ConstantObjectInspector constantOI = (ConstantObjectInspector)arguments[f]; fname.add(constantOI.getWritableConstantValue().toString()); retOIs.add(arguments[f + 1]); } StructObjectInspector soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, retOIs); return soi; }
@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( "grouping() requires 2 argument, got " + arguments.length); } if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be primitive"); } PrimitiveObjectInspector arg1OI = (PrimitiveObjectInspector) arguments[0]; if (arg1OI.getPrimitiveCategory() != PrimitiveCategory.INT) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be an integer"); } groupingIdOI = (IntObjectInspector) arguments[0]; PrimitiveObjectInspector arg2OI = (PrimitiveObjectInspector) arguments[1]; if (!(arg2OI instanceof WritableConstantIntObjectInspector)) { throw new UDFArgumentTypeException(1, "The second argument to grouping() must be a constant"); } index = ((WritableConstantIntObjectInspector)arg2OI).getWritableConstantValue().get(); return PrimitiveObjectInspectorFactory.writableByteObjectInspector; }
@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 != 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( "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 { HiveConf conf = SessionState.getSessionConf(); if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST)) { throw new RuntimeException("this UDF is only available in testmode"); } if (arguments.length != 1) { throw new UDFArgumentLengthException("ASSERT_TRUE_OOM() expects one argument."); } if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Argument to ASSERT_TRUE_OOM() should be primitive."); } conditionConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); return PrimitiveObjectInspectorFactory.writableVoidObjectInspector; }
@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 != 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 != 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("Decode() requires exactly two arguments"); throw new UDFArgumentTypeException(0, "The first argument to Decode() must be primitive"); bytesOI = (VoidObjectInspector) arguments[0]; } else { throw new UDFArgumentTypeException(0, "The first argument to Decode() must be binary"); throw new UDFArgumentTypeException(1, "The second argument to Decode() must be primitive");
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "The function EWAH_BITMAP_EMPTY(b) takes exactly 1 argument"); } if (arguments[0].getCategory().equals(Category.LIST)) { bitmapOI = (ListObjectInspector) arguments[0]; } else { throw new UDFArgumentTypeException(0, "\"" + Category.LIST.toString().toLowerCase() + "\" is expected at function EWAH_BITMAP_EMPTY, but \"" + arguments[0].getTypeName() + "\" is found"); } boolOI = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; return boolOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException("Encode() requires exactly two arguments"); } if (arguments[0].getCategory() != Category.PRIMITIVE || PrimitiveGrouping.STRING_GROUP != PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector)arguments[0]).getPrimitiveCategory())){ throw new UDFArgumentTypeException( 0, "The first argument to Encode() must be a string/varchar"); } stringOI = (PrimitiveObjectInspector) arguments[0]; if (arguments[1].getCategory() != Category.PRIMITIVE || PrimitiveGrouping.STRING_GROUP != PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector)arguments[1]).getPrimitiveCategory())){ throw new UDFArgumentTypeException( 1, "The second argument to Encode() must be a string/varchar"); } charsetOI = (PrimitiveObjectInspector) arguments[1]; // If the character set for encoding is constant, we can optimize that if (charsetOI instanceof ConstantObjectInspector){ String charSetName = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue().toString(); encoder = Charset.forName(charSetName).newEncoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); } result = new BytesWritable(); return (ObjectInspector) PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "InBloomFilter requires exactly 2 arguments but got " + arguments.length); } // Verify individual arguments if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The 1st argument must be a primitive type but " + arguments[0].getTypeName() + " was passed"); } if (((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) { throw new UDFArgumentTypeException(1, "The 2nd argument must be a binary type but " + arguments[1].getTypeName() + " was passed"); } valObjectInspector = arguments[0]; bloomFilterObjectInspector = arguments[1]; assert bloomFilterObjectInspector instanceof WritableBinaryObjectInspector; initializedBloomFilter = false; return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector; }
throw new UDFArgumentLengthException( "The function GET_SPLITS accepts 2 arguments."); } else if (!(arguments[0] instanceof StringObjectInspector)) { LOG.error("Got " + arguments[0].getTypeName() + " instead of string."); throw new UDFArgumentTypeException(0, "\"" + "string\" is expected at function GET_SPLITS, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } else if (!(arguments[1] instanceof IntObjectInspector)) { LOG.error("Got " + arguments[1].getTypeName() + " instead of int."); throw new UDFArgumentTypeException(1, "\"" + "int\" is expected at function GET_SPLITS, " + "but \"" + arguments[1].getTypeName() + "\" is found");
@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; }