Search in sources :

Example 11 with ThriftField

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

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

the class ThriftSchemaConverter method toStructType.

private static StructType toStructType(TStructDescriptor struct) {
    List<Field> fields = struct.getFields();
    List<ThriftField> children = new ArrayList<ThriftField>(fields.size());
    for (Field field : fields) {
        Requirement req = field.getFieldMetaData() == null ? Requirement.OPTIONAL : Requirement.fromType(field.getFieldMetaData().requirementType);
        children.add(toThriftField(field.getName(), field, req));
    }
    return new StructType(children, structOrUnionType(struct.getThriftClass()));
}
Also used : ThriftField(org.apache.parquet.thrift.struct.ThriftField) Field(com.twitter.elephantbird.thrift.TStructDescriptor.Field) Requirement(org.apache.parquet.thrift.struct.ThriftField.Requirement) ArrayList(java.util.ArrayList) ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 13 with ThriftField

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

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

the class ProtocolEventsAmender method checkStruct.

private void checkStruct(Iterator<TProtocol> eventIter, ThriftType.StructType thriftStructType) throws TException {
    TStruct tStruct = acceptProtocol(eventIter.next()).readStructBegin();
    List<ThriftField> childrenFields = thriftStructType.getChildren();
    Set<Short> includedFieldsIds = new HashSet<Short>();
    while (true) {
        TProtocol next = eventIter.next();
        TField field = next.readFieldBegin();
        if (isStopField(field))
            break;
        acceptProtocol(next);
        includedFieldsIds.add(field.id);
        ThriftField fieldDefinition = thriftStructType.getChildById(field.id);
        checkField(field.type, eventIter, fieldDefinition);
        acceptProtocol(eventIter.next()).readFieldEnd();
    }
    for (ThriftField requiredField : childrenFields) {
        if (!isRequired(requiredField)) {
            continue;
        }
        if (!includedFieldsIds.contains(requiredField.getFieldId())) {
            fixedEvents.addAll(new DefaultProtocolEventsGenerator().createProtocolEventsForField(requiredField));
        }
    }
    acceptProtocol(DefaultProtocolEventsGenerator.READ_FIELD_STOP);
    acceptProtocol(eventIter.next()).readStructEnd();
}
Also used : ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 15 with ThriftField

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

the class ProtocolEventsAmender method checkMap.

private void checkMap(Iterator<TProtocol> eventIter, ThriftField mapFieldForWriting) throws TException {
    TMap thriftMap = acceptProtocol(eventIter.next()).readMapBegin();
    ThriftField keyFieldForWriting = ((ThriftType.MapType) mapFieldForWriting.getType()).getKey();
    ThriftField valueFieldForWriting = ((ThriftType.MapType) mapFieldForWriting.getType()).getValue();
    int mapSize = thriftMap.size;
    for (int i = 0; i < mapSize; i++) {
        // readkey
        checkField(thriftMap.keyType, eventIter, keyFieldForWriting);
        // readValue
        checkField(thriftMap.valueType, eventIter, valueFieldForWriting);
    }
    acceptProtocol(eventIter.next()).readMapEnd();
}
Also used : 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