Search in sources :

Example 6 with StringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector in project hive by apache.

the class TestAvroDeserializer method canDeserializeEnums.

// Enums are one of two types we fudge for Hive. Enums go in, Strings come out.
@Test
public void canDeserializeEnums() throws SerDeException, IOException {
    Schema s = AvroSerdeUtils.getSchemaFor(TestAvroObjectInspectorGenerator.ENUM_SCHEMA);
    GenericData.Record record = new GenericData.Record(s);
    record.put("baddies", new GenericData.EnumSymbol(s.getField("baddies").schema(), "DALEKS"));
    assertTrue(GENERIC_DATA.validate(s, record));
    AvroGenericRecordWritable garw = Utils.serializeAndDeserializeRecord(record);
    AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
    AvroDeserializer de = new AvroDeserializer();
    ArrayList<Object> row = (ArrayList<Object>) de.deserialize(aoig.getColumnNames(), aoig.getColumnTypes(), garw, s);
    assertEquals(1, row.size());
    StandardStructObjectInspector oi = (StandardStructObjectInspector) aoig.getObjectInspector();
    List<? extends StructField> fieldRefs = oi.getAllStructFieldRefs();
    assertEquals(1, fieldRefs.size());
    StructField fieldRef = fieldRefs.get(0);
    assertEquals("baddies", fieldRef.getFieldName());
    Object theStringObject = oi.getStructFieldData(row, fieldRef);
    assertTrue(fieldRef.getFieldObjectInspector() instanceof StringObjectInspector);
    StringObjectInspector soi = (StringObjectInspector) fieldRef.getFieldObjectInspector();
    String finalValue = soi.getPrimitiveJavaObject(theStringObject);
    assertEquals("DALEKS", finalValue);
}
Also used : Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) GenericData(org.apache.avro.generic.GenericData) JavaStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaStringObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) Test(org.junit.Test)

Example 7 with StringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector in project hive by apache.

the class KeyWrapperFactory method getKeyWrapper.

public KeyWrapper getKeyWrapper() {
    if (keyFields.length == 1 && TypeInfoUtils.getTypeInfoFromObjectInspector(keyObjectInspectors[0]).equals(TypeInfoFactory.stringTypeInfo)) {
        assert (TypeInfoUtils.getTypeInfoFromObjectInspector(currentKeyObjectInspectors[0]).equals(TypeInfoFactory.stringTypeInfo));
        soi_new = (StringObjectInspector) keyObjectInspectors[0];
        soi_copy = (StringObjectInspector) currentKeyObjectInspectors[0];
        return new TextKeyWrapper(false);
    } else {
        currentStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, currentKeyObjectInspectors);
        newKeyStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, keyObjectInspectors);
        return new ListKeyWrapper(false);
    }
}
Also used : ListObjectsEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.ListObjectsEqualComparer)

Example 8 with StringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector in project hive by apache.

the class ColumnStatsTask method unpackDateStats.

private void unpackDateStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) {
    if (fName.equals("countnulls")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getDateStats().setNumNulls(v);
    } else if (fName.equals("numdistinctvalues")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getDateStats().setNumDVs(v);
    } else if (fName.equals("max")) {
        DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
        statsObj.getStatsData().getDateStats().setHighValue(new Date(v.getDays()));
    } else if (fName.equals("min")) {
        DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
        statsObj.getStatsData().getDateStats().setLowValue(new Date(v.getDays()));
    } else if (fName.equals("ndvbitvector")) {
        PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
        String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o);
        statsObj.getStatsData().getDateStats().setBitVectors(v);
        ;
    }
}
Also used : LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) DateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) Date(org.apache.hadoop.hive.metastore.api.Date)

Example 9 with StringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector in project hive by apache.

the class ColumnStatsTask method unpackLongStats.

private void unpackLongStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) {
    if (fName.equals("countnulls")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getLongStats().setNumNulls(v);
    } else if (fName.equals("numdistinctvalues")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getLongStats().setNumDVs(v);
    } else if (fName.equals("max")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getLongStats().setHighValue(v);
    } else if (fName.equals("min")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getLongStats().setLowValue(v);
    } else if (fName.equals("ndvbitvector")) {
        PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
        String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o);
        statsObj.getStatsData().getLongStats().setBitVectors(v);
        ;
    }
}
Also used : LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)

Example 10 with StringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector in project hive by apache.

the class ColumnStatsTask method unpackStringStats.

private void unpackStringStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) {
    if (fName.equals("countnulls")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getStringStats().setNumNulls(v);
    } else if (fName.equals("numdistinctvalues")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getStringStats().setNumDVs(v);
    } else if (fName.equals("avglength")) {
        double d = ((DoubleObjectInspector) oi).get(o);
        statsObj.getStatsData().getStringStats().setAvgColLen(d);
    } else if (fName.equals("maxlength")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getStringStats().setMaxColLen(v);
    } else if (fName.equals("ndvbitvector")) {
        PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
        String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o);
        statsObj.getStatsData().getStringStats().setBitVectors(v);
        ;
    }
}
Also used : LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) DoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)

Aggregations

StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)30 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)15 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)15 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)15 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)12 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)12 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)12 ByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)11 FloatObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector)11 HiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector)11 BooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)10 ShortObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector)10 TimestampObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector)10 BinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector)9 Text (org.apache.hadoop.io.Text)9 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)8 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)7 DateObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector)7 HiveCharObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveCharObjectInspector)7 ArrayList (java.util.ArrayList)6