Search in sources :

Example 61 with UDFArgumentException

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

the class GenericUDTFParseUrlTuple method initialize.

@Override
public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException {
    inputOIs = args;
    numCols = args.length - 1;
    if (numCols < 1) {
        throw new UDFArgumentException("parse_url_tuple() takes at least two arguments: " + "the url string and a part name");
    }
    for (int i = 0; i < args.length; ++i) {
        if (args[i].getCategory() != ObjectInspector.Category.PRIMITIVE || !args[i].getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) {
            throw new UDFArgumentException("parse_url_tuple()'s arguments have to be string type");
        }
    }
    seenErrors = false;
    pathParsed = false;
    url = null;
    p = null;
    lastKey = null;
    paths = new String[numCols];
    partnames = new PARTNAME[numCols];
    cols = new Text[numCols];
    retCols = new Text[numCols];
    nullCols = new Object[numCols];
    for (int i = 0; i < numCols; ++i) {
        cols[i] = new Text();
        retCols[i] = cols[i];
        nullCols[i] = null;
    }
    // construct output object inspector
    ArrayList<String> fieldNames = new ArrayList<String>(numCols);
    ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(numCols);
    for (int i = 0; i < numCols; ++i) {
        // column name can be anything since it will be named by UDTF as clause
        fieldNames.add("c" + i);
        // all returned type will be Text
        fieldOIs.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    }
    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text)

Example 62 with UDFArgumentException

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

the class TestGenericUDFGreatest method testOneArg.

@Test
public void testOneArg() throws HiveException {
    @SuppressWarnings("resource") GenericUDFGreatest udf = new GenericUDFGreatest();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI1 };
    UDFArgumentException ex = null;
    try {
        udf.initialize(arguments);
    } catch (UDFArgumentException e) {
        ex = e;
    }
    assertNotNull("greatest() test ", ex);
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Test(org.junit.Test)

Example 63 with UDFArgumentException

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

the class TestGenericUDFDate method testVoidToDate.

@Test
public void testVoidToDate() throws HiveException {
    GenericUDFDate udf = new GenericUDFDate();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject[] args = { new DeferredJavaObject(null) };
    DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
    // Try with null VOID
    assertNull("to_date() with null DATE ", output);
    // Try with erroneously generated VOID
    DeferredObject[] junkArgs = { new DeferredJavaObject(new Text("2015-11-22")) };
    try {
        udf.evaluate(junkArgs);
        fail("to_date() test with VOID non-null failed");
    } catch (UDFArgumentException udfae) {
        assertEquals("TO_DATE() received non-null object of VOID type", udfae.getMessage());
    }
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 64 with UDFArgumentException

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

the class GenericUDFBaseCompare method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentException(opName + " requires two arguments.");
    }
    argumentOIs = arguments;
    Category c1 = arguments[0].getCategory();
    Category c2 = arguments[1].getCategory();
    if (c1 != c2) {
        throw new UDFArgumentException("Type mismatch in " + opName + "(" + c1 + "," + c2 + ")");
    }
    if (!supportsCategory(c1)) {
        throw new UDFArgumentException(opName + " does not support " + c1 + " types");
    }
    switch(c1) {
        case PRIMITIVE:
            initForPrimitives(arguments[0], arguments[1]);
            break;
        case MAP:
        case STRUCT:
        case LIST:
            initForNonPrimitives(arguments[0], arguments[1]);
            break;
        default:
            throw new AssertionError("Missing init method for " + c1 + " types");
    }
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category)

Example 65 with UDFArgumentException

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

the class GenericUDFBaseUnary method initialize.

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

Aggregations

UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)72 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)31 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)27 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)24 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)18 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)11 ArrayList (java.util.ArrayList)9 Category (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category)7 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)7 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)6 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)6 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)6 Test (org.junit.Test)6 PrimitiveObjectInspectorConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter)5 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)5 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)3 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)3 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)3