Search in sources :

Example 41 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFPosMod method testPosModByZero5.

@Test
public void testPosModByZero5() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    // Float
    FloatWritable f1 = new FloatWritable(4.5f);
    FloatWritable f2 = new FloatWritable(0.0f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
    udf.initialize(inputOIs);
    FloatWritable f3 = (FloatWritable) udf.evaluate(args);
    Assert.assertNull(f3);
}
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) Test(org.junit.Test)

Example 42 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFPosMod method testPosModByZero1.

@Test
public void testPosModByZero1() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    // Byte
    ByteWritable b1 = new ByteWritable((byte) 4);
    ByteWritable b2 = new ByteWritable((byte) 0);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(b1), new DeferredJavaObject(b2) };
    udf.initialize(inputOIs);
    ByteWritable b3 = (ByteWritable) udf.evaluate(args);
    Assert.assertNull(b3);
}
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) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 43 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFPosMod method testPosModByZero2.

@Test
public void testPosModByZero2() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    // Short
    ShortWritable s1 = new ShortWritable((short) 4);
    ShortWritable s2 = new ShortWritable((short) 0);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(s1), new DeferredJavaObject(s2) };
    udf.initialize(inputOIs);
    ShortWritable s3 = (ShortWritable) udf.evaluate(args);
    Assert.assertNull(s3);
}
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) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) Test(org.junit.Test)

Example 44 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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()));
}
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) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 45 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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()));
}
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)700 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)299 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)261 Test (org.junit.Test)241 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)163 ArrayList (java.util.ArrayList)159 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)159 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)107 Text (org.apache.hadoop.io.Text)103 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)89 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)75 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)73 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)66 IntWritable (org.apache.hadoop.io.IntWritable)65 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)58 LongWritable (org.apache.hadoop.io.LongWritable)54 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)53 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)53 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)51 BytesWritable (org.apache.hadoop.io.BytesWritable)51