ProtoBuf模式的命名空间错误。

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

ProtoBuf schema having wrong namespace

问题

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

我已经定义了我的 Protobuf 模式如下:

    message VertexUpdate {
      required VertexId id = 1;
      map<string, google.protobuf.Value> properties = 2;
      optional bool isDelete = 3;
    }
    
    message EdgeUpdate {
      required EdgeId id = 1;
      map<string, google.protobuf.Value> properties = 2;
      optional bool isDelete = 3;
    }
    
    message GraphUpdate {
      required string graphName = 1;
      optional VertexUpdate vertexUpdate = 2;
      optional EdgeUpdate edgeUpdate = 3;
    }

然后我执行了这段代码:

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

但是这给了我一个错误:

    java.lang.RuntimeException: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
    	at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:144)
    	...

我不知道为什么类名在模式对象中被指定为 "com.mycompany.protos.kgschema.Graphaction_.GraphUpdate",我认为这是问题的根本原因。

为了确认,我尝试了以下这段代码(试图调用引发异常的方法,使用了正确的类名):

    Class<?> out = org.apache.avro.util.ClassUtils.forName("com.mycompany.protos.kgschema.Graphaction$GraphUpdate");

这段代码能够正常运行,没有任何错误。

我不明白为什么类的命名空间会在由 ProtobufData.get().getSchema(Graphaction.GraphUpdate.class) 创建的模式对象中出错,

同时我想知道如何修复这个问题?任何帮助将不胜感激。

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

英文:

I have defined my Protobuf schema like this

message VertexUpdate {
  required VertexId id = 1;
  map&lt;string, google.protobuf.Value&gt; properties = 2;
  optional bool isDelete = 3;
}

message EdgeUpdate {
  required EdgeId id = 1;
  map&lt;string, google.protobuf.Value&gt; properties = 2;
  optional bool isDelete = 3;
}

message GraphUpdate {
  required string graphName = 1;
  optional VertexUpdate vertexUpdate = 2;
  optional EdgeUpdate edgeUpdate = 3;
}

and I am executing this code

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

which gives me error

java.lang.RuntimeException: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
	at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:144)
	at com.mycompany.knowledge.graph.ingest.backfill.hlc.GraphUpdateDataIngestorTest.test2(GraphUpdateDataIngestorTest.java:53)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory$CancellableRunner.run(CancellableRequestFactory.java:108)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:116)
	at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:159)
	at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:85)
Caused by: java.lang.ClassNotFoundException: Failed to load class com.mycompany.protos.kgschema.Graphaction_.GraphUpdate
	at org.apache.avro.util.ClassUtils.forName(ClassUtils.java:60)
	at org.apache.avro.util.ClassUtils.forName(ClassUtils.java:36)
	at org.apache.avro.protobuf.ProtobufData.newRecord(ProtobufData.java:136)
	... 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 )

Class&lt;?&gt; out =
        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:

确定