use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFBRound method testDoubleScaleMinus1.
@Test
public void testDoubleScaleMinus1() throws HiveException {
GenericUDFBRound udf = new GenericUDFBRound();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
IntWritable scale = new IntWritable(-1);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, scale);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runDouble(55.0, scale, 60.0, udf);
runDouble(45.0, scale, 40.0, udf);
runDouble(54.9, scale, 50.0, udf);
runDouble(44.9, scale, 40.0, udf);
runDouble(55.1, scale, 60.0, udf);
runDouble(45.1, scale, 50.0, udf);
runDouble(-55.0, scale, -60.0, udf);
runDouble(-45.0, scale, -40.0, udf);
runDouble(-54.9, scale, -50.0, udf);
runDouble(-44.9, scale, -40.0, udf);
runDouble(-55.1, scale, -60.0, udf);
runDouble(-45.1, scale, -50.0, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFCbrt method testCbrt.
public void testCbrt() throws HiveException {
GenericUDFCbrt udf = new GenericUDFCbrt();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
ObjectInspector[] arguments = { valueOI0 };
udf.initialize(arguments);
runAndVerify(0.0, 0.0, udf);
runAndVerify(1.0, 1.0, udf);
runAndVerify(-1.0, -1.0, udf);
runAndVerify(27.0, 3.0, udf);
runAndVerify(-27.0, -3.0, udf);
runAndVerify(87860583272930481.0, 444561.0, udf);
runAndVerify(null, null, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFCeil method testDouble.
@Test
public void testDouble() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
DoubleWritable input = new DoubleWritable(32300.004747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
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(32301L, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFFloor method testDouble.
@Test
public void testDouble() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
DoubleWritable input = new DoubleWritable(32300.004747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
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(32300L, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class GenericUDFPower method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentException(opName + " requires two arguments.");
}
for (int i = 0; i < 2; i++) {
Category category = arguments[i].getCategory();
if (category != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found");
}
}
baseOI = (PrimitiveObjectInspector) arguments[0];
if (!FunctionRegistry.isNumericType(baseOI.getTypeInfo())) {
throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + "numeric type, but " + baseOI.getTypeName() + " is found");
}
powerOI = (PrimitiveObjectInspector) arguments[1];
if (!FunctionRegistry.isNumericType(powerOI.getTypeInfo())) {
throw new UDFArgumentTypeException(1, "The " + GenericUDFUtils.getOrdinal(2) + " argument of " + opName + " is expected to a " + "numeric type, but " + powerOI.getTypeName() + " is found");
}
baseConverter = ObjectInspectorConverters.getConverter(baseOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
powerConverter = ObjectInspectorConverters.getConverter(powerOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
return resultOI;
}
Aggregations