use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector in project hive by apache.
the class TestGenericUDFOPPositive method testInt.
@Test
public void testInt() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
IntWritable input = new IntWritable(747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableIntObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.intTypeInfo, oi.getTypeInfo());
IntWritable res = (IntWritable) udf.evaluate(args);
Assert.assertEquals(747, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector in project hive by apache.
the class TestGenericUDFOPMultiply method testVarcharTimesInt.
@Test
public void testVarcharTimesInt() throws HiveException {
GenericUDFOPMultiply udf = new GenericUDFOPMultiply();
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 * 456), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector in project hive by apache.
the class TestGenericUDFNextDay method testNextDayErrorArg2.
public void testNextDayErrorArg2() throws HiveException {
@SuppressWarnings("resource") GenericUDFNextDay udf = new GenericUDFNextDay();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("UDFArgumentException expected", false);
} catch (UDFArgumentException e) {
assertEquals("next_day only takes STRING_GROUP, VOID_GROUP types as 2nd argument, got INT", e.getMessage());
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector in project hive by apache.
the class TestGenericUDFRpad method testRpad.
public void testRpad() throws HiveException {
GenericUDFRpad udf = new GenericUDFRpad();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 };
udf.initialize(arguments);
runAndVerify("hi", 5, "??", "hi???", udf);
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("hi", 5, "??", "hi???", udf);
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("hi", 3, "", null, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortTupleArrayStructOrderDESC.
@Test
public void testSortTupleArrayStructOrderDESC() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector));
ObjectInspector field = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, new Text("Scores"));
ObjectInspector orderField = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, new Text("desc"));
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Student", "Scores"), tuple)), field, orderField };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Foo"), asList(new IntWritable(4), new IntWritable(3), new IntWritable(2), new IntWritable(1)));
Object i2 = asList(new Text("Boo"), asList(new IntWritable(2), new IntWritable(3), new IntWritable(2), new IntWritable(1)));
Object i3 = asList(new Text("Tom"), asList(new IntWritable(10), new IntWritable(3), new IntWritable(2), new IntWritable(1)));
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3)), new GenericUDF.DeferredJavaObject(field), new GenericUDF.DeferredJavaObject(orderField) };
runAndVerify(argas, asList(i3, i1, i2));
}
Aggregations