ccciudatu commented on a change in pull request #13572:
URL: https://github.com/apache/beam/pull/13572#discussion_r548433396
##########
File path:
sdks/java/io/thrift/src/main/java/org/apache/beam/sdk/io/thrift/ThriftSchema.java
##########
@@ -243,37 +253,65 @@ private FieldValueTypeInformation
fieldValueTypeInfo(Class<?> type, String field
@Override
public @NonNull SchemaUserTypeCreator schemaTypeCreator(
@NonNull Class<?> targetClass, @NonNull Schema schema) {
- return params -> restoreThriftObject(targetClass, params);
+ return thriftMapper(targetClass, schema);
+ }
+
+ private <FieldT extends Enum<FieldT> & TFieldIdEnum, T extends TBase<T,
FieldT>>
+ SchemaUserTypeCreator thriftMapper(Class<?> targetClass, Schema schema) {
+ final Map<FieldT, FieldMetaData> fieldDescriptors =
schemaFieldDescriptors(targetClass, schema);
+ return params -> restoreThriftObject(targetClass, fieldDescriptors,
params);
}
+ @SuppressWarnings("nullness")
private <FieldT extends Enum<FieldT> & TFieldIdEnum, T extends TBase<T,
FieldT>>
- T restoreThriftObject(Class<?> targetClass, Object[] params) {
+ Map<FieldT, FieldMetaData> schemaFieldDescriptors(Class<?> targetClass,
Schema schema) {
Review comment:
This allows using the order of fields in the incoming schema, instead of
the original order in the thrift descriptor, so this will still work if fields
are reordered by clients (the shuffled schema table test validates this).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]