Search in sources :

Example 1 with TypeInfoFactory.getListTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo in project nifi by apache.

the class TestNiFiOrcUtils method test_getOrcField_array.

@Test
public void test_getOrcField_array() throws Exception {
    final SchemaBuilder.FieldAssembler<Schema> builder = SchemaBuilder.record("testRecord").namespace("any.data").fields();
    builder.name("array").type().array().items().longType().noDefault();
    Schema testSchema = builder.endRecord();
    TypeInfo orcType = NiFiOrcUtils.getOrcField(testSchema.getField("array").schema());
    assertEquals(TypeInfoFactory.getListTypeInfo(TypeInfoCreator.createLong()), orcType);
}
Also used : Schema(org.apache.avro.Schema) SchemaBuilder(org.apache.avro.SchemaBuilder) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) Test(org.junit.Test)

Example 2 with TypeInfoFactory.getListTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo in project haivvreo by jghoman.

the class SchemaToTypeInfo method generateArrayTypeInfo.

private static TypeInfo generateArrayTypeInfo(Schema schema) throws HaivvreoException {
    assert schema.getType().equals(Schema.Type.ARRAY);
    Schema itemsType = schema.getElementType();
    TypeInfo itemsTypeInfo = generateTypeInfo(itemsType);
    return TypeInfoFactory.getListTypeInfo(itemsTypeInfo);
}
Also used : Schema(org.apache.avro.Schema) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 3 with TypeInfoFactory.getListTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo in project hive by apache.

the class TestKeyWrapperFactory method setup.

@Before
public void setup() throws Exception {
    SessionState ss = new SessionState(new HiveConf());
    SessionState.setCurrentSessionState(ss);
    ArrayList<Text> col1 = new ArrayList<Text>();
    col1.add(new Text("0"));
    col1.add(new Text("1"));
    col1.add(new Text("2"));
    col1.add(new Text("3"));
    TypeInfo col1Type = TypeInfoFactory.getListTypeInfo(TypeInfoFactory.stringTypeInfo);
    ArrayList<Text> cola = new ArrayList<Text>();
    cola.add(new Text("a"));
    cola.add(new Text("b"));
    cola.add(new Text("c"));
    TypeInfo colaType = TypeInfoFactory.getListTypeInfo(TypeInfoFactory.stringTypeInfo);
    try {
        ArrayList<Object> data = new ArrayList<Object>();
        data.add(col1);
        data.add(cola);
        ArrayList<String> names = new ArrayList<String>();
        names.add("col1");
        names.add("cola");
        ArrayList<TypeInfo> typeInfos = new ArrayList<TypeInfo>();
        typeInfos.add(col1Type);
        typeInfos.add(colaType);
        TypeInfo dataType = TypeInfoFactory.getStructTypeInfo(names, typeInfos);
        InspectableObject r = new InspectableObject();
        ObjectInspector[] oi = new ObjectInspector[1];
        r.o = data;
        oi[0] = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(dataType);
        try {
            // get a evaluator for a simple field expression
            ExprNodeDesc exprDesc = new ExprNodeColumnDesc(colaType, "cola", "", false);
            ExprNodeEvaluator eval = ExprNodeEvaluatorFactory.get(exprDesc);
            ExprNodeEvaluator[] evals = new ExprNodeEvaluator[1];
            evals[0] = eval;
            ObjectInspector resultOI = eval.initialize(oi[0]);
            ObjectInspector[] resultOIs = new ObjectInspector[1];
            resultOIs[0] = resultOI;
            factory = new KeyWrapperFactory(evals, oi, resultOIs);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) InspectableObject(org.apache.hadoop.hive.serde2.objectinspector.InspectableObject) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) HiveConf(org.apache.hadoop.hive.conf.HiveConf) InspectableObject(org.apache.hadoop.hive.serde2.objectinspector.InspectableObject) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Before(org.junit.Before)

Example 4 with TypeInfoFactory.getListTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo in project hive by apache.

the class SchemaToTypeInfo method generateArrayTypeInfo.

private static TypeInfo generateArrayTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException {
    assert schema.getType().equals(Schema.Type.ARRAY);
    Schema itemsType = schema.getElementType();
    TypeInfo itemsTypeInfo = generateTypeInfo(itemsType, seenSchemas);
    return TypeInfoFactory.getListTypeInfo(itemsTypeInfo);
}
Also used : Schema(org.apache.avro.Schema) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 5 with TypeInfoFactory.getListTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo in project nifi by apache.

the class TestNiFiOrcUtils method test_getOrcField_record.

@Test
public void test_getOrcField_record() throws Exception {
    final SchemaBuilder.FieldAssembler<Schema> builder = SchemaBuilder.record("testRecord").namespace("any.data").fields();
    builder.name("int").type().intType().noDefault();
    builder.name("long").type().longType().longDefault(1L);
    builder.name("array").type().array().items().stringType().noDefault();
    Schema testSchema = builder.endRecord();
    TypeInfo orcType = NiFiOrcUtils.getOrcField(testSchema);
    assertEquals(TypeInfoFactory.getStructTypeInfo(Arrays.asList("int", "long", "array"), Arrays.asList(TypeInfoCreator.createInt(), TypeInfoCreator.createLong(), TypeInfoFactory.getListTypeInfo(TypeInfoCreator.createString()))), orcType);
}
Also used : Schema(org.apache.avro.Schema) SchemaBuilder(org.apache.avro.SchemaBuilder) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) Test(org.junit.Test)

Aggregations

TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)7 Schema (org.apache.avro.Schema)5 Test (org.junit.Test)4 SchemaBuilder (org.apache.avro.SchemaBuilder)3 ArrayList (java.util.ArrayList)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 LazySimpleDeserializeRead (org.apache.hadoop.hive.serde2.lazy.fast.LazySimpleDeserializeRead)1 InspectableObject (org.apache.hadoop.hive.serde2.objectinspector.InspectableObject)1