use of com.twitter.scrooge.ThriftStructFieldInfo in project parquet-mr by apache.
the class ScroogeStructConverter method getFieldInfosForUnion.
private Iterable<ThriftStructFieldInfo> getFieldInfosForUnion(Class klass) {
ArrayList<ThriftStructFieldInfo> fields = new ArrayList<ThriftStructFieldInfo>();
for (Field f : klass.getDeclaredFields()) {
if (f.getType().equals(Manifest.class)) {
Class unionClass = (Class) ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0];
Class companionUnionClass = getCompanionClass(unionClass);
try {
Object companionUnionObj = companionUnionClass.getField("MODULE$").get(null);
ThriftStructFieldInfo info = (ThriftStructFieldInfo) companionUnionClass.getMethod("fieldInfo").invoke(companionUnionObj);
fields.add(info);
} catch (NoSuchFieldException e) {
throw new ScroogeSchemaConversionException("can not find fieldInfo for " + unionClass, e);
} catch (InvocationTargetException e) {
throw new ScroogeSchemaConversionException("can not find fieldInfo for " + unionClass, e);
} catch (NoSuchMethodException e) {
throw new ScroogeSchemaConversionException("can not find fieldInfo for " + unionClass, e);
} catch (IllegalAccessException e) {
throw new ScroogeSchemaConversionException("can not find fieldInfo for " + unionClass, e);
}
}
}
return fields;
}
use of com.twitter.scrooge.ThriftStructFieldInfo 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