use of org.apache.hadoop.io.IntWritable in project hive by apache.
the class TestGenericUDFInternalInterval method testDayIntervalConstant.
@Test
public void testDayIntervalConstant() throws Exception {
try (GenericUDFInternalInterval udf = new GenericUDFInternalInterval()) {
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(HiveParser.TOK_INTERVAL_DAY_LITERAL)), PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(3)) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
ConstantObjectInspector coi = (ConstantObjectInspector) oi;
HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) coi.getWritableConstantValue();
Assert.assertEquals(3, res.getHiveIntervalDayTime().getDays());
}
}
use of org.apache.hadoop.io.IntWritable 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.io.IntWritable in project hive by apache.
the class TestGenericUDFOPDivide method testVarcharDivideInt.
@Test
public void testVarcharDivideInt() throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
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(123.0 / 456.0), new Double(res.get()));
}
use of org.apache.hadoop.io.IntWritable in project hive by apache.
the class TestGenericUDFBRound method testDecimal.
@Test
public void testDecimal() throws HiveException {
GenericUDFBRound udf = new GenericUDFBRound();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector;
IntWritable scale = new IntWritable(0);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, scale);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runDecimal(2.5, scale, 2.0, udf);
runDecimal(3.5, scale, 4.0, udf);
runDecimal(2.49, scale, 2.0, udf);
runDecimal(3.49, scale, 3.0, udf);
runDecimal(2.51, scale, 3.0, udf);
runDecimal(3.51, scale, 4.0, udf);
runDecimal(2.4, scale, 2.0, udf);
runDecimal(3.4, scale, 3.0, udf);
runDecimal(2.6, scale, 3.0, udf);
runDecimal(3.6, scale, 4.0, udf);
}
use of org.apache.hadoop.io.IntWritable in project hive by apache.
the class TestGenericUDFBRound method testDoubleScaleMinus1.
@Test
public void testDoubleScaleMinus1() throws HiveException {
GenericUDFBRound udf = new GenericUDFBRound();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
IntWritable scale = new IntWritable(-1);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, scale);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runDouble(55.0, scale, 60.0, udf);
runDouble(45.0, scale, 40.0, udf);
runDouble(54.9, scale, 50.0, udf);
runDouble(44.9, scale, 40.0, udf);
runDouble(55.1, scale, 60.0, udf);
runDouble(45.1, scale, 50.0, udf);
runDouble(-55.0, scale, -60.0, udf);
runDouble(-45.0, scale, -40.0, udf);
runDouble(-54.9, scale, -50.0, udf);
runDouble(-44.9, scale, -40.0, udf);
runDouble(-55.1, scale, -60.0, udf);
runDouble(-45.1, scale, -50.0, udf);
}
Aggregations