use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.
the class ScroogeStructConverter method convertMapTypeField.
private ThriftType convertMapTypeField(String fieldName, Manifest<?> keyManifest, Manifest<?> valueManifest, Requirement requirement) {
String keyName = mapKeyName(fieldName);
String valueName = mapValueName(fieldName);
ThriftType keyType = convertClassToThriftType(keyName, requirement, keyManifest);
ThriftField keyField = generateFieldWithoutId(keyName, requirement, keyType);
ThriftType valueType = convertClassToThriftType(valueName, requirement, valueManifest);
ThriftField valueField = generateFieldWithoutId(valueName, requirement, valueType);
return new ThriftType.MapType(keyField, valueField);
}
use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.
the class ScroogeStructConverter method convertEnumTypeField.
private ThriftType convertEnumTypeField(Class enumClass, String fieldName) {
List<ThriftType.EnumValue> enumValues = new ArrayList<ThriftType.EnumValue>();
String enumName = enumClass.getName();
try {
List enumCollection = getEnumList(enumName);
for (Object enumObj : enumCollection) {
ScroogeEnumDesc enumDesc = ScroogeEnumDesc.fromEnum(enumObj);
enumValues.add(new ThriftType.EnumValue(enumDesc.id, enumDesc.originalName));
}
return new ThriftType.EnumType(enumValues);
} catch (RuntimeException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
} catch (NoSuchMethodException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
} catch (IllegalAccessException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
} catch (NoSuchFieldException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
} catch (InvocationTargetException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
} catch (ClassNotFoundException e) {
throw new ScroogeSchemaConversionException("Can not convert enum field " + fieldName, e);
}
}
use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.
the class ScroogeStructConverter method convertClassToThriftType.
/**
* In composite types, such as the type of the key in a map, since we use reflection to get the type class, this method
* does conversion based on the class provided.
*
* @return converted ThriftType
*/
private ThriftType convertClassToThriftType(String name, Requirement requirement, Manifest<?> typeManifest) {
Class typeClass = typeManifest.runtimeClass();
if (typeManifest.runtimeClass() == boolean.class) {
return new ThriftType.BoolType();
} else if (typeClass == byte.class) {
return new ThriftType.ByteType();
} else if (typeClass == double.class) {
return new ThriftType.DoubleType();
} else if (typeClass == short.class) {
return new ThriftType.I16Type();
} else if (typeClass == int.class) {
return new ThriftType.I32Type();
} else if (typeClass == long.class) {
return new ThriftType.I64Type();
} else if (typeClass == String.class) {
return new ThriftType.StringType();
} else if (typeClass == ByteBuffer.class) {
return new ThriftType.StringType();
} else if (typeClass == scala.collection.Seq.class) {
Manifest<?> a = typeManifest.typeArguments().apply(0);
return convertListTypeField(name, a, requirement);
} else if (typeClass == scala.collection.Set.class) {
Manifest<?> setElementManifest = typeManifest.typeArguments().apply(0);
return convertSetTypeField(name, setElementManifest, requirement);
} else if (typeClass == scala.collection.Map.class) {
List<Manifest<?>> ms = JavaConversions.seqAsJavaList(typeManifest.typeArguments());
Manifest keyManifest = ms.get(0);
Manifest valueManifest = ms.get(1);
return convertMapTypeField(name, keyManifest, valueManifest, requirement);
} else if (com.twitter.scrooge.ThriftEnum.class.isAssignableFrom(typeClass)) {
return convertEnumTypeField(typeClass, name);
} else {
return convertStructFromClass(typeClass);
}
}
use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.
the class ScroogeStructConverter method convertSetTypeField.
private ThriftType convertSetTypeField(String fieldName, Manifest<?> valueManifest, Requirement requirement) {
String elemName = setElemName(fieldName);
ThriftType elementType = convertClassToThriftType(elemName, requirement, valueManifest);
// Set only has one sub-field as element field, therefore using hard-coded 1 as fieldId,
// it's the same as the solution used in ElephantBird
ThriftField elementField = generateFieldWithoutId(elemName, requirement, elementType);
return new ThriftType.SetType(elementField);
}
use of org.apache.parquet.thrift.struct.ThriftType in project parquet-mr by apache.
the class TestThriftSchemaConverter method testToThriftType.
@Test
public void testToThriftType() throws Exception {
final StructType converted = ThriftSchemaConverter.toStructType(AddressBook.class);
final String json = converted.toJSON();
final ThriftType fromJSON = StructType.fromJSON(json);
assertEquals(json, fromJSON.toJSON());
}
Aggregations