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 2022/10/06 22:40:34 UTC

[GitHub] [druid] jon-wei opened a new pull request, #13192: Add inline descriptor Protobuf bytes decoder

jon-wei opened a new pull request, #13192:
URL: https://github.com/apache/druid/pull/13192

   This PR adds a new ProtobufBytesDecoder implementation that allows the user to pass inline the contents of a Protobuf descriptor file, encoded as a Base64 string. 
   
   This can be useful when the user does not have the ability/convenience of placing files on the filesystems of the Druid cluster nodes.
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] abhishekagarwal87 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990607935


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;
+    this.protoMessageType = protoMessageType;
+    initDescriptor();
+  }
+
+  @JsonProperty
+  public String getDescriptorString()
+  {
+    return descriptorString;
+  }
+
+  @JsonProperty
+  public String getProtoMessageType()
+  {
+    return protoMessageType;
+  }
+
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorString);
+    }
+  }
+
+  @Override
+  public DynamicMessage parse(ByteBuffer bytes)
+  {
+    try {
+      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
+      return message;
+    }
+    catch (Exception e) {
+      throw new ParseException(null, e, "Fail to decode protobuf message!");
+    }
+  }
+
+  private Descriptors.Descriptor getDescriptor(String descriptorString)
+  {
+    DynamicSchema dynamicSchema;
+    try {
+      byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);

Review Comment:
   I agree that it is not a kind of exception that we can just move over. Though @FrankChen021  makes a good point of surfacing a nicer user-friendly error and throwing an IAE isn't a good way of getting that done. 
   @jon-wei - What error does the user get with this change if the descriptor string is not valid / can't be decoded? 



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] FrankChen021 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990093245


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;

Review Comment:
   Better to check if it's null



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] FrankChen021 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990590459


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;
+    this.protoMessageType = protoMessageType;
+    initDescriptor();
+  }
+
+  @JsonProperty
+  public String getDescriptorString()
+  {
+    return descriptorString;
+  }
+
+  @JsonProperty
+  public String getProtoMessageType()
+  {
+    return protoMessageType;
+  }
+
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorString);
+    }
+  }
+
+  @Override
+  public DynamicMessage parse(ByteBuffer bytes)
+  {
+    try {
+      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
+      return message;
+    }
+    catch (Exception e) {
+      throw new ParseException(null, e, "Fail to decode protobuf message!");
+    }
+  }
+
+  private Descriptors.Descriptor getDescriptor(String descriptorString)
+  {
+    DynamicSchema dynamicSchema;
+    try {
+      byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);

Review Comment:
   But other exceptions caught by the try-catch here are turned into `ParseException`. 
   
   My concern is that, if the descriptorString is not a valid base64 string, the thrown `IllegalArgumentException` is not a user-face exception that maybe it's not intuitive for user to realize it's due to the wrong input instead they might think there's bug at the Druid server side.



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] FrankChen021 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990091871


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;
+    this.protoMessageType = protoMessageType;
+    initDescriptor();
+  }
+
+  @JsonProperty
+  public String getDescriptorString()
+  {
+    return descriptorString;
+  }
+
+  @JsonProperty
+  public String getProtoMessageType()
+  {
+    return protoMessageType;
+  }
+
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorString);
+    }
+  }
+
+  @Override
+  public DynamicMessage parse(ByteBuffer bytes)
+  {
+    try {
+      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
+      return message;
+    }
+    catch (Exception e) {
+      throw new ParseException(null, e, "Fail to decode protobuf message!");
+    }
+  }
+
+  private Descriptors.Descriptor getDescriptor(String descriptorString)
+  {
+    DynamicSchema dynamicSchema;
+    try {
+      byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);

Review Comment:
   In case of decode failure, `IllegalArgumentException` is thrown. We should catch it and turn it into a `ParseException`



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] jon-wei commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
jon-wei commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r991553682


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;
+    this.protoMessageType = protoMessageType;
+    initDescriptor();
+  }
+
+  @JsonProperty
+  public String getDescriptorString()
+  {
+    return descriptorString;
+  }
+
+  @JsonProperty
+  public String getProtoMessageType()
+  {
+    return protoMessageType;
+  }
+
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorString);
+    }
+  }
+
+  @Override
+  public DynamicMessage parse(ByteBuffer bytes)
+  {
+    try {
+      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
+      return message;
+    }
+    catch (Exception e) {
+      throw new ParseException(null, e, "Fail to decode protobuf message!");
+    }
+  }
+
+  private Descriptors.Descriptor getDescriptor(String descriptorString)
+  {
+    DynamicSchema dynamicSchema;
+    try {
+      byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);

Review Comment:
   Updated to catch `IllegalArgumentException` and throw a new exception indicating Base64 encoding was not valid.
   
   For valid Base64 and invalid descriptor the existing block 
   ```
       catch (Descriptors.DescriptorValidationException e) {
         throw new ParseException(null, e, "Invalid descriptor string: " + descriptorString);
       }
   ```
   handles that



##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder

Review Comment:
   Refactored to share a base calss



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] jon-wei merged pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
jon-wei merged PR #13192:
URL: https://github.com/apache/druid/pull/13192


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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] FrankChen021 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990092904


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder

