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; }
protected void checkIfPrimitive(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + argOrder + " argument, got " + oiCat); } }
@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; }
@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 != 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[0].getTypeName().equals("boolean")) { throw new UDFArgumentTypeException(0, "First argument for BETWEEN should be boolean type"); } egt.initialize(new ObjectInspector[] {arguments[1], arguments[2]}); elt.initialize(new ObjectInspector[] {arguments[1], arguments[3]}); argumentOIs = arguments; return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
@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( "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; }
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; }
@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 != 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); }
protected void checkIfPrimitive(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + argOrder + " argument, got " + oiCat); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (!arguments[0].getTypeName().equals("boolean")) { throw new UDFArgumentTypeException(0, "First argument for BETWEEN should be boolean type"); } egt.initialize(new ObjectInspector[] {arguments[1], arguments[2]}); elt.initialize(new ObjectInspector[] {arguments[1], arguments[3]}); argumentOIs = arguments; return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
@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 != 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; }
if (arguments[i].getCategory() == ObjectInspector.Category.PRIMITIVE) { PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) arguments[i]); throw new UDFArgumentTypeException(i, "The argument of function should be \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[i].getTypeName() + "\" is found"); if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The argument of function should be primative" + ", but \"" + arguments[i].getTypeName() + "\" is found");
@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; }
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");
protected void checkArgPrimitive(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + getArgOrder(i) + " argument, got " + oiCat); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentTypeException { argumentOIs = arguments; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); for (int i = 0; i + 1 < arguments.length; i += 2) { if (!arguments[i].getTypeName().equals(serdeConstants.BOOLEAN_TYPE_NAME)) { throw new UDFArgumentTypeException(i, "\"" + serdeConstants.BOOLEAN_TYPE_NAME + "\" is expected after WHEN, " + "but \"" + arguments[i].getTypeName() + "\" is found"); } if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expressions after THEN should have the same type: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } if (arguments.length % 2 == 1) { int i = arguments.length - 2; if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expression after ELSE should have the same type as those after THEN: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } return returnOIResolver.get(); }