You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2018/11/29 05:59:31 UTC

[GitHub] fjy closed pull request #6678: lazy create descriptor in ProtobufInputRowParser

fjy closed pull request #6678: lazy create descriptor in ProtobufInputRowParser
URL: https://github.com/apache/incubator-druid/pull/6678
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParser.java b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParser.java
index b75e4002850..81ddb444092 100644
--- a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParser.java
+++ b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParser.java
@@ -22,6 +22,7 @@
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.github.os72.protobuf.dynamic.DynamicSchema;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -53,7 +54,7 @@
   private final ParseSpec parseSpec;
   private final String descriptorFilePath;
   private final String protoMessageType;
-  private final Descriptor descriptor;
+  private Descriptor descriptor;
   private Parser<String, Object> parser;
   private final List<String> dimensions;
 
@@ -67,7 +68,6 @@ public ProtobufInputRowParser(
     this.parseSpec = parseSpec;
     this.descriptorFilePath = descriptorFilePath;
     this.protoMessageType = protoMessageType;
-    this.descriptor = getDescriptor(descriptorFilePath);
     this.dimensions = parseSpec.getDimensionsSpec().getDimensionNames();
   }
 
@@ -83,6 +83,14 @@ public ProtobufInputRowParser withParseSpec(ParseSpec parseSpec)
     return new ProtobufInputRowParser(parseSpec, descriptorFilePath, protoMessageType);
   }
 
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorFilePath);
+    }
+  }
+
   @Override
   public List<InputRow> parseBatch(ByteBuffer input)
   {
@@ -90,6 +98,7 @@ public ProtobufInputRowParser withParseSpec(ParseSpec parseSpec)
       // parser should be created when it is really used to avoid unnecessary initialization of the underlying
       // parseSpec.
       parser = parseSpec.makeParser();
+      initDescriptor();
     }
     String json;
     try {
diff --git a/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParserTest.java b/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParserTest.java
index 92cefd34f17..081fc23a24f 100644
--- a/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParserTest.java
+++ b/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/ProtobufInputRowParserTest.java
@@ -83,7 +83,7 @@ public void testShortMessageType()
     //configure parser with desc file, and specify which file name to use
     @SuppressWarnings("unused") // expected to create parser without exception
     ProtobufInputRowParser parser = new ProtobufInputRowParser(parseSpec, "prototest.desc", "ProtoTestEvent");
-
+    parser.initDescriptor();
   }
 
 
@@ -93,7 +93,7 @@ public void testLongMessageType()
     //configure parser with desc file, and specify which file name to use
     @SuppressWarnings("unused") // expected to create parser without exception
     ProtobufInputRowParser parser = new ProtobufInputRowParser(parseSpec, "prototest.desc", "prototest.ProtoTestEvent");
-
+    parser.initDescriptor();
   }
 
 
@@ -103,7 +103,7 @@ public void testBadProto()
     //configure parser with desc file
     @SuppressWarnings("unused") // expected exception
     ProtobufInputRowParser parser = new ProtobufInputRowParser(parseSpec, "prototest.desc", "BadName");
-
+    parser.initDescriptor();
   }
 
   @Test(expected = ParseException.class)
@@ -112,6 +112,7 @@ public void testMalformedDescriptorUrl()
     //configure parser with non existent desc file
     @SuppressWarnings("unused") // expected exception
     ProtobufInputRowParser parser = new ProtobufInputRowParser(parseSpec, "file:/nonexist.desc", "BadName");
+    parser.initDescriptor();
   }
 
   @Test
@@ -120,6 +121,7 @@ public void testSingleDescriptorNoMessageType()
     // For the backward compatibility, protoMessageType allows null when the desc file has only one message type.
     @SuppressWarnings("unused") // expected to create parser without exception
     ProtobufInputRowParser parser = new ProtobufInputRowParser(parseSpec, "prototest.desc", null);
+    parser.initDescriptor();
   }
 
   @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org