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);
}
Aggregations