This is an automated email from the ASF dual-hosted git repository. cwylie pushed a commit to branch 35.0.1 in repository https://gitbox.apache.org/repos/asf/druid.git
commit 0da44fe94c53a9f1e6cf3e0265aacf5f441956d6 Author: Hiroshi Fukada <[email protected]> AuthorDate: Tue Nov 25 18:55:17 2025 -0500 fix(protobuf-core): re-introduce the load-by-file-path/url protobuf descriptors (#18770) * fix(protobuf-core): re-introduce the load-by-file-path/url protobuf descriptors * fix: typo and refactor with context --- .../protobuf/FileBasedProtobufBytesDecoder.java | 33 +++++++++++++++++++--- .../FileBasedProtobufBytesDecoderTest.java | 13 ++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java index 39ce2520f42..1f5b19ab0b6 100644 --- a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java +++ b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java @@ -27,6 +27,8 @@ import org.apache.druid.java.util.common.parsers.ParseException; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Objects; public class FileBasedProtobufBytesDecoder extends DescriptorBasedProtobufBytesDecoder @@ -56,12 +58,35 @@ public class FileBasedProtobufBytesDecoder extends DescriptorBasedProtobufBytesD @Override protected DescriptorProtos.FileDescriptorSet loadFileDescriptorSet() { - try (InputStream fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath)) { + InputStream fin; + DescriptorProtos.FileDescriptorSet descriptorSet; + try { + fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath); if (fin == null) { - throw new ParseException(descriptorFilePath, "Descriptor not found in class path [%s]", descriptorFilePath); + URL url; + try { + url = new URL(descriptorFilePath); + } + catch (MalformedURLException e) { + throw new ParseException( + descriptorFilePath, + e, + "Descriptor not found in class path or malformed URL: [%s]", descriptorFilePath + ); + } + try (InputStream urlIn = url.openConnection().getInputStream()) { + if (urlIn == null) { + throw new ParseException( + descriptorFilePath, + "Descriptor not found at URL: [%s]", descriptorFilePath + ); + } + descriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(urlIn); + } + } else { + descriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(fin); } - final var descriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(fin); if (descriptorSet.getFileCount() == 0) { throw new ParseException(null, "No file descriptors found in the descriptor set"); } @@ -69,7 +94,7 @@ public class FileBasedProtobufBytesDecoder extends DescriptorBasedProtobufBytesD return descriptorSet; } catch (IOException e) { - throw new ParseException(descriptorFilePath, e, "Failed to initialize descriptor"); + throw new ParseException(descriptorFilePath, e, "Failed to initialize descriptor at [%s]", descriptorFilePath); } } diff --git a/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoderTest.java b/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoderTest.java index 5bcc4ffbeb6..7a4b693b51d 100644 --- a/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoderTest.java +++ b/extensions-core/protobuf-extensions/src/test/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoderTest.java @@ -25,6 +25,7 @@ import com.google.protobuf.util.JsonFormat; import org.apache.druid.java.util.common.parsers.ParseException; import org.junit.jupiter.api.Test; +import java.io.File; import java.nio.ByteBuffer; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -67,6 +68,16 @@ public class FileBasedProtobufBytesDecoderTest assertEquals("prototest.ProtoNestedEvent", decoder.getDescriptor().getFullName()); } + @Test + public void testDescriptorUrl() + { + File descFile = new File("src/test/resources/proto_test_event.desc"); + String path = descFile.getAbsoluteFile().toString(); + + final var decoder = new FileBasedProtobufBytesDecoder("file://" + path, "ProtoTestEvent"); + assertEquals("prototest.ProtoTestEvent", decoder.getDescriptor().getFullName()); + } + @Test public void testParsingWithMoreComplexProtoFile() throws Exception { @@ -122,7 +133,7 @@ public class FileBasedProtobufBytesDecoderTest ); assertEquals( - "Descriptor not found in class path [file:/nonexist.desc]", + "Failed to initialize descriptor at [file:/nonexist.desc]", ex.getMessage() ); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
