Search in sources :

Example 46 with CharTypeInfo

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

the class VectorDeserializeRow method initSourceEntry.

/*
   * Initialize one column's source deserializtion related arrays.
   */
private void initSourceEntry(int logicalColumnIndex, int projectionColumnNum, TypeInfo sourceTypeInfo) {
    isConvert[logicalColumnIndex] = false;
    projectionColumnNums[logicalColumnIndex] = projectionColumnNum;
    Category sourceCategory = sourceTypeInfo.getCategory();
    sourceCategories[logicalColumnIndex] = sourceCategory;
    if (sourceCategory == Category.PRIMITIVE) {
        PrimitiveTypeInfo sourcePrimitiveTypeInfo = (PrimitiveTypeInfo) sourceTypeInfo;
        PrimitiveCategory sourcePrimitiveCategory = sourcePrimitiveTypeInfo.getPrimitiveCategory();
        sourcePrimitiveCategories[logicalColumnIndex] = sourcePrimitiveCategory;
        switch(sourcePrimitiveCategory) {
            case CHAR:
                maxLengths[logicalColumnIndex] = ((CharTypeInfo) sourcePrimitiveTypeInfo).getLength();
                break;
            case VARCHAR:
                maxLengths[logicalColumnIndex] = ((VarcharTypeInfo) sourcePrimitiveTypeInfo).getLength();
                break;
            default:
                // No additional data type specific setting.
                break;
        }
    } else {
        // We don't currently support complex types.
        Preconditions.checkState(false);
    }
}
Also used : PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Example 47 with CharTypeInfo

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

the class SerdeRandomRowSource method randomObject.

public Object randomObject(int column) {
    PrimitiveCategory primitiveCategory = primitiveCategories[column];
    PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column];
    switch(primitiveCategory) {
        case BOOLEAN:
            return Boolean.valueOf(r.nextInt(1) == 1);
        case BYTE:
            return Byte.valueOf((byte) r.nextInt());
        case SHORT:
            return Short.valueOf((short) r.nextInt());
        case INT:
            return Integer.valueOf(r.nextInt());
        case LONG:
            return Long.valueOf(r.nextLong());
        case DATE:
            return RandomTypeUtil.getRandDate(r);
        case FLOAT:
            return Float.valueOf(r.nextFloat() * 10 - 5);
        case DOUBLE:
            return Double.valueOf(r.nextDouble() * 10 - 5);
        case STRING:
            return RandomTypeUtil.getRandString(r);
        case CHAR:
            return getRandHiveChar(r, (CharTypeInfo) primitiveTypeInfo);
        case VARCHAR:
            return getRandHiveVarchar(r, (VarcharTypeInfo) primitiveTypeInfo);
        case BINARY:
            return getRandBinary(r, 1 + r.nextInt(100));
        case TIMESTAMP:
            return RandomTypeUtil.getRandTimestamp(r);
        case INTERVAL_YEAR_MONTH:
            return getRandIntervalYearMonth(r);
        case INTERVAL_DAY_TIME:
            return getRandIntervalDayTime(r);
        case DECIMAL:
            {
                HiveDecimal dec = getRandHiveDecimal(r, (DecimalTypeInfo) primitiveTypeInfo);
                return dec;
            }
        default:
            throw new Error("Unknown primitive category " + primitiveCategory);
    }
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Example 48 with CharTypeInfo

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

the class SerdeRandomRowSource method getWritableObject.

