Search in sources :

Example 21 with ObjectInspectorFactory.getStandardListObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector in project hive by apache.

the class AvroObjectInspectorGenerator method createObjectInspectorWorker.

private ObjectInspector createObjectInspectorWorker(TypeInfo ti) throws SerDeException {
    // at deserialization and the object inspector will never see the actual union.
    if (!supportedCategories(ti)) {
        throw new AvroSerdeException("Don't yet support this type: " + ti);
    }
    ObjectInspector result;
    switch(ti.getCategory()) {
        case PRIMITIVE:
            PrimitiveTypeInfo pti = (PrimitiveTypeInfo) ti;
            result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti);
            break;
        case STRUCT:
            StructTypeInfo sti = (StructTypeInfo) ti;
            ArrayList<ObjectInspector> ois = new ArrayList<ObjectInspector>(sti.getAllStructFieldTypeInfos().size());
            for (TypeInfo typeInfo : sti.getAllStructFieldTypeInfos()) {
                ois.add(createObjectInspectorWorker(typeInfo));
            }
            result = ObjectInspectorFactory.getStandardStructObjectInspector(sti.getAllStructFieldNames(), ois);
            break;
        case MAP:
            MapTypeInfo mti = (MapTypeInfo) ti;
            result = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveObjectInspector.PrimitiveCategory.STRING), createObjectInspectorWorker(mti.getMapValueTypeInfo()));
            break;
        case LIST:
            ListTypeInfo ati = (ListTypeInfo) ti;
            result = ObjectInspectorFactory.getStandardListObjectInspector(createObjectInspectorWorker(ati.getListElementTypeInfo()));
            break;
        case UNION:
            UnionTypeInfo uti = (UnionTypeInfo) ti;
            List<TypeInfo> allUnionObjectTypeInfos = uti.getAllUnionObjectTypeInfos();
            List<ObjectInspector> unionObjectInspectors = new ArrayList<ObjectInspector>(allUnionObjectTypeInfos.size());
            for (TypeInfo typeInfo : allUnionObjectTypeInfos) {
                unionObjectInspectors.add(createObjectInspectorWorker(typeInfo));
            }
            result = ObjectInspectorFactory.getStandardUnionObjectInspector(unionObjectInspectors);
            break;
        default:
            throw new AvroSerdeException("No Hive categories matched: " + ti);
    }
    return result;
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ArrayList(java.util.ArrayList) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)

Example 22 with ObjectInspectorFactory.getStandardListObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector 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));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Example 23 with ObjectInspectorFactory.getStandardListObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector 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));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 24 with ObjectInspectorFactory.getStandardListObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector 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));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Example 25 with ObjectInspectorFactory.getStandardListObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector 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));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)11 Text (org.apache.hadoop.io.Text)9 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)6 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)6 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)5 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)5 HashMap (java.util.HashMap)4 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)4 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)4 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)4 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)4 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)4 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)4 ListTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo)4 MapTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)4 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)4 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)4 IntWritable (org.apache.hadoop.io.IntWritable)4