use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.
the class TestStreamingAvg method avgHiveDecimal.
public void avgHiveDecimal(Iterator<HiveDecimal> inVals, int inSz, int numPreceding, int numFollowing, Iterator<HiveDecimal> outVals) throws HiveException {
GenericUDAFAverage fnR = new GenericUDAFAverage();
TypeInfo[] inputTypes = { TypeInfoFactory.decimalTypeInfo };
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector };
HiveDecimalWritable[] in = new HiveDecimalWritable[1];
in[0] = new HiveDecimalWritable();
TestStreamingSum._agg(fnR, inputTypes, inVals, TypeHandler.HiveDecimalHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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.ObjectInspector in project hive by apache.
the class AbstractTestGenericUDFOPNumeric method verifyReturnType.
protected void verifyReturnType(GenericUDF udf, String typeStr1, String typeStr2, String expectedTypeStr) throws HiveException {
// Lookup type infos for our input types and expected return type
PrimitiveTypeInfo type1 = TypeInfoFactory.getPrimitiveTypeInfo(typeStr1);
PrimitiveTypeInfo type2 = TypeInfoFactory.getPrimitiveTypeInfo(typeStr2);
PrimitiveTypeInfo expectedType = TypeInfoFactory.getPrimitiveTypeInfo(expectedTypeStr);
// Initialize UDF which will output the return type for the UDF.
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(type1), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(type2) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals("Return type for " + udf.getDisplayString(new String[] { typeStr1, typeStr2 }), expectedType, oi.getTypeInfo());
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.
the class TestGenericUDAFCorrelation method testCorr.
public void testCorr() throws HiveException {
GenericUDAFCorrelation corr = new GenericUDAFCorrelation();
GenericUDAFEvaluator eval1 = corr.getEvaluator(new TypeInfo[] { TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.doubleTypeInfo });
GenericUDAFEvaluator eval2 = corr.getEvaluator(new TypeInfo[] { TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.doubleTypeInfo });
ObjectInspector poi1 = eval1.init(GenericUDAFEvaluator.Mode.PARTIAL1, new ObjectInspector[] { PrimitiveObjectInspectorFactory.javaDoubleObjectInspector, PrimitiveObjectInspectorFactory.javaDoubleObjectInspector });
ObjectInspector poi2 = eval2.init(GenericUDAFEvaluator.Mode.PARTIAL1, new ObjectInspector[] { PrimitiveObjectInspectorFactory.javaDoubleObjectInspector, PrimitiveObjectInspectorFactory.javaDoubleObjectInspector });
GenericUDAFEvaluator.AggregationBuffer buffer1 = eval1.getNewAggregationBuffer();
eval1.iterate(buffer1, new Object[] { 100d, 200d });
eval1.iterate(buffer1, new Object[] { 150d, 210d });
eval1.iterate(buffer1, new Object[] { 200d, 220d });
Object object1 = eval1.terminatePartial(buffer1);
GenericUDAFEvaluator.AggregationBuffer buffer2 = eval2.getNewAggregationBuffer();
eval2.iterate(buffer2, new Object[] { 250d, 230d });
eval2.iterate(buffer2, new Object[] { 250d, 240d });
eval2.iterate(buffer2, new Object[] { 300d, 250d });
eval2.iterate(buffer2, new Object[] { 350d, 260d });
Object object2 = eval2.terminatePartial(buffer2);
ObjectInspector coi = eval2.init(GenericUDAFEvaluator.Mode.FINAL, new ObjectInspector[] { poi1 });
GenericUDAFEvaluator.AggregationBuffer buffer3 = eval2.getNewAggregationBuffer();
eval2.merge(buffer3, object1);
eval2.merge(buffer3, object2);
Object result = eval2.terminate(buffer3);
assertEquals("0.987829161147262", String.valueOf(result));
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.
the class TestGenericUDFAbs method testFloat.
public void testFloat() throws HiveException {
GenericUDFAbs udf = new GenericUDFAbs();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new FloatWritable(107.78f));
DeferredObject[] args = { valueObj };
DoubleWritable output = (DoubleWritable) udf.evaluate(args);
// Make sure flow and double equality compare works
assertTrue("abs() test for Float failed ", Math.abs(107.78 - output.get()) < 0.0001);
valueObj = new DeferredJavaObject(new FloatWritable(-107.78f));
args[0] = valueObj;
output = (DoubleWritable) udf.evaluate(args);
assertTrue("abs() test for Float failed ", Math.abs(107.78 - output.get()) < 0.0001);
}
Aggregations