Search in sources :

Example 6 with ThriftType

use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.

the class ParquetWriteProtocol method getProtocol.

private TProtocol getProtocol(ThriftField field, ColumnIO columnIO, Events returnClause) {
    TProtocol p;
    final ThriftType type = field.getType();
    switch(type.getType()) {
        case STOP:
        case VOID:
        default:
            throw new UnsupportedOperationException("can't convert type of " + field);
        case BOOL:
        case BYTE:
        case DOUBLE:
        case I16:
        case I32:
        case I64:
        case STRING:
            p = new PrimitiveWriteProtocol((PrimitiveColumnIO) columnIO, returnClause);
            break;
        case STRUCT:
            p = new StructWriteProtocol((GroupColumnIO) columnIO, (StructType) type, returnClause);
            break;
        case MAP:
            p = new MapWriteProtocol((GroupColumnIO) columnIO, (MapType) type, returnClause);
            break;
        case SET:
            p = new ListWriteProtocol((GroupColumnIO) columnIO, ((SetType) type).getValues(), returnClause);
            break;
        case LIST:
            p = new ListWriteProtocol((GroupColumnIO) columnIO, ((ListType) type).getValues(), returnClause);
            break;
        case ENUM:
            p = new EnumWriteProtocol((PrimitiveColumnIO) columnIO, (EnumType) type, returnClause);
            break;
    }
    return p;
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) PrimitiveColumnIO(org.apache.parquet.io.PrimitiveColumnIO) MapType(org.apache.parquet.thrift.struct.ThriftType.MapType) TProtocol(org.apache.thrift.protocol.TProtocol) GroupColumnIO(org.apache.parquet.io.GroupColumnIO) SetType(org.apache.parquet.thrift.struct.ThriftType.SetType) EnumType(org.apache.parquet.thrift.struct.ThriftType.EnumType) ListType(org.apache.parquet.thrift.struct.ThriftType.ListType)

Example 7 with ThriftType

use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.

the class ScroogeStructConverter method convertListTypeField.

private ThriftType convertListTypeField(String fieldName, Manifest<?> valueManifest, Requirement requirement) {
    String elemName = listElemName(fieldName);
    ThriftType elementType = convertClassToThriftType(elemName, requirement, valueManifest);
    ThriftField elementField = generateFieldWithoutId(elemName, requirement, elementType);
    return new ThriftType.ListType(elementField);
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 8 with ThriftType

use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.

the class ThriftSchemaConverter method toThriftField.

private static ThriftField toThriftField(String name, Field field, ThriftField.Requirement requirement) {
    ThriftType type;
    switch(ThriftTypeID.fromByte(field.getType())) {
        case STOP:
        case VOID:
        default:
            throw new UnsupportedOperationException("can't convert type of " + field);
        case BOOL:
            type = new BoolType();
            break;
        case BYTE:
            type = new ByteType();
            break;
        case DOUBLE:
            type = new DoubleType();
            break;
        case I16:
            type = new I16Type();
            break;
        case I32:
            type = new I32Type();
            break;
        case I64:
            type = new I64Type();
            break;
        case STRING:
            StringType stringType = new StringType();
            FieldMetaData fieldMetaData = field.getFieldMetaData();
            // binary data is represented by String type with an additional binary flag.
            if (fieldMetaData != null && fieldMetaData.valueMetaData.isBinary()) {
                stringType.setBinary(true);
            }
            type = stringType;
            break;
        case STRUCT:
            type = toStructType(field.gettStructDescriptor());
            break;
        case MAP:
            final Field mapKeyField = field.getMapKeyField();
            final Field mapValueField = field.getMapValueField();
            type = new ThriftType.MapType(toThriftField(mapKeyField.getName(), mapKeyField, requirement), toThriftField(mapValueField.getName(), mapValueField, requirement));
            break;
        case SET:
            final Field setElemField = field.getSetElemField();
            type = new ThriftType.SetType(toThriftField(setElemField.getName(), setElemField, requirement));
            break;
        case LIST:
            final Field listElemField = field.getListElemField();
            type = new ThriftType.ListType(toThriftField(listElemField.getName(), listElemField, requirement));
            break;
        case ENUM:
            Collection<TEnum> enumValues = field.getEnumValues();
            List<EnumValue> values = new ArrayList<ThriftType.EnumValue>();
            for (TEnum tEnum : enumValues) {
                values.add(new EnumValue(tEnum.getValue(), tEnum.toString()));
            }
            type = new EnumType(values);
            break;
    }
    return new ThriftField(name, field.getId(), requirement, type);
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) ArrayList(java.util.ArrayList) ThriftField(org.apache.parquet.thrift.struct.ThriftField) ThriftField(org.apache.parquet.thrift.struct.ThriftField) Field(com.twitter.elephantbird.thrift.TStructDescriptor.Field) FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) TEnum(org.apache.thrift.TEnum)

