use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.
the class TestGenericUDFCeil method testLong.
@Test
public void testLong() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
LongWritable input = new LongWritable(3234747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(3234747L, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.
the class TestGenericUDFAbs method testLong.
@Test
public void testLong() throws HiveException {
GenericUDFAbs udf = new GenericUDFAbs();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new LongWritable(107L));
DeferredObject[] args = { valueObj };
LongWritable output = (LongWritable) udf.evaluate(args);
assertEquals("abs() test for LONG failed ", 107, output.get());
valueObj = new DeferredJavaObject(new LongWritable(-107L));
args[0] = valueObj;
output = (LongWritable) udf.evaluate(args);
assertEquals("abs() test for LONG failed ", 107, output.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.
the class TestStreamingMax method maxLong.
public void maxLong(Iterator<Long> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Long> outVals) throws HiveException {
GenericUDAFMax fnR = new GenericUDAFMax();
TypeInfo[] inputTypes = { TypeInfoFactory.longTypeInfo };
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
LongWritable[] in = new LongWritable[1];
in[0] = new LongWritable();
TestStreamingSum._agg(fnR, inputTypes, inVals, TypeHandler.LongHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector 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 at least 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];
// INT can happen in cases where grouping() is used without grouping sets, in all other cases it should be LONG.
if (!(arg1OI.getPrimitiveCategory() == PrimitiveCategory.INT || arg1OI.getPrimitiveCategory() == PrimitiveCategory.LONG)) {
throw new UDFArgumentTypeException(0, "The first argument to grouping() must be an int/long. Got: " + arg1OI.getPrimitiveCategory());
}
groupingIdOI = arg1OI;
indices = new int[arguments.length - 1];
for (int i = 1; i < arguments.length; i++) {
PrimitiveObjectInspector arg2OI = (PrimitiveObjectInspector) arguments[i];
if (!(arg2OI instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(i, "Must be a constant. Got: " + arg2OI.getClass().getSimpleName());
}
indices[i - 1] = PrimitiveObjectInspectorUtils.getInt(((ConstantObjectInspector) arguments[i]).getWritableConstantValue(), arg2OI);
}
return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.
the class GenericUDFFactorial method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 1, 1);
checkArgPrimitive(arguments, 0);
checkArgGroups(arguments, 0, inputTypes, NUMERIC_GROUP, VOID_GROUP);
obtainIntConverter(arguments, 0, inputTypes, converters);
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
return outputOI;
}
Aggregations