use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFOPDivide method testByteDivideShort.
@Test
public void testByteDivideShort() throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
ByteWritable left = new ByteWritable((byte) 4);
ShortWritable right = new ShortWritable((short) 6);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.getDecimalTypeInfo(9, 6));
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("0.666667"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFOPMod method testModByZero1.
@Test
public void testModByZero1() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// 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);
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFInternalInterval method testDayInterval.
@Test
public void testDayInterval() throws Exception {
try (GenericUDFInternalInterval udf = new GenericUDFInternalInterval()) {
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(HiveParser.TOK_INTERVAL_DAY_LITERAL)), PrimitiveObjectInspectorFactory.writableStringObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(new ByteWritable((byte) 4)), new DeferredJavaObject(new Text("8")) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) udf.evaluate(args);
Assert.assertEquals(8, res.getHiveIntervalDayTime().getDays());
}
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFNullif method testNotSupportedArgumentMix.
@Test(expected = UDFArgumentException.class)
public void testNotSupportedArgumentMix() throws HiveException {
GenericUDFNullif udf = new GenericUDFNullif();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(new DateWritableV2(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
udf.initialize(inputOIs);
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFOPPlus method testBytePlusShort.
@Test
public void testBytePlusShort() throws HiveException {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
// Byte
ByteWritable left = new ByteWritable((byte) 4);
ShortWritable right = new ShortWritable((short) 6);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.shortTypeInfo);
ShortWritable res = (ShortWritable) udf.evaluate(args);
Assert.assertEquals(10, res.get());
}
Aggregations