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;
}
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);
}
Aggregations