ccciudatu commented on a change in pull request #13572:
URL: https://github.com/apache/beam/pull/13572#discussion_r546433681



##########
File path: 
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoMessageSchema.java
##########
@@ -130,28 +129,12 @@ public SchemaUserTypeCreator schemaTypeCreator(Class<?> 
targetClass, Schema sche
     "unchecked"
   })
   public static <T> SimpleFunction<byte[], Row> getProtoBytesToRowFn(Class<T> 
clazz) {
-    checkForMessageType(clazz);
-    return new ProtoBytesToRowFn(clazz);
-  }
-
-  private static class ProtoBytesToRowFn<T extends Message> extends 
SimpleFunction<byte[], Row> {
-    private final ProtoCoder<T> protoCoder;
-    private final SerializableFunction<T, Row> toRowFunction;
-
-    public ProtoBytesToRowFn(Class<T> clazz) {
-      this.protoCoder = ProtoCoder.of(clazz);
-      this.toRowFunction = new 
ProtoMessageSchema().toRowFunction(TypeDescriptor.of(clazz));
-    }
-
-    @Override
-    public Row apply(byte[] bytes) {
-      try {
-        T message = protoCoder.getParser().parseFrom(bytes);
-        return toRowFunction.apply(message);
-      } catch (IOException e) {
-        throw new IllegalArgumentException("Could not decode row from proto 
payload.", e);
-      }
-    }
+    Class<Message> protoClass = ensureMessageType(clazz);
+    ProtoCoder<Message> protoCoder = ProtoCoder.of(protoClass);
+    return new SqlRows.BytesToRowFn<>(
+        new ProtoMessageSchema(),
+        TypeDescriptor.of(protoClass),
+        bytes -> protoCoder.getParser().parseFrom(bytes));

Review comment:
       this can't be a method reference (`protoCoder.getParser()::parseFrom`) 
because the protobuf `Parser` is not `Serializable`.




----------------------------------------------------------------
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]


Reply via email to