ProtoBuf模式的命名空间错误。

huangapple go评论95阅读模式
英文:

ProtoBuf schema having wrong namespace

问题

我已经按照你提供的要求,将代码部分翻译成中文,如下所示:

  1. 我已经定义了我的 Protobuf 模式如下:
  2. message VertexUpdate {
  3. required VertexId id = 1;
  4. map<string, google.protobuf.Value> properties = 2;
  5. optional bool isDelete = 3;
  6. }
  7. message EdgeUpdate {
  8. required EdgeId id = 1;
  9. map<string, google.protobuf.Value> properties = 2;
  10. optional bool isDelete = 3;
  11. }
  12. message GraphUpdate {
  13. required string graphName = 1;
  14. optional VertexUpdate vertexUpdate = 2;
  15. optional EdgeUpdate edgeUpdate = 3;
  16. }
  17. 然后我执行了这段代码:
  18. Graphaction.GraphUpdate graphUpdate = createGraphUpdateObject();
  19. Schema schema = ProtobufData.get().getSchema(Graphaction.GraphUpdate.class);
  20. ProtobufData.get().newRecord(graphUpdate, schema);
  21. 但是这给了我一个错误:
  22. java.lang.RuntimeException: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
  23. at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:144)
  24. ...
  25. 我不知道为什么类名在模式对象中被指定为 "com.mycompany.protos.kgschema.Graphaction_.GraphUpdate",我认为这是问题的根本原因。
  26. 为了确认,我尝试了以下这段代码(试图调用引发异常的方法,使用了正确的类名):
  27. Class<?> out = org.apache.avro.util.ClassUtils.forName("com.mycompany.protos.kgschema.Graphaction$GraphUpdate");
  28. 这段代码能够正常运行,没有任何错误。
  29. 我不明白为什么类的命名空间会在由 ProtobufData.get().getSchema(Graphaction.GraphUpdate.class) 创建的模式对象中出错,
  30. 同时我想知道如何修复这个问题?任何帮助将不胜感激。

请注意,我已经按照你的要求,只返回翻译好的部分,没有包含其他内容。如果你有任何其他问题或需要进一步帮助,请随时提问。

英文:

I have defined my Protobuf schema like this

  1. message VertexUpdate {
  2. required VertexId id = 1;
  3. map&lt;string, google.protobuf.Value&gt; properties = 2;
  4. optional bool isDelete = 3;
  5. }
  6. message EdgeUpdate {
  7. required EdgeId id = 1;
  8. map&lt;string, google.protobuf.Value&gt; properties = 2;
  9. optional bool isDelete = 3;
  10. }
  11. message GraphUpdate {
  12. required string graphName = 1;
  13. optional VertexUpdate vertexUpdate = 2;
  14. optional EdgeUpdate edgeUpdate = 3;
  15. }

and I am executing this code

  1. Graphaction.GraphUpdate graphUpdate = createGraphUpdateObject();
  2. Schema schema = ProtobufData.get().getSchema(Graphaction.GraphUpdate.class);
  3. ProtobufData.get().newRecord(graphUpdate, schema);

which gives me error

  1. java.lang.RuntimeException: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
  2. at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:144)
  3. at com.mycompany.knowledge.graph.ingest.backfill.hlc.GraphUpdateDataIngestorTest.test2(GraphUpdateDataIngestorTest.java:53)
  4. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  6. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  7. at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  8. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  9. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  10. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  11. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  12. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  13. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  14. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  15. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  16. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  17. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  18. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  19. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  20. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  21. at com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory$CancellableRunner.run(CancellableRequestFactory.java:108)
  22. at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  23. at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
  24. at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:116)
  25. at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:159)
  26. at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:85)
  27. Caused by: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
  28. at org.apache.avro.util.ClassUtils.forName(ClassUtils.java:60)
  29. at org.apache.avro.util.ClassUtils.forName(ClassUtils.java:36)
  30. at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:136)
  31. ... 24 more

I don't know why class name is mentioned in schema object as "com.mycompany.protos.kgschema.Graphaction_.GraphUpdate" which I think is root cause of this issue.

To confirm that I tried out this code ( trying method call which is causing exception with correct class name )

  1. Class&lt;?&gt; out =
  2. org.apache.avro.util.ClassUtils.forName(&quot;com.mycompany.protos.kgschema.Graphaction$GraphUpdate&quot;);

and it works fine without any error.

I don't understand why class namespace is coming wrong in schema object created by
ProtobufData.get().getSchema(Graphaction.GraphUpdate.class)

also what is way to fix it ? Any help is appreciated.

答案1

得分: 0

我发现这是Avro-protobuf 1.8版本的一个问题,已在1.9版本及以后得到修复。

英文:

I found that this is a issue with Avro-protobuf version 1.8 and is fixed in 1.9 version onwards

huangapple
  • 本文由 发表于 2020年10月2日 00:50:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/64159924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定