Search in sources :

Example 41 with HiveVarcharWritable

use of org.apache.hadoop.hive.serde2.io.HiveVarcharWritable in project hive by apache.

the class TestGenericUDFOPPlus method testVarcharPlusInt.

@Test
public void testVarcharPlusInt() throws HiveException {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    // Short
    HiveVarcharWritable left = new HiveVarcharWritable();
    left.set("123");
    IntWritable right = new IntWritable(456);
    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(579.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) 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 42 with HiveVarcharWritable

use of org.apache.hadoop.hive.serde2.io.HiveVarcharWritable in project hive by apache.

the class TestGenericUDFFloor method testVarchar.

@Test
public void testVarchar() throws HiveException {
    GenericUDFFloor udf = new GenericUDFFloor();
    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.longTypeInfo, oi.getTypeInfo());
    LongWritable res = (LongWritable) udf.evaluate(args);
    Assert.assertEquals(32300L, 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) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) 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) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Aggregations

HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)37 Text (org.apache.hadoop.io.Text)22 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)20 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)18 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)17 IntWritable (org.apache.hadoop.io.IntWritable)16 Test (org.junit.Test)16 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)15 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)15 BytesWritable (org.apache.hadoop.io.BytesWritable)14 LongWritable (org.apache.hadoop.io.LongWritable)13 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)12 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)12 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)12 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)11 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)11 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)11 FloatWritable (org.apache.hadoop.io.FloatWritable)11 ArrayList (java.util.ArrayList)10 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)10