use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class GenericUDFMonthsBetween method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 2, 3);
checkArgPrimitive(arguments, 0);
checkArgPrimitive(arguments, 1);
if (arguments.length == 3) {
if (arguments[2] instanceof ConstantObjectInspector) {
isRoundOffNeeded = getConstantBooleanValue(arguments, 2);
}
}
// the function should support both short date and full timestamp format
// time part of the timestamp should not be skipped
checkArgGroups(arguments, 0, tsInputTypes, STRING_GROUP, DATE_GROUP);
checkArgGroups(arguments, 1, tsInputTypes, STRING_GROUP, DATE_GROUP);
checkArgGroups(arguments, 0, dtInputTypes, STRING_GROUP, DATE_GROUP);
checkArgGroups(arguments, 1, dtInputTypes, STRING_GROUP, DATE_GROUP);
obtainTimestampConverter(arguments, 0, tsInputTypes, tsConverters);
obtainTimestampConverter(arguments, 1, tsInputTypes, tsConverters);
obtainDateConverter(arguments, 0, dtInputTypes, dtConverters);
obtainDateConverter(arguments, 1, dtInputTypes, dtConverters);
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
return outputOI;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestStreamingAvg method avgDouble.
public void avgDouble(Iterator<Double> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Double> outVals) throws HiveException {
GenericUDAFAverage fnR = new GenericUDAFAverage();
TypeInfo[] inputTypes = { TypeInfoFactory.doubleTypeInfo };
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
DoubleWritable[] in = new DoubleWritable[1];
in[0] = new DoubleWritable();
TestStreamingSum._agg(fnR, inputTypes, inVals, TypeHandler.DoubleHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestStreamingSum method sumDouble.
public void sumDouble(Iterator<Double> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Double> outVals) throws HiveException {
GenericUDAFSum fnR = new GenericUDAFSum();
TypeInfo[] inputTypes = { TypeInfoFactory.doubleTypeInfo };
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
DoubleWritable[] in = new DoubleWritable[1];
in[0] = new DoubleWritable();
_agg(fnR, inputTypes, inVals, TypeHandler.DoubleHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFAbs method testDouble.
public void testDouble() throws HiveException {
GenericUDFAbs udf = new GenericUDFAbs();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new DoubleWritable(107.78));
DeferredObject[] args = { valueObj };
DoubleWritable output = (DoubleWritable) udf.evaluate(args);
assertEquals("abs() test for Double failed ", 107.78, output.get());
valueObj = new DeferredJavaObject(new DoubleWritable(-107.78));
args[0] = valueObj;
output = (DoubleWritable) udf.evaluate(args);
assertEquals("abs() test for Double failed ", 107.78, output.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFPower method testDoublePowerLong.
@Test
public void testDoublePowerLong() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
DoubleWritable left = new DoubleWritable(4.5);
LongWritable right = new LongWritable(4);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(4.5 * 4.5 * 4.5 * 4.5), new Double(res.get()));
}
Aggregations