问题描述
我已经定义了这样的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$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
我不知道为什么在架构对象中将类名称为“ 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)
还有什么解决方法?任何帮助表示赞赏。
解决方法
我发现这是Avro-protobuf 1.8版的问题,并且在1.9版及更高版本中已解决