use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector in project hive by apache.
the class MaskTransformer method getCharArg.
int getCharArg(ObjectInspector[] arguments, int index, int defaultValue) {
int ret = defaultValue;
ObjectInspector arg = (arguments != null && arguments.length > index) ? arguments[index] : null;
if (arg != null) {
if (arg instanceof WritableConstantIntObjectInspector) {
IntWritable value = ((WritableConstantIntObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = value.get();
}
} else if (arg instanceof WritableConstantLongObjectInspector) {
LongWritable value = ((WritableConstantLongObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = (int) value.get();
}
} else if (arg instanceof WritableConstantShortObjectInspector) {
ShortWritable value = ((WritableConstantShortObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = value.get();
}
} else if (arg instanceof ConstantObjectInspector) {
Object value = ((ConstantObjectInspector) arg).getWritableConstantValue();
if (value != null) {
String strValue = value.toString();
if (strValue != null && strValue.length() > 0) {
ret = strValue.charAt(0);
}
}
}
}
return ret;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector in project hive by apache.
the class GenericUDFRound method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 1 || arguments.length > 2) {
throw new UDFArgumentLengthException("ROUND requires one or two argument, got " + arguments.length);
}
if (arguments[0].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0, "ROUND input only takes primitive types, got " + arguments[0].getTypeName());
}
inputOI = (PrimitiveObjectInspector) arguments[0];
if (arguments.length == 2) {
if (arguments[1].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(1, "ROUND second argument only takes primitive types, got " + arguments[1].getTypeName());
}
PrimitiveObjectInspector scaleOI = (PrimitiveObjectInspector) arguments[1];
switch(scaleOI.getPrimitiveCategory()) {
case VOID:
break;
case BYTE:
if (!(scaleOI instanceof WritableConstantByteObjectInspector)) {
throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes constant");
}
scale = ((WritableConstantByteObjectInspector) scaleOI).getWritableConstantValue().get();
break;
case SHORT:
if (!(scaleOI instanceof WritableConstantShortObjectInspector)) {
throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes constant");
}
scale = ((WritableConstantShortObjectInspector) scaleOI).getWritableConstantValue().get();
break;
case INT:
if (!(scaleOI instanceof WritableConstantIntObjectInspector)) {
throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes constant");
}
scale = ((WritableConstantIntObjectInspector) scaleOI).getWritableConstantValue().get();
break;
case LONG:
if (!(scaleOI instanceof WritableConstantLongObjectInspector)) {
throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes constant");
}
long l = ((WritableConstantLongObjectInspector) scaleOI).getWritableConstantValue().get();
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new UDFArgumentException(getFuncName().toUpperCase() + " scale argument out of allowed range");
}
scale = (int) l;
break;
default:
throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes integer constant");
}
}
inputType = inputOI.getPrimitiveCategory();
ObjectInspector outputOI = null;
switch(inputType) {
case DECIMAL:
DecimalTypeInfo inputTypeInfo = (DecimalTypeInfo) inputOI.getTypeInfo();
DecimalTypeInfo typeInfo = getOutputTypeInfo(inputTypeInfo, scale);
outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
break;
case VOID:
case BYTE:
case SHORT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType);
break;
case STRING:
case VARCHAR:
case CHAR:
outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.DOUBLE);
converterFromString = ObjectInspectorConverters.getConverter(inputOI, outputOI);
break;
default:
throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for ROUND function. Got " + inputType.name());
}
return outputOI;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector in project hive by apache.
the class MaskTransformer method getIntArg.
int getIntArg(ObjectInspector[] arguments, int index, int defaultValue) {
int ret = defaultValue;
ObjectInspector arg = (arguments != null && arguments.length > index) ? arguments[index] : null;
if (arg != null) {
if (arg instanceof WritableConstantIntObjectInspector) {
IntWritable value = ((WritableConstantIntObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = value.get();
}
} else if (arg instanceof WritableConstantLongObjectInspector) {
LongWritable value = ((WritableConstantLongObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = (int) value.get();
}
} else if (arg instanceof WritableConstantShortObjectInspector) {
ShortWritable value = ((WritableConstantShortObjectInspector) arg).getWritableConstantValue();
if (value != null) {
ret = value.get();
}
} else if (arg instanceof ConstantObjectInspector) {
Object value = ((ConstantObjectInspector) arg).getWritableConstantValue();
if (value != null) {
String strValue = value.toString();
if (strValue != null && strValue.length() > 0) {
ret = Integer.parseInt(value.toString());
}
}
}
}
return ret;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector in project hive by apache.
the class GenericUDFGrouping method initialize.
@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;
}
Aggregations