ProtoBuf schema having wrong namespace

160 views Asked by At

I have defined my Protobuf schema like this

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;
}

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<?> out =
        org.apache.avro.util.ClassUtils.forName("com.mycompany.protos.kgschema.Graphaction$GraphUpdate");

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

There are 1 answers

0
Vishal On BEST ANSWER

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