Search in sources :

Example 1 with Requirement

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

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

ThriftField (org.apache.parquet.thrift.struct.ThriftField)2 Requirement (org.apache.parquet.thrift.struct.ThriftField.Requirement)2 Field (com.twitter.elephantbird.thrift.TStructDescriptor.Field)1 ArrayList (java.util.ArrayList)1 ThriftType (org.apache.parquet.thrift.struct.ThriftType)1 ThriftTypeID (org.apache.parquet.thrift.struct.ThriftTypeID)1