You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by fj...@apache.org on 2018/11/29 05:59:34 UTC
[incubator-druid] branch master updated: lazy create descriptor in
ProtobufInputRowParser (#6678)
This is an automated email from the ASF dual-hosted git repository.
fjy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git
The following commit(s) were added to refs/heads/master by this push:
new 624f328 lazy create descriptor in ProtobufInputRowParser (#6678)
624f328 is described below
commit 624f328ea1acfe91d18c07808e51ce80515eeba7
Author: 陈春斌 <cc...@gmail.com>
AuthorDate: Thu Nov 29 13:59:29 2018 +0800
lazy create descriptor in ProtobufInputRowParser (#6678)
---
.../druid/data/input/protobuf/ProtobufInputRowParser.java | 13 +++++++++++--
.../data/input/protobuf/ProtobufInputRowParserTest.java | 8 +++++---
2 files changed, 16 insertions(+), 5 deletions(-)
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 b75e400..81ddb44 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 @@ package org.apache.druid.data.input.protobuf;
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 @@ public class ProtobufInputRowParser implements ByteBufferInputRowParser
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 class ProtobufInputRowParser implements ByteBufferInputRowParser
this.parseSpec = parseSpec;
this.descriptorFilePath = descriptorFilePath;
this.protoMessageType = protoMessageType;
- this.descriptor = getDescriptor(descriptorFilePath);
this.dimensions = parseSpec.getDimensionsSpec().getDimensionNames();
}
@@ -83,6 +83,14 @@ public class ProtobufInputRowParser implements ByteBufferInputRowParser
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 class ProtobufInputRowParser implements ByteBufferInputRowParser
// 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 92cefd3..081fc23 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 class ProtobufInputRowParserTest
//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 class ProtobufInputRowParserTest
//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 class ProtobufInputRowParserTest
//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 class ProtobufInputRowParserTest
//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 class ProtobufInputRowParserTest
// 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org