use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testLongMinusDecimal.
@Test
public void testLongMinusDecimal() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
LongWritable left = new LongWritable(104);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(9, 4)) };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(24, 4), oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("-130.97"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector 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);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector in project hive by apache.
the class TestGenericUDFPower method testLongPowerDecimal.
@Test
public void testLongPowerDecimal() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
LongWritable left = new LongWritable(10);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("3.14"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(9, 4)) };
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(1380.3842646028852), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector in project hive by apache.
the class TestGenericUDFPrintf method testVarcharFormat.
@Test
public void testVarcharFormat() throws HiveException {
GenericUDFPrintf udf = new GenericUDFPrintf();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(5)) };
HiveCharWritable argChar = new HiveCharWritable();
argChar.set("hello");
HiveVarcharWritable formatVarchar = new HiveVarcharWritable();
formatVarchar.set("arg1=%s");
DeferredObject[] args = { new DeferredJavaObject(formatVarchar), new DeferredJavaObject(argChar) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi);
Text res = (Text) udf.evaluate(args);
Assert.assertEquals("arg1=hello", res.toString());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector 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());
}
Aggregations