Search in sources :

Example 6 with AvroObjectInspectorGenerator

use of com.linkedin.haivvreo.AvroObjectInspectorGenerator in project haivvreo by jghoman.

the class TestAvroObjectInspectorGenerator method canHandleMapsWithPrimitiveValueTypes.

@Test
public void canHandleMapsWithPrimitiveValueTypes() throws SerDeException {
    Schema s = Schema.parse(MAP_WITH_PRIMITIVE_VALUE_TYPE);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    // Column names
    assertEquals(1, aoig.getColumnNames().size());
    assertEquals("aMap", aoig.getColumnNames().get(0));
    // Column types
    assertEquals(1, aoig.getColumnTypes().size());
    TypeInfo typeInfo = aoig.getColumnTypes().get(0);
    assertEquals(ObjectInspector.Category.MAP, typeInfo.getCategory());
    assertTrue(typeInfo instanceof MapTypeInfo);
    MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
    assertEquals("bigint", /* == long in Avro */
    mapTypeInfo.getMapValueTypeInfo().getTypeName());
    assertEquals("string", mapTypeInfo.getMapKeyTypeInfo().getTypeName());
}
Also used : Schema(org.apache.avro.Schema) AvroObjectInspectorGenerator(com.linkedin.haivvreo.AvroObjectInspectorGenerator) Test(org.junit.Test)

Example 7 with AvroObjectInspectorGenerator

use of com.linkedin.haivvreo.AvroObjectInspectorGenerator in project haivvreo by jghoman.

the class TestAvroObjectInspectorGenerator method canHandleArrays.

@Test
public void canHandleArrays() throws SerDeException {
    Schema s = Schema.parse(ARRAY_WITH_PRIMITIVE_ELEMENT_TYPE);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    // Column names
    assertEquals(1, aoig.getColumnNames().size());
    assertEquals("anArray", aoig.getColumnNames().get(0));
    // Column types
    assertEquals(1, aoig.getColumnTypes().size());
    TypeInfo typeInfo = aoig.getColumnTypes().get(0);
    assertEquals(ObjectInspector.Category.LIST, typeInfo.getCategory());
    assertTrue(typeInfo instanceof ListTypeInfo);
    ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
    assertEquals("string", listTypeInfo.getListElementTypeInfo().getTypeName());
}
Also used : Schema(org.apache.avro.Schema) AvroObjectInspectorGenerator(com.linkedin.haivvreo.AvroObjectInspectorGenerator) Test(org.junit.Test)

Example 8 with AvroObjectInspectorGenerator

use of com.linkedin.haivvreo.AvroObjectInspectorGenerator in project haivvreo by jghoman.

the class TestAvroObjectInspectorGenerator method objectInspectorsAreCached.

@Test
public void objectInspectorsAreCached() throws SerDeException {
    // Verify that Hive is caching the object inspectors for us.
    Schema s = Schema.parse(KITCHEN_SINK_SCHEMA);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    Schema s2 = Schema.parse(KITCHEN_SINK_SCHEMA);
    AvroObjectInspectorGenerator aoig2 = new AvroObjectInspectorGenerator(s2);
    assertEquals(aoig.getObjectInspector(), aoig2.getObjectInspector());
    // For once we actually want reference equality in Java.
    assertTrue(aoig.getObjectInspector() == aoig2.getObjectInspector());
}
Also used : Schema(org.apache.avro.Schema) AvroObjectInspectorGenerator(com.linkedin.haivvreo.AvroObjectInspectorGenerator) Test(org.junit.Test)

Example 9 with AvroObjectInspectorGenerator

use of com.linkedin.haivvreo.AvroObjectInspectorGenerator in project haivvreo by jghoman.

the class TestAvroObjectInspectorGenerator method canHandleBytes.

// Avro considers bytes primitive, Hive doesn't. Make them list of tinyint.
@Test
public void canHandleBytes() throws SerDeException {
    Schema s = Schema.parse(BYTES_SCHEMA);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    // Column names
    assertEquals(1, aoig.getColumnNames().size());
    assertEquals("bytesField", aoig.getColumnNames().get(0));
    // Column types
    assertEquals(1, aoig.getColumnTypes().size());
    TypeInfo typeInfo = aoig.getColumnTypes().get(0);
    assertTrue(typeInfo instanceof ListTypeInfo);
    ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
    assertTrue(listTypeInfo.getListElementTypeInfo() instanceof PrimitiveTypeInfo);
    assertEquals("tinyint", listTypeInfo.getListElementTypeInfo().getTypeName());
}
Also used : Schema(org.apache.avro.Schema) AvroObjectInspectorGenerator(com.linkedin.haivvreo.AvroObjectInspectorGenerator) Test(org.junit.Test)

Example 10 with AvroObjectInspectorGenerator

use of com.linkedin.haivvreo.AvroObjectInspectorGenerator in project haivvreo by jghoman.

the class TestAvroObjectInspectorGenerator method canHandleFixed.

// Hive has no concept of Avro's fixed type.  Fixed -> arrays of bytes
@Test
public void canHandleFixed() throws SerDeException {
    Schema s = Schema.parse(FIXED_SCHEMA);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    // Column names
    assertEquals(1, aoig.getColumnNames().size());
    assertEquals("hash", aoig.getColumnNames().get(0));
    // Column types
    assertEquals(1, aoig.getColumnTypes().size());
    TypeInfo typeInfo = aoig.getColumnTypes().get(0);
    assertTrue(typeInfo instanceof ListTypeInfo);
    ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
    assertTrue(listTypeInfo.getListElementTypeInfo() instanceof PrimitiveTypeInfo);
    assertEquals("tinyint", listTypeInfo.getListElementTypeInfo().getTypeName());
}
Also used : Schema(org.apache.avro.Schema) AvroObjectInspectorGenerator(com.linkedin.haivvreo.AvroObjectInspectorGenerator) Test(org.junit.Test)

Aggregations

AvroObjectInspectorGenerator (com.linkedin.haivvreo.AvroObjectInspectorGenerator)11 Test (org.junit.Test)11 Schema (org.apache.avro.Schema)10 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)1 StandardStructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector)1