use of org.apache.beam.sdk.schemas.utils.AvroUtils.AvroTypeConversionFactory in project beam by apache.
the class AvroByteBuddyUtils method readAndConvertParameter.
private static StackManipulation readAndConvertParameter(Class<?> constructorParameterType, int index) {
TypeConversionsFactory typeConversionsFactory = new AvroTypeConversionFactory();
// The types in the AVRO-generated constructor might be the types returned by Beam's Row class,
// so we have to convert the types used by Beam's Row class.
// We know that AVRO generates constructor parameters in the same order as fields
// in the schema, so we can just add the parameters sequentially.
TypeConversion<Type> convertType = typeConversionsFactory.createTypeConversion(true);
// Map the AVRO-generated type to the one Beam will use.
ForLoadedType convertedType = new ForLoadedType((Class) convertType.convert(TypeDescriptor.of(constructorParameterType)));
// This will run inside the generated creator. Read the parameter and convert it to the
// type required by the SpecificRecord constructor.
StackManipulation readParameter = new StackManipulation.Compound(MethodVariableAccess.REFERENCE.loadFrom(1), IntegerConstant.forValue(index), ArrayAccess.REFERENCE.load(), TypeCasting.to(convertedType));
// Convert to the parameter accepted by the SpecificRecord constructor.
return typeConversionsFactory.createSetterConversions(readParameter).convert(TypeDescriptor.of(constructorParameterType));
}
Aggregations