use of org.apache.thrift.meta_data.StructMetaData in project beam by apache.
the class ThriftSchema method beamType.
private <EnumT extends Enum<EnumT> & TEnum> FieldType beamType(FieldValueMetaData metadata) {
if (metadata.isTypedef()) {
final FieldType beamType = typedefs.get(metadata.getTypedefName());
if (beamType != null) {
return beamType;
}
}
switch(metadata.type) {
case TType.BOOL:
return FieldType.BOOLEAN;
case TType.BYTE:
return FieldType.BYTE;
case TType.I16:
return FieldType.INT16;
case TType.I32:
return FieldType.INT32;
case TType.I64:
return FieldType.INT64;
case TType.DOUBLE:
return FieldType.DOUBLE;
case TType.STRING:
return metadata.isBinary() ? FieldType.BYTES : FieldType.STRING;
case TType.SET:
final FieldValueMetaData setElemMetadata = ((SetMetaData) metadata).elemMetaData;
return FieldType.iterable(beamType(setElemMetadata));
case TType.LIST:
final FieldValueMetaData listElemMetadata = ((ListMetaData) metadata).elemMetaData;
return FieldType.array(beamType(listElemMetadata));
case TType.MAP:
final MapMetaData mapMetadata = ((MapMetaData) metadata);
return FieldType.map(beamType(mapMetadata.keyMetaData), beamType(mapMetadata.valueMetaData));
case TType.STRUCT:
final StructMetaData structMetadata = ((StructMetaData) metadata);
return FieldType.row(schemaFor(structMetadata.structClass));
case TType.ENUM:
@SuppressWarnings("unchecked") final Class<EnumT> enumClass = (Class<EnumT>) ((EnumMetaData) metadata).enumClass;
// it's either "nullness" or "unsafe", apparently
@SuppressWarnings("nullness") final EnumT @NonNull [] enumConstants = enumClass.getEnumConstants();
final String[] enumValues = Stream.of(enumConstants).map(EnumT::name).toArray(String[]::new);
return FieldType.logicalType(EnumerationType.create(enumValues));
default:
throw new IllegalArgumentException("Unsupported thrift type code: " + metadata.type);
}
}
Aggregations