Example 9 with ThriftType

use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.

the class ScroogeStructConverter method toThriftField.

/**
 * Convert a field in scrooge to ThriftField in parquet
 */
public ThriftField toThriftField(ThriftStructFieldInfo scroogeField) {
    Requirement requirement = getRequirementType(scroogeField);
    String fieldName = scroogeField.tfield().name;
    short fieldId = scroogeField.tfield().id;
    byte thriftTypeByte = scroogeField.tfield().type;
    ThriftTypeID typeId = ThriftTypeID.fromByte(thriftTypeByte);
    ThriftType thriftType;
    switch(typeId) {
        case BOOL:
            thriftType = new ThriftType.BoolType();
            break;
        case BYTE:
            thriftType = new ThriftType.ByteType();
            break;
        case DOUBLE:
            thriftType = new ThriftType.DoubleType();
            break;
        case I16:
            thriftType = new ThriftType.I16Type();
            break;
        case I32:
            thriftType = new ThriftType.I32Type();
            break;
        case I64:
            thriftType = new ThriftType.I64Type();
            break;
        case STRING:
            ThriftType.StringType stringType = new ThriftType.StringType();
            // binary data is represented by String type with an additional binary flag.
            if (!String.class.equals(scroogeField.manifest().runtimeClass())) {
                stringType.setBinary(true);
            }
            thriftType = stringType;
            break;
        case STRUCT:
            thriftType = convertStructTypeField(scroogeField);
            break;
        case MAP:
            thriftType = convertMapTypeField(scroogeField, requirement);
            break;
        case SET:
            thriftType = convertSetTypeField(scroogeField, requirement);
            break;
        case LIST:
            thriftType = convertListTypeField(scroogeField, requirement);
            break;
        case ENUM:
            thriftType = convertEnumTypeField(scroogeField);
            break;
        case STOP:
        case VOID:
        default:
            throw new IllegalArgumentException("can't convert type " + typeId);
    }
    return new ThriftField(fieldName, fieldId, requirement, thriftType);
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) ThriftField(org.apache.parquet.thrift.struct.ThriftField) Requirement(org.apache.parquet.thrift.struct.ThriftField.Requirement) ThriftTypeID(org.apache.parquet.thrift.struct.ThriftTypeID)

Aggregations

ThriftType (org.apache.parquet.thrift.struct.ThriftType)9 ThriftField (org.apache.parquet.thrift.struct.ThriftField)5 ArrayList (java.util.ArrayList)2 StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)2 Field (com.twitter.elephantbird.thrift.TStructDescriptor.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 GroupColumnIO (org.apache.parquet.io.GroupColumnIO)1 PrimitiveColumnIO (org.apache.parquet.io.PrimitiveColumnIO)1 Requirement (org.apache.parquet.thrift.struct.ThriftField.Requirement)1 EnumType (org.apache.parquet.thrift.struct.ThriftType.EnumType)1 ListType (org.apache.parquet.thrift.struct.ThriftType.ListType)1 MapType (org.apache.parquet.thrift.struct.ThriftType.MapType)1 SetType (org.apache.parquet.thrift.struct.ThriftType.SetType)1 ThriftTypeID (org.apache.parquet.thrift.struct.ThriftTypeID)1 TEnum (org.apache.thrift.TEnum)1 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)1 TProtocol (org.apache.thrift.protocol.TProtocol)1