Search in sources :

Example 36 with TypeInfoFactory.getDecimalTypeInfo

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

the class TestGenericUDFOPMod method testDecimalModDecimal.

@Test
public void testDecimalModDecimal() throws HiveException {
    GenericUDFOPMod udf = new GenericUDFOPMod();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(3, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(4, 2), oi.getTypeInfo());
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 37 with TypeInfoFactory.getDecimalTypeInfo

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

the class TestGenericUDFPosMod method testDecimalPosModDecimalSameParams.

@Test
public void testDecimalPosModDecimalSameParams() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(5, 2), oi.getTypeInfo());
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 38 with TypeInfoFactory.getDecimalTypeInfo

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

the class TestGenericUDFPosMod method testPosModByZero8.

@Test
public void testPosModByZero8() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    // Decimal
    HiveDecimalWritable dec1 = new HiveDecimalWritable(HiveDecimal.create("4.5"));
    HiveDecimalWritable dec2 = new HiveDecimalWritable(HiveDecimal.create("0"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(2, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(1, 0)) };
    DeferredObject[] args = { new DeferredJavaObject(dec1), new DeferredJavaObject(dec2) };
    udf.initialize(inputOIs);
    HiveDecimalWritable dec3 = (HiveDecimalWritable) udf.evaluate(args);
    Assert.assertNull(dec3);
}
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) Test(org.junit.Test)

Example 39 with TypeInfoFactory.getDecimalTypeInfo

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

the class TestGenericUDFPosMod method testDecimalPosModDecimal.

@Test
public void testDecimalPosModDecimal() throws HiveException {
    GenericUDFPosMod udf = new GenericUDFPosMod();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(3, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(5, 2), oi.getTypeInfo());
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 40 with TypeInfoFactory.getDecimalTypeInfo

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

the class TestGenericUDFPrintf method testDecimalArgs.

@Test
public void testDecimalArgs() throws HiveException {
    GenericUDFPrintf udf = new GenericUDFPrintf();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(3, 2)) };
    HiveDecimalWritable argDec1 = new HiveDecimalWritable();
    argDec1.set(HiveDecimal.create("234.789"));
    HiveDecimalWritable argDec2 = new HiveDecimalWritable();
    argDec2.set(HiveDecimal.create("3.5"));
    DeferredObject[] args = { new DeferredJavaObject(new Text("1st: %s, 2nd: %s")), new DeferredJavaObject(argDec1), new DeferredJavaObject(argDec2) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi);
    Text res = (Text) udf.evaluate(args);
    Assert.assertEquals("1st: 234.79, 2nd: 3.5", res.toString());
}
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) Text(org.apache.hadoop.io.Text) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)38 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)38 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)27 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)25 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)25 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)11 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)7 LongWritable (org.apache.hadoop.io.LongWritable)5 BaseScalarUdfTest (org.apache.hadoop.hive.ql.testutil.BaseScalarUdfTest)3 IntWritable (org.apache.hadoop.io.IntWritable)3 HashMap (java.util.HashMap)2 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)2 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)2 SearchArgument (org.apache.hadoop.hive.ql.io.sarg.SearchArgument)2 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)2 MessageType (org.apache.parquet.schema.MessageType)2 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)1 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)1 GenericUDFAbs (org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs)1