Search in sources :

Example 11 with UDFArgumentLengthException

use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.

the class GenericUDFMapKeys method initialize.

@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);
}
Also used : MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 12 with UDFArgumentLengthException

use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.

the class GenericUDFIn method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length < 2) {
        throw new UDFArgumentLengthException("The function IN requires at least two arguments, got " + arguments.length);
    }
    argumentOIs = arguments;
    // We want to use the ReturnObjectInspectorResolver because otherwise
    // ObjectInspectorUtils.compare() will return != for two objects that have
    // different object inspectors, e.g. 238 and "238". The ROIR will help convert
    // both values to a common type so that they can be compared reasonably.
    conversionHelper = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
    for (ObjectInspector oi : arguments) {
        if (!conversionHelper.update(oi)) {
            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++) {
                if (i != 1) {
                    sb.append(", ");
                }
                sb.append(arguments[i].getTypeName());
            }
            sb.append(")}");
            throw new UDFArgumentException(sb.toString());
        }
    }
    compareOI = conversionHelper.get();
    checkIfInSetConstant();
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
Also used : ReturnObjectInspectorResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils.ReturnObjectInspectorResolver) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)

Example 13 with UDFArgumentLengthException

use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.

the class GenericUDFSoundex method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException(getFuncName() + " requires 1 argument, got " + arguments.length);
    }
    checkIfPrimitive(arguments, 0, "1st");
    checkIfStringGroup(arguments, 0, "1st");
    getStringConverter(arguments, 0, "1st");
    ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    return outputOI;
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)

Example 14 with UDFArgumentLengthException

use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.

the class GenericUDFSplit method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentLengthException("The function SPLIT(s, regexp) takes exactly 2 arguments.");
    }
    converters = new ObjectInspectorConverters.Converter[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        converters[i] = ObjectInspectorConverters.getConverter(arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    }
    ObjectInspector rightArg = arguments[1];
    if (rightArg instanceof ConstantObjectInspector) {
        constPattern = Pattern.compile(((ConstantObjectInspector) rightArg).getWritableConstantValue().toString());
    }
    return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
}
Also used : ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) ObjectInspectorConverters(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)

Example 15 with UDFArgumentLengthException

use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.

the class GenericUDFMapValues method initialize.

@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);
}
Also used : MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Aggregations

UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)47 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)29 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)26 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)21 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)21 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)13 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)6 PrimitiveObjectInspectorConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter)5 TimestampConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.TimestampConverter)5 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)4 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)4 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)2 ObjectInspectorConverters (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters)2 HiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector)2 StringConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.StringConverter)2