Search in sources :

Example 6 with WritableStringObjectInspector

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

the class TestStreaming method deserializeInner.

// Assumes row schema => string,int,string
private static SampleRec deserializeInner(Object row, StructObjectInspector inspector) {
    List<? extends StructField> fields = inspector.getAllStructFieldRefs();
    WritableStringObjectInspector f0ins = (WritableStringObjectInspector) fields.get(0).getFieldObjectInspector();
    WritableIntObjectInspector f1ins = (WritableIntObjectInspector) fields.get(1).getFieldObjectInspector();
    WritableStringObjectInspector f2ins = (WritableStringObjectInspector) fields.get(2).getFieldObjectInspector();
    String f0 = f0ins.getPrimitiveJavaObject(inspector.getStructFieldData(row, fields.get(0)));
    int f1 = f1ins.get(inspector.getStructFieldData(row, fields.get(1)));
    String f2 = f2ins.getPrimitiveJavaObject(inspector.getStructFieldData(row, fields.get(2)));
    return new SampleRec(f0, f1, f2);
}
Also used : WritableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector) WritableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector)

Example 7 with WritableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector in project presto by prestodb.

the class HiveWriteUtils method getRowColumnInspector.

public static ObjectInspector getRowColumnInspector(Type type) {
    if (type.equals(BooleanType.BOOLEAN)) {
        return writableBooleanObjectInspector;
    }
    if (type.equals(BigintType.BIGINT)) {
        return writableLongObjectInspector;
    }
    if (type.equals(IntegerType.INTEGER)) {
        return writableIntObjectInspector;
    }
    if (type.equals(SmallintType.SMALLINT)) {
        return writableShortObjectInspector;
    }
    if (type.equals(TinyintType.TINYINT)) {
        return writableByteObjectInspector;
    }
    if (type.equals(RealType.REAL)) {
        return writableFloatObjectInspector;
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return writableDoubleObjectInspector;
    }
    if (type instanceof VarcharType) {
        VarcharType varcharType = (VarcharType) type;
        int varcharLength = varcharType.getLength();
        // VARCHAR columns with the length less than or equal to 65535 are supported natively by Hive
        if (varcharLength <= HiveVarchar.MAX_VARCHAR_LENGTH) {
            return getPrimitiveWritableObjectInspector(getVarcharTypeInfo(varcharLength));
        } else // Values for such columns must be stored as STRING in Hive
        if (varcharLength == VarcharType.UNBOUNDED_LENGTH) {
            return writableStringObjectInspector;
        }
    }
    if (isCharType(type)) {
        CharType charType = (CharType) type;
        int charLength = charType.getLength();
        return getPrimitiveWritableObjectInspector(getCharTypeInfo(charLength));
    }
    if (type.equals(VarbinaryType.VARBINARY)) {
        return writableBinaryObjectInspector;
    }
    if (type.equals(DateType.DATE)) {
        return writableDateObjectInspector;
    }
    if (type.equals(TimestampType.TIMESTAMP)) {
        return writableTimestampObjectInspector;
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        return getPrimitiveWritableObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
    }
    if (isArrayType(type) || isMapType(type) || isRowType(type)) {
        return getJavaObjectInspector(type);
    }
    throw new IllegalArgumentException("unsupported type: " + type);
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) VarcharType(com.facebook.presto.spi.type.VarcharType) DecimalType(com.facebook.presto.spi.type.DecimalType) CharType(com.facebook.presto.spi.type.CharType) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType)

Aggregations

WritableStringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector)4 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)4 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)3 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)3 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)3 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)3 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)3 VarcharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo)3 CharType (com.facebook.presto.spi.type.CharType)2 Chars.isCharType (com.facebook.presto.spi.type.Chars.isCharType)2 DecimalType (com.facebook.presto.spi.type.DecimalType)2 Date (java.sql.Date)2 Timestamp (java.sql.Timestamp)2 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)2 WritableIntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector)2 BytesWritable (org.apache.hadoop.io.BytesWritable)2 Text (org.apache.hadoop.io.Text)2 HIVE_DATABASE_LOCATION_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_DATABASE_LOCATION_ERROR)1 HIVE_FILESYSTEM_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR)1 HIVE_WRITER_DATA_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_DATA_ERROR)1