Review Comment:
   This implementation is very similar to `FileBasedProtobufBytesDecoder`. I'm wondering if we can abstract some code so that these two classes can share them?



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] jon-wei commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
jon-wei commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r990565379


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;
+    this.protoMessageType = protoMessageType;
+    initDescriptor();
+  }
+
+  @JsonProperty
+  public String getDescriptorString()
+  {
+    return descriptorString;
+  }
+
+  @JsonProperty
+  public String getProtoMessageType()
+  {
+    return protoMessageType;
+  }
+
+  @VisibleForTesting
+  void initDescriptor()
+  {
+    if (this.descriptor == null) {
+      this.descriptor = getDescriptor(descriptorString);
+    }
+  }
+
+  @Override
+  public DynamicMessage parse(ByteBuffer bytes)
+  {
+    try {
+      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
+      return message;
+    }
+    catch (Exception e) {
+      throw new ParseException(null, e, "Fail to decode protobuf message!");
+    }
+  }
+
+  private Descriptors.Descriptor getDescriptor(String descriptorString)
+  {
+    DynamicSchema dynamicSchema;
+    try {
+      byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);

Review Comment:
   If the descriptor can't be decoded, then we can't proceed, since we won't be able to parse any records, so I don't think this should be a parse exception



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] FrankChen021 commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r991758310


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -58,64 +53,22 @@ public String getDescriptorString()
     return descriptorString;
   }
 
-  @JsonProperty
-  public String getProtoMessageType()
-  {
-    return protoMessageType;
-  }
-
-  @VisibleForTesting
-  void initDescriptor()
-  {
-    if (this.descriptor == null) {
-      this.descriptor = getDescriptor(descriptorString);
-    }
-  }
-
   @Override
-  public DynamicMessage parse(ByteBuffer bytes)
+  protected DynamicSchema generateDynamicSchema()
   {
-    try {
-      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(bytes));
-      return message;
-    }
-    catch (Exception e) {
-      throw new ParseException(null, e, "Fail to decode protobuf message!");
-    }
-  }
-
-  private Descriptors.Descriptor getDescriptor(String descriptorString)
-  {
-    DynamicSchema dynamicSchema;
     try {
       byte[] decodedDesc = StringUtils.decodeBase64String(descriptorString);
-      dynamicSchema = DynamicSchema.parseFrom(decodedDesc);
+      return DynamicSchema.parseFrom(decodedDesc);
+    }
+    catch (IllegalArgumentException e) {
+      throw new IAE("Descriptor string was did not have valid Base64 encoding.");

Review Comment:
   ```suggestion
         throw new IAE("Descriptor string does not have valid Base64 encoding.");
   ```



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [druid] jon-wei commented on a diff in pull request #13192: Add inline descriptor Protobuf bytes decoder

Posted by GitBox <gi...@apache.org>.
jon-wei commented on code in PR #13192:
URL: https://github.com/apache/druid/pull/13192#discussion_r991553871


##########
extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/InlineDescriptorProtobufBytesDecoder.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.protobuf.ByteString;
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.ParseException;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Set;
+
+public class InlineDescriptorProtobufBytesDecoder implements ProtobufBytesDecoder
+{
+  private final String descriptorString;
+  private final String protoMessageType;
+  private Descriptors.Descriptor descriptor;
+
+
+  @JsonCreator
+  public InlineDescriptorProtobufBytesDecoder(
+      @JsonProperty("descriptorString") String descriptorString,
+      @JsonProperty("protoMessageType") String protoMessageType
+  )
+  {
+    this.descriptorString = descriptorString;

Review Comment:
   Added null checks



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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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