use of org.apache.hadoop.hive.common.type.HiveVarchar 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.common.type.HiveVarchar 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.common.type.HiveVarchar in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleTwoField.
@Test
public void testSortPrimitiveTupleTwoField() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Department"), tuple)), PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Linkedin"), new Text("HR"));
Object i2 = asList(new Text("Linkedin"), new Text("IT"));
Object i3 = asList(new Text("Linkedin"), new Text("Finance"));
Object i4 = asList(new Text("Facebook"), new Text("IT"));
Object i5 = asList(new Text("Facebook"), new Text("Finance"));
Object i6 = asList(new Text("Facebook"), new Text("HR"));
Object i7 = asList(new Text("Google"), new Text("Logistics"));
Object i8 = asList(new Text("Google"), new Text("Finance"));
Object i9 = asList(new Text("Google"), new Text("HR"));
HiveVarchar vc = new HiveVarchar();
vc.setValue("Department");
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4, i5, i6, i7, i8, i9)), new GenericUDF.DeferredJavaObject(new Text("Company")), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)) };
runAndVerify(argas, asList(i5, i6, i4, i8, i9, i7, i3, i1, i2));
}
use of org.apache.hadoop.hive.common.type.HiveVarchar in project hive by apache.
the class TestGenericUDFFloor method testVarchar.
@Test
public void testVarchar() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
HiveVarchar vc = new HiveVarchar("32300.004747", 12);
HiveVarcharWritable input = new HiveVarcharWritable(vc);
VarcharTypeInfo inputTypeInfo = TypeInfoFactory.getVarcharTypeInfo(12);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(32300L, res.get());
}
use of org.apache.hadoop.hive.common.type.HiveVarchar in project hive by apache.
the class TestGenericUDFLikeAll method testTrue.
@Test
public void testTrue() throws HiveException {
udf = new GenericUDFLikeAll();
ObjectInspector valueOIOne = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOITwo = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOIThree = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector;
ObjectInspector[] arguments = { valueOIOne, valueOITwo, valueOIThree };
udf.initialize(arguments);
DeferredJavaObject valueObjOne = new DeferredJavaObject(new Text("abc"));
DeferredJavaObject valueObjTwo = new DeferredJavaObject(new Text("%b%"));
HiveVarchar vc = new HiveVarchar();
vc.setValue("a%");
GenericUDF.DeferredJavaObject[] args = { valueObjOne, valueObjTwo, new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)) };
BooleanWritable output = (BooleanWritable) udf.evaluate(args);
assertEquals(true, output.get());
}
Aggregations