jihoonson commented on a change in pull request #8623: Consolidate and bump the 
protobuf version
URL: https://github.com/apache/druid/pull/8623#discussion_r398210684
 
 

 ##########
 File path: 
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParser.java
 ##########
 @@ -127,49 +127,59 @@ void initDescriptor()
 
   private Descriptor getDescriptor(String descriptorFilePath)
   {
-    InputStream fin;
-
-    fin = 
this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath);
+    InputStream fin = 
this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath);
     if (fin == null) {
-      URL url;
       try {
-        url = new URL(descriptorFilePath);
+        final URL url = new URL(descriptorFilePath);
+        fin = url.openConnection().getInputStream();
       }
       catch (MalformedURLException e) {
         throw new ParseException(e, "Descriptor not found in class path or 
malformed URL:" + descriptorFilePath);
       }
-      try {
-        fin = url.openConnection().getInputStream();
-      }
       catch (IOException e) {
-        throw new ParseException(e, "Cannot read descriptor file: " + url);
+        throw new ParseException(e, "Cannot read descriptor file: " + 
descriptorFilePath);
       }
     }
 
-    DynamicSchema dynamicSchema;
+    final DescriptorProtos.FileDescriptorProto schema;
     try {
-      dynamicSchema = DynamicSchema.parseFrom(fin);
-    }
-    catch (Descriptors.DescriptorValidationException e) {
-      throw new ParseException(e, "Invalid descriptor file: " + 
descriptorFilePath);
+      final DescriptorProtos.FileDescriptorSet set = 
DescriptorProtos.FileDescriptorSet.parseFrom(fin);
+      schema = set.getFile(0);
     }
     catch (IOException e) {
       throw new ParseException(e, "Cannot read descriptor file: " + 
descriptorFilePath);
     }
+    finally {
+      CloseQuietly.close(fin);
+    }
 
-    Set<String> messageTypes = dynamicSchema.getMessageTypes();
-    if (messageTypes.size() == 0) {
+    final Descriptors.FileDescriptor fd;
+    try {
+      fd = Descriptors.FileDescriptor.buildFrom(schema, new 
Descriptors.FileDescriptor[] {});
+    }
+    catch (Descriptors.DescriptorValidationException e) {
+      throw new ParseException(e, "Cannot read descriptor file: " + 
descriptorFilePath);
+    }
+
+    if (schema.getMessageTypeCount() == 0) {
       throw new ParseException("No message types found in the descriptor: " + 
descriptorFilePath);
     }
 
-    String messageType = protoMessageType == null ? (String) 
messageTypes.toArray()[0] : protoMessageType;
-    Descriptor desc = dynamicSchema.getMessageDescriptor(messageType);
+    // Step through the descriptors, and find the correct one
+    Descriptors.Descriptor desc = null;
+    for (Descriptor d : fd.getMessageTypes()) {
+      if (protoMessageType == null || d.getName().equals(protoMessageType) || 
d.getFullName().equals(protoMessageType)) {
 
 Review comment:
   I guess this technically can change the behavior since `messageTypes` was a 
keyset of a `HashMap` while messageTypes is an array. But it doesn't seem 
matter.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to