use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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()));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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()));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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()));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFPrintf method testCharVarcharArgs.
@Test
public void testCharVarcharArgs() throws HiveException {
GenericUDFPrintf udf = new GenericUDFPrintf();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(5)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)) };
HiveCharWritable argChar = new HiveCharWritable();
argChar.set("hello");
HiveVarcharWritable argVarchar = new HiveVarcharWritable();
argVarchar.set("world");
DeferredObject[] args = { new DeferredJavaObject(new Text("1st: %s, 2nd: %s")), new DeferredJavaObject(argChar), new DeferredJavaObject(argVarchar) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi);
Text res = (Text) udf.evaluate(args);
Assert.assertEquals("1st: hello, 2nd: world", res.toString());
}
Aggregations