Search in sources :

Example 16 with TypeInfoFactory.doubleTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.

the class TestGenericUDFPower method testFloatPowerFloat.

@Test
public void testFloatPowerFloat() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    FloatWritable f1 = new FloatWritable(4.5f);
    FloatWritable f2 = new FloatWritable(-1.5f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(new Double(0.10475656017578482), new Double(res.get()));
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 17 with TypeInfoFactory.doubleTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.

the class TestGenericUDFPower method testDoulePowerDecimal.

@Test
public void testDoulePowerDecimal() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    DoubleWritable left = new DoubleWritable(-4.52);
    HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("3"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    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("Unexpected result", new Double(-4.52 * 4.52 * 4.52), new Double(res.get()), 1e-6);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 18 with TypeInfoFactory.doubleTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.

the class TestGenericUDFPower method testShortPowerFloat.

@Test
public void testShortPowerFloat() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    ShortWritable base = new ShortWritable((short) 23);
    FloatWritable power = new FloatWritable(-1.5f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(base), new DeferredJavaObject(power) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(new Double(0.009065844089438033), new Double(res.get()));
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) Test(org.junit.Test)

Example 19 with TypeInfoFactory.doubleTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.

the class TestGenericUDFPower method testDecimalPowerDecimal.

@Test
public void testDecimalPowerDecimal() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    HiveDecimalWritable left = new HiveDecimalWritable(HiveDecimal.create("14.5"));
    HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("-3.2"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(3, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    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(1.9214203800477838E-4), new Double(res.get()));
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 20 with TypeInfoFactory.doubleTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.

the class TestGenericUDFOPMultiply method testDoubleTimesLong.

@Test
public void testDoubleTimesLong() throws HiveException {
    GenericUDFOPMultiply udf = new GenericUDFOPMultiply();
    DoubleWritable left = new DoubleWritable(4.5);
    LongWritable right = new LongWritable(10);
    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(45.0), new Double(res.get()));
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)33 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)31 Test (org.junit.Test)30 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)29 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)29 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)29 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)10 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)7 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)7 LongWritable (org.apache.hadoop.io.LongWritable)6 IntWritable (org.apache.hadoop.io.IntWritable)5 ArrayList (java.util.ArrayList)4 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)4 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)3 FloatWritable (org.apache.hadoop.io.FloatWritable)3 Method (java.lang.reflect.Method)2 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)2 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)2 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)2 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)2