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



##########
File path: 
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoMessageSchema.java
##########
@@ -129,68 +129,29 @@ public SchemaUserTypeCreator schemaTypeCreator(Class<?> 
targetClass, Schema sche
     "rawtypes", // TODO(https://issues.apache.org/jira/browse/BEAM-10556)
     "unchecked"
   })
-  public static <T> SimpleFunction<byte[], Row> getProtoBytesToRowFn(Class<T> 
clazz) {
+  public static <T extends Message> 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);
-      }
-    }
+    final ProtoCoder<T> protoCoder = ProtoCoder.of(clazz);
+    final SerializableFunction<T, Row> toRowFunction =
+        new ProtoMessageSchema().toRowFunction(TypeDescriptor.of(clazz));
+    return new SqlRows.BytesToRowFn<>(protoCoder.getParser()::parseFrom, 
toRowFunction);
   }
 
   // Other modules are not allowed to use non-vendored Message class
   @SuppressWarnings({
     "rawtypes", // TODO(https://issues.apache.org/jira/browse/BEAM-10556)
     "unchecked"
   })
-  public static <T> SimpleFunction<Row, byte[]> getRowToProtoBytesFn(Class<T> 
clazz) {
+  public static <T extends Message> SimpleFunction<Row, byte[]> 
getRowToProtoBytesFn(

Review comment:
       reverted




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