Search in sources :

Example 16 with ThriftField

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

the class ProtocolEventsAmender method checkList.

private void checkList(Iterator<TProtocol> eventIter, ThriftField listFieldUsedForWriting) throws TException {
    ThriftField valueFieldForWriting = ((ThriftType.ListType) listFieldUsedForWriting.getType()).getValues();
    TList thriftList = acceptProtocol(eventIter.next()).readListBegin();
    int listSize = thriftList.size;
    for (int i = 0; i < listSize; i++) {
        checkField(thriftList.elemType, eventIter, valueFieldForWriting);
    }
    acceptProtocol(eventIter.next()).readListEnd();
}
Also used : ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 17 with ThriftField

use of org.apache.parquet.thrift.struct.ThriftField 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)

Example 18 with ThriftField

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

the class ScroogeStructConverter method convertCompanionClassToStruct.

private ThriftType.StructType convertCompanionClassToStruct(Class<?> companionClass) {
    ThriftStructCodec<?> companionObject;
    try {
        companionObject = (ThriftStructCodec<?>) companionClass.getField("MODULE$").get(null);
    } catch (NoSuchFieldException e) {
        throw new ScroogeSchemaConversionException("Can not get ThriftStructCodec from companion object of " + companionClass.getName(), e);
    } catch (IllegalAccessException e) {
        throw new ScroogeSchemaConversionException("Can not get ThriftStructCodec from companion object of " + companionClass.getName(), e);
    }
    // {@link ThriftType.StructType} uses foreach loop to iterate the children, yields O(n) time for linked list
    List<ThriftField> children = new LinkedList<ThriftField>();
    Iterable<ThriftStructFieldInfo> scroogeFields = getFieldInfos(companionObject);
    for (ThriftStructFieldInfo field : scroogeFields) {
        children.add(toThriftField(field));
    }
    StructOrUnionType structOrUnionType = isUnion(companionObject.getClass()) ? StructOrUnionType.UNION : StructOrUnionType.STRUCT;
    return new ThriftType.StructType(children, structOrUnionType);
}
Also used : StructOrUnionType(org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType) ThriftStructFieldInfo(com.twitter.scrooge.ThriftStructFieldInfo) LinkedList(java.util.LinkedList) ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Aggregations

ThriftField (org.apache.parquet.thrift.struct.ThriftField)18 ThriftType (org.apache.parquet.thrift.struct.ThriftType)7 ArrayList (java.util.ArrayList)4 EnumType (org.apache.parquet.thrift.struct.ThriftType.EnumType)3 StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)3 StructOrUnionType (org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType)3 Field (com.twitter.elephantbird.thrift.TStructDescriptor.Field)2 ConversionPatterns.listType (org.apache.parquet.schema.ConversionPatterns.listType)2 ConversionPatterns.mapType (org.apache.parquet.schema.ConversionPatterns.mapType)2 GroupType (org.apache.parquet.schema.GroupType)2 MessageType (org.apache.parquet.schema.MessageType)2 OriginalType (org.apache.parquet.schema.OriginalType)2 PrimitiveType (org.apache.parquet.schema.PrimitiveType)2 Type (org.apache.parquet.schema.Type)2 Drop (org.apache.parquet.thrift.ConvertedField.Drop)2 Keep (org.apache.parquet.thrift.ConvertedField.Keep)2 Requirement (org.apache.parquet.thrift.struct.ThriftField.Requirement)2 BoolType (org.apache.parquet.thrift.struct.ThriftType.BoolType)2 ByteType (org.apache.parquet.thrift.struct.ThriftType.ByteType)2 DoubleType (org.apache.parquet.thrift.struct.ThriftType.DoubleType)2