Search in sources :

Example 1 with StructOrUnionType

use of org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType 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

ThriftStructFieldInfo (com.twitter.scrooge.ThriftStructFieldInfo)1 LinkedList (java.util.LinkedList)1 ThriftField (org.apache.parquet.thrift.struct.ThriftField)1 StructOrUnionType (org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType)1