Search in sources :

Example 1 with CompatLevel

use of org.apache.hive.common.HiveCompat.CompatLevel in project hive by apache.

the class GenericUDFBaseNumeric method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentException(opName + " requires two arguments.");
    }
    for (int i = 0; i < 2; i++) {
        Category category = arguments[i].getCategory();
        if (category != Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of " + opName + "  is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found");
        }
    }
    // we have access to these values in the map/reduce tasks.
    if (confLookupNeeded) {
        CompatLevel compatLevel = HiveCompat.getCompatLevel(SessionState.get().getConf());
        ansiSqlArithmetic = compatLevel.ordinal() > CompatLevel.HIVE_0_12.ordinal();
        confLookupNeeded = false;
    }
    leftOI = (PrimitiveObjectInspector) arguments[0];
    rightOI = (PrimitiveObjectInspector) arguments[1];
    resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(deriveResultTypeInfo());
    converterLeft = ObjectInspectorConverters.getConverter(leftOI, resultOI);
    converterRight = ObjectInspectorConverters.getConverter(rightOI, resultOI);
    return resultOI;
}
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) CompatLevel(org.apache.hive.common.HiveCompat.CompatLevel) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 2 with CompatLevel

use of org.apache.hive.common.HiveCompat.CompatLevel in project hive by apache.

the class GenericUDFBaseArithmetic method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentException(getClass().getSimpleName() + " requires two arguments.");
    }
    // Lookup values needed for numeric arithmetic UDFs
    if (confLookupNeeded) {
        CompatLevel compatLevel = HiveCompat.getCompatLevel(SessionState.get().getConf());
        ansiSqlArithmetic = compatLevel.ordinal() > CompatLevel.HIVE_0_12.ordinal();
        confLookupNeeded = false;
    }
    // Determine if we are dealing with a numeric or date arithmetic operation
    boolean isDateTimeOp = false;
    for (int idx = 0; idx < 2; ++idx) {
        switch(((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory()) {
            case DATE:
            case TIMESTAMP:
            case INTERVAL_YEAR_MONTH:
            case INTERVAL_DAY_TIME:
                isDateTimeOp = true;
                break;
            default:
                break;
        }
    }
    if (isDateTimeOp) {
        arithmeticOperation = instantiateDTIUDF();
    } else {
        GenericUDFBaseNumeric numericUDF = instantiateNumericUDF();
        // Set values needed for numeric arithmetic UDFs
        numericUDF.setAnsiSqlArithmetic(ansiSqlArithmetic);
        numericUDF.setConfLookupNeeded(confLookupNeeded);
        arithmeticOperation = numericUDF;
    }
    return arithmeticOperation.initialize(arguments);
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) CompatLevel(org.apache.hive.common.HiveCompat.CompatLevel) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Aggregations

UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)2 CompatLevel (org.apache.hive.common.HiveCompat.CompatLevel)2 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)1 Category (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category)1 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)1 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)1