命名空间错误的 ProtoBuf 模式

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)
    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.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.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.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

我不知道为什么 class 名称在架构对象中提到为“com.mycompany.protos.kgschema.Graphaction_.GraphUpdate”,我认为这是此问题的根本原因。

确认我尝试了这段代码(尝试使用正确的 class 名称导致异常的方法调用)

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

并且它工作正常,没有任何错误。

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

还有什么办法可以解决?感谢任何帮助。

我发现这是 Avro-protobuf 1.8 版的问题,并在 1.9 版以后得到修复