use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleOneFieldOrderASC.
@Test
public void testSortPrimitiveTupleOneFieldOrderASC() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Salary"), tuple)), PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Facebook"), new DoubleWritable(80223.25));
Object i2 = asList(new Text("Facebook"), new DoubleWritable(50223.25));
Object i3 = asList(new Text("Facebook"), new DoubleWritable(40223.25));
Object i4 = asList(new Text("Facebook"), new DoubleWritable(60223.25));
HiveVarchar vc = new HiveVarchar();
vc.setValue("Salary");
HiveVarchar order = new HiveVarchar();
order.setValue("ASC");
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(order)) };
runAndVerify(argas, asList(i3, i2, i4, i1));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleOneField.
@Test
public void testSortPrimitiveTupleOneField() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Salary"), tuple)), PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Facebook"), new DoubleWritable(80223.25));
Object i2 = asList(new Text("Facebook"), new DoubleWritable(50223.25));
Object i3 = asList(new Text("Facebook"), new DoubleWritable(40223.25));
Object i4 = asList(new Text("Facebook"), new DoubleWritable(60223.25));
HiveVarchar vc = new HiveVarchar();
vc.setValue("Salary");
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)) };
runAndVerify(argas, asList(i3, i2, i4, i1));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFLevenshtein method testLevenshteinWrongType0.
public void testLevenshteinWrongType0() throws HiveException {
@SuppressWarnings("resource") GenericUDFLevenshtein udf = new GenericUDFLevenshtein();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("levenshtein test. UDFArgumentTypeException is expected", false);
} catch (UDFArgumentTypeException e) {
assertEquals("levenshtein test", "levenshtein only takes STRING_GROUP, VOID_GROUP types as 1st argument, got INT", e.getMessage());
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFMapValues method testNullMap.
@Test
public void testNullMap() throws HiveException, IOException {
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector) };
Map<String, String> input = null;
DeferredObject[] args = { new DeferredJavaObject(input) };
GenericUDFMapValues udf = new GenericUDFMapValues();
StandardListObjectInspector oi = (StandardListObjectInspector) udf.initialize(inputOIs);
Object res = udf.evaluate(args);
Assert.assertTrue(oi.getList(res).isEmpty());
udf.close();
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFNextDay method testNextDayErrorArg1.
public void testNextDayErrorArg1() throws HiveException {
@SuppressWarnings("resource") GenericUDFNextDay udf = new GenericUDFNextDay();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("UDFArgumentException expected", false);
} catch (UDFArgumentException e) {
assertEquals("next_day only takes STRING_GROUP, DATE_GROUP, VOID_GROUP types as 1st argument, got LONG", e.getMessage());
}
}
Aggregations