use of org.apache.hadoop.hive.serde2.io.DoubleWritable in project hive by apache.
the class TestUDFMath method testLog.
@Test
public void testLog() throws HiveException {
UDFLog udf = new UDFLog();
input = createDecimal("7.38905609893065");
DoubleWritable res = udf.evaluate(input);
Assert.assertEquals(2.0, res.get(), 0.000001);
res = udf.evaluate(createDecimal("3.0"), createDecimal("9.0"));
Assert.assertEquals(2.0, res.get(), 0.000001);
}
use of org.apache.hadoop.hive.serde2.io.DoubleWritable in project hive by apache.
the class TestGenericUDFOPPositive method testVarchar.
@Test
public void testVarchar() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
HiveVarchar vc = new HiveVarchar("32300.004747", 12);
HiveVarcharWritable input = new HiveVarcharWritable(vc);
VarcharTypeInfo inputTypeInfo = TypeInfoFactory.getVarcharTypeInfo(12);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(32300.004747), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.io.DoubleWritable in project hive by apache.
the class TestGenericUDFOPPositive method testString.
@Test
public void testString() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
Text input = new Text("32300.004747");
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(32300.004747), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.io.DoubleWritable in project hive by apache.
the class TestGenericUDFOPPositive method testChar.
@Test
public void testChar() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
HiveChar vc = new HiveChar("32300.004747", 12);
HiveCharWritable input = new HiveCharWritable(vc);
CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(32300.004747), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.io.DoubleWritable in project hive by apache.
the class TestGenericUDFPower method testVarcharPowerInt.
@Test
public void testVarcharPowerInt() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
HiveVarcharWritable left = new HiveVarcharWritable();
left.set("3.14");
IntWritable right = new IntWritable(2);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(3.14 * 3.14), new Double(res.get()));
}
Aggregations