public Object getWritableObject(int column, Object object) {
    ObjectInspector objectInspector = primitiveObjectInspectorList.get(column);
    PrimitiveCategory primitiveCategory = primitiveCategories[column];
    PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column];
    switch(primitiveCategory) {
        case BOOLEAN:
            return ((WritableBooleanObjectInspector) objectInspector).create((boolean) object);
        case BYTE:
            return ((WritableByteObjectInspector) objectInspector).create((byte) object);
        case SHORT:
            return ((WritableShortObjectInspector) objectInspector).create((short) object);
        case INT:
            return ((WritableIntObjectInspector) objectInspector).create((int) object);
        case LONG:
            return ((WritableLongObjectInspector) objectInspector).create((long) object);
        case DATE:
            return ((WritableDateObjectInspector) objectInspector).create((Date) object);
        case FLOAT:
            return ((WritableFloatObjectInspector) objectInspector).create((float) object);
        case DOUBLE:
            return ((WritableDoubleObjectInspector) objectInspector).create((double) object);
        case STRING:
            return ((WritableStringObjectInspector) objectInspector).create((String) object);
        case CHAR:
            {
                WritableHiveCharObjectInspector writableCharObjectInspector = new WritableHiveCharObjectInspector((CharTypeInfo) primitiveTypeInfo);
                return writableCharObjectInspector.create((HiveChar) object);
            }
        case VARCHAR:
            {
                WritableHiveVarcharObjectInspector writableVarcharObjectInspector = new WritableHiveVarcharObjectInspector((VarcharTypeInfo) primitiveTypeInfo);
                return writableVarcharObjectInspector.create((HiveVarchar) object);
            }
        case BINARY:
            return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector.create((byte[]) object);
        case TIMESTAMP:
            return ((WritableTimestampObjectInspector) objectInspector).create((Timestamp) object);
        case INTERVAL_YEAR_MONTH:
            return ((WritableHiveIntervalYearMonthObjectInspector) objectInspector).create((HiveIntervalYearMonth) object);
        case INTERVAL_DAY_TIME:
            return ((WritableHiveIntervalDayTimeObjectInspector) objectInspector).create((HiveIntervalDayTime) object);
        case DECIMAL:
            {
                WritableHiveDecimalObjectInspector writableDecimalObjectInspector = new WritableHiveDecimalObjectInspector((DecimalTypeInfo) primitiveTypeInfo);
                return writableDecimalObjectInspector.create((HiveDecimal) object);
            }
        default:
            throw new Error("Unknown primitive category " + primitiveCategory);
    }
}
Also used : VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) WritableHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveVarcharObjectInspector) WritableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableLongObjectInspector) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) WritableHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalDayTimeObjectInspector) WritableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveDecimalObjectInspector) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) WritableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableFloatObjectInspector) WritableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector) WritableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableShortObjectInspector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) WritableHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalYearMonthObjectInspector) WritableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveCharObjectInspector) WritableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector) WritableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableByteObjectInspector) WritableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveCharObjectInspector) WritableHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveVarcharObjectInspector) WritableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableBooleanObjectInspector) WritableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableTimestampObjectInspector) WritableHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalDayTimeObjectInspector) WritableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableShortObjectInspector) WritableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDoubleObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) WritableHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalYearMonthObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) WritableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableFloatObjectInspector) WritableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableLongObjectInspector) WritableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDateObjectInspector) WritableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveDecimalObjectInspector) WritableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector) WritableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableTimestampObjectInspector) WritableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableBooleanObjectInspector) WritableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableByteObjectInspector) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) WritableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector) WritableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDateObjectInspector) WritableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDoubleObjectInspector)

Example 49 with CharTypeInfo

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

the class DruidSerDe method deserialize.

@Override
public Object deserialize(Writable writable) throws SerDeException {
    final DruidWritable input = (DruidWritable) writable;
    final List<Object> output = Lists.newArrayListWithExpectedSize(columns.length);
    for (int i = 0; i < columns.length; i++) {
        final Object value = input.getValue().get(columns[i]);
        if (value == null) {
            output.add(null);
            continue;
        }
        switch(types[i].getPrimitiveCategory()) {
            case TIMESTAMP:
                output.add(new TimestampWritable(Timestamp.valueOf(ZonedDateTime.ofInstant(Instant.ofEpochMilli(((Number) value).longValue()), tsTZTypeInfo.timeZone()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).toString())));
                break;
            case TIMESTAMPLOCALTZ:
                output.add(new TimestampLocalTZWritable(new TimestampTZ(ZonedDateTime.ofInstant(Instant.ofEpochMilli(((Number) value).longValue()), ((TimestampLocalTZTypeInfo) types[i]).timeZone()))));
                break;
            case BYTE:
                output.add(new ByteWritable(((Number) value).byteValue()));
                break;
            case SHORT:
                output.add(new ShortWritable(((Number) value).shortValue()));
                break;
            case INT:
                output.add(new IntWritable(((Number) value).intValue()));
                break;
            case LONG:
                output.add(new LongWritable(((Number) value).longValue()));
                break;
            case FLOAT:
                output.add(new FloatWritable(((Number) value).floatValue()));
                break;
            case DOUBLE:
                output.add(new DoubleWritable(((Number) value).doubleValue()));
                break;
            case DECIMAL:
                output.add(new HiveDecimalWritable(HiveDecimal.create(((Number) value).doubleValue())));
                break;
            case CHAR:
                output.add(new HiveCharWritable(new HiveChar(value.toString(), ((CharTypeInfo) types[i]).getLength())));
                break;
            case VARCHAR:
                output.add(new HiveVarcharWritable(new HiveVarchar(value.toString(), ((VarcharTypeInfo) types[i]).getLength())));
                break;
            case STRING:
                output.add(new Text(value.toString()));
                break;
            case BOOLEAN:
                output.add(new BooleanWritable(Boolean.valueOf(value.toString())));
                break;
            default:
                throw new SerDeException("Unknown type: " + types[i].getPrimitiveCategory());
        }
    }
    return output;
}
Also used : HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) TimestampLocalTZTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TimestampLocalTZTypeInfo) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Text(org.apache.hadoop.io.Text) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) FloatWritable(org.apache.hadoop.io.FloatWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) TimestampLocalTZWritable(org.apache.hadoop.hive.serde2.io.TimestampLocalTZWritable) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 50 with CharTypeInfo

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

the class OrcFlowFileWriter method writeTypes.

private static void writeTypes(OrcProto.Footer.Builder builder, TreeWriter treeWriter) {
    OrcProto.Type.Builder type = OrcProto.Type.newBuilder();
    switch(treeWriter.inspector.getCategory()) {
        case PRIMITIVE:
            switch(((PrimitiveObjectInspector) treeWriter.inspector).getPrimitiveCategory()) {
                case BOOLEAN:
                    type.setKind(OrcProto.Type.Kind.BOOLEAN);
                    break;
                case BYTE:
                    type.setKind(OrcProto.Type.Kind.BYTE);
                    break;
                case SHORT:
                    type.setKind(OrcProto.Type.Kind.SHORT);
                    break;
                case INT:
                    type.setKind(OrcProto.Type.Kind.INT);
                    break;
                case LONG:
                    type.setKind(OrcProto.Type.Kind.LONG);
                    break;
                case FLOAT:
                    type.setKind(OrcProto.Type.Kind.FLOAT);
                    break;
                case DOUBLE:
                    type.setKind(OrcProto.Type.Kind.DOUBLE);
                    break;
                case STRING:
                    type.setKind(OrcProto.Type.Kind.STRING);
                    break;
                case CHAR:
                    // The char length needs to be written to file and should be available
                    // from the object inspector
                    CharTypeInfo charTypeInfo = (CharTypeInfo) ((PrimitiveObjectInspector) treeWriter.inspector).getTypeInfo();
                    type.setKind(Type.Kind.CHAR);
                    type.setMaximumLength(charTypeInfo.getLength());
                    break;
                case VARCHAR:
                    // The varchar length needs to be written to file and should be available
                    // from the object inspector
                    VarcharTypeInfo typeInfo = (VarcharTypeInfo) ((PrimitiveObjectInspector) treeWriter.inspector).getTypeInfo();
                    type.setKind(Type.Kind.VARCHAR);
                    type.setMaximumLength(typeInfo.getLength());
                    break;
                case BINARY:
                    type.setKind(OrcProto.Type.Kind.BINARY);
                    break;
                case TIMESTAMP:
                    type.setKind(OrcProto.Type.Kind.TIMESTAMP);
                    break;
                case DATE:
                    type.setKind(OrcProto.Type.Kind.DATE);
                    break;
                case DECIMAL:
                    DecimalTypeInfo decTypeInfo = (DecimalTypeInfo) ((PrimitiveObjectInspector) treeWriter.inspector).getTypeInfo();
                    type.setKind(OrcProto.Type.Kind.DECIMAL);
                    type.setPrecision(decTypeInfo.precision());
                    type.setScale(decTypeInfo.scale());
                    break;
                default:
                    throw new IllegalArgumentException("Unknown primitive category: " + ((PrimitiveObjectInspector) treeWriter.inspector).getPrimitiveCategory());
            }
            break;
        case LIST:
            type.setKind(OrcProto.Type.Kind.LIST);
            type.addSubtypes(treeWriter.childrenWriters[0].id);
            break;
        case MAP:
            type.setKind(OrcProto.Type.Kind.MAP);
            type.addSubtypes(treeWriter.childrenWriters[0].id);
            type.addSubtypes(treeWriter.childrenWriters[1].id);
            break;
        case STRUCT:
            type.setKind(OrcProto.Type.Kind.STRUCT);
            for (TreeWriter child : treeWriter.childrenWriters) {
                type.addSubtypes(child.id);
            }
            for (StructField field : ((StructTreeWriter) treeWriter).fields) {
                type.addFieldNames(field.getFieldName());
            }
            break;
        case UNION:
            type.setKind(OrcProto.Type.Kind.UNION);
            for (TreeWriter child : treeWriter.childrenWriters) {
                type.addSubtypes(child.id);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown category: " + treeWriter.inspector.getCategory());
    }
    builder.addTypes(type);
    for (TreeWriter child : treeWriter.childrenWriters) {
        writeTypes(builder, child);
    }
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) Type(org.apache.hadoop.hive.ql.io.orc.OrcProto.Type) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Aggregations

CharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo)40 VarcharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo)33 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)25 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)24 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)22 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)19 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)16 Text (org.apache.hadoop.io.Text)15 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)14 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)12 LongWritable (org.apache.hadoop.io.LongWritable)12 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)11 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)11 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)10 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)10 BytesWritable (org.apache.hadoop.io.BytesWritable)10 IntWritable (org.apache.hadoop.io.IntWritable)10 Test (org.junit.Test)10 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)9 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)9