use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector 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.ConstantObjectInspector in project hive by apache.
the class GenericUDFNamedStruct method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
int numFields = arguments.length;
if (numFields % 2 == 1) {
throw new UDFArgumentLengthException("NAMED_STRUCT expects an even number of arguments.");
}
ret = new Object[numFields / 2];
ArrayList<String> fname = new ArrayList<String>(numFields / 2);
ArrayList<ObjectInspector> retOIs = new ArrayList<ObjectInspector>(numFields / 2);
for (int f = 0; f < numFields; f += 2) {
if (!(arguments[f] instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(f, "Even arguments" + " to NAMED_STRUCT must be a constant STRING." + arguments[f].toString());
}
ConstantObjectInspector constantOI = (ConstantObjectInspector) arguments[f];
fname.add(constantOI.getWritableConstantValue().toString());
retOIs.add(arguments[f + 1]);
}
StructObjectInspector soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, retOIs);
return soi;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class GenericUDFNextDay method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 2, 2);
checkArgPrimitive(arguments, 0);
checkArgPrimitive(arguments, 1);
checkArgGroups(arguments, 0, inputTypes, STRING_GROUP, DATE_GROUP, VOID_GROUP);
checkArgGroups(arguments, 1, inputTypes, STRING_GROUP, VOID_GROUP);
obtainDateConverter(arguments, 0, inputTypes, converters);
obtainStringConverter(arguments, 1, inputTypes, converters);
if (arguments[1] instanceof ConstantObjectInspector) {
String dayOfWeek = getConstantStringValue(arguments, 1);
isDayOfWeekConst = true;
dayOfWeekIntConst = getIntDayOfWeek(dayOfWeek);
}
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
return outputOI;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class GenericUDFInternalInterval method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
// read operation mode
if (!(arguments[0] instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(0, getFuncName() + ": may only accept constant as first argument");
}
Integer operationMode = getConstantIntValue(arguments, 0);
if (operationMode == null) {
throw new UDFArgumentTypeException(0, "must supply operationmode");
}
processor = getProcessorMap().get(operationMode);
if (processor == null) {
throw new UDFArgumentTypeException(0, getFuncName() + ": unsupported operationMode: " + operationMode);
}
// check value argument
if (arguments[1].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(1, "The first argument to " + getFuncName() + " must be primitive");
}
inputOI = (PrimitiveObjectInspector) arguments[1];
PrimitiveCategory inputCategory = inputOI.getPrimitiveCategory();
if (!isValidInputCategory(inputCategory)) {
throw new UDFArgumentTypeException(1, "The second argument to " + getFuncName() + " must be from the string group or numeric group (except:float/double)");
}
if (arguments[1] instanceof ConstantObjectInspector) {
// return value as constant in case arg is constant
return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(processor.getTypeInfo(), processor.evaluate(getConstantStringValue(arguments, 1)));
} else {
return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(processor.getTypeInfo());
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class AccumuloRangeGenerator method getBinaryValue.
/**
* Attempts to construct the binary value from the given inspector. Falls back to UTF8 encoding
* when the value cannot be coerced into binary.
*
* @return Binary value when possible, utf8 otherwise
* @throws IOException
*/
protected Text getBinaryValue(ConstantObjectInspector objInspector) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (objInspector instanceof PrimitiveObjectInspector) {
LazyUtils.writePrimitive(out, objInspector.getWritableConstantValue(), (PrimitiveObjectInspector) objInspector);
} else {
return getUtf8Value(objInspector);
}
out.close();
return new Text(out.toByteArray());
}
Aggregations