syucream commented on a change in pull request #14376:
URL: https://github.com/apache/flink/pull/14376#discussion_r547039824



##########
File path: 
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/deserialize/PbCodegenSimpleDeserializer.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.formats.protobuf.deserialize;
+
+import com.google.protobuf.Descriptors;
+
+public class PbCodegenSimpleDeserializer implements PbCodegenDeserializer {
+       private Descriptors.FieldDescriptor fd;
+
+       public PbCodegenSimpleDeserializer(
+               Descriptors.FieldDescriptor fd) {
+               this.fd = fd;
+       }
+
+       @Override
+       public String codegen(String returnVarName, String messageGetStr) {
+               StringBuilder sb = new StringBuilder();
+               switch (fd.getJavaType()) {
+                       case INT:
+                       case LONG:
+                       case FLOAT:
+                       case DOUBLE:
+                       case BOOLEAN:
+                               sb.append(returnVarName + " = " + messageGetStr 
+ ";");
+                               break;
+                       case BYTE_STRING:
+                               sb.append(returnVarName + " = " + messageGetStr 
+ ".toByteArray();");
+                               break;
+                       case STRING:
+                       case ENUM:
+                               sb.append(
+                                       returnVarName + " = 
StringData.fromString(" + messageGetStr + ".toString());");

Review comment:
       It raises `java.lang.IncompatibleClassChangeError` when I built with 
Java11:
   ```
   java.io.IOException: Failed to deserialize PB object.
           at 
org.apache.flink.formats.protobuf.deserialize.PbRowDeserializationSchema.deserialize(PbRowDeserializationSchema.java:96)
           at 
org.apache.flink.formats.protobuf.MapProtoToRowTest.testMessage(MapProtoToRowTest.java:52)
           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 org.junit.runners.Suite.runChild(Suite.java:128)
           at org.junit.runners.Suite.runChild(Suite.java:27)
           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 
org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55)
           at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
           at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeLazy(JUnitCoreWrapper.java:119)
           at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:87)
           at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
           at 
org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:158)
           at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
           at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
           at 
org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
           at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
   Caused by: java.lang.reflect.InvocationTargetException
           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.codehaus.janino.ScriptEvaluator.evaluate(ScriptEvaluator.java:798)
           at 
org.codehaus.janino.ScriptEvaluator.evaluate(ScriptEvaluator.java:790)
           at 
org.apache.flink.formats.protobuf.deserialize.ProtoToRowConverter.convertProtoBinaryToRow(ProtoToRowConverter.java:97)
           at 
org.apache.flink.formats.protobuf.deserialize.PbRowDeserializationSchema.deserialize(PbRowDeserializationSchema.java:90)
           ... 36 more
   Caused by: java.lang.IncompatibleClassChangeError: Method 
'org.apache.flink.table.data.StringData 
org.apache.flink.table.data.StringData.fromString(java.lang.String)' must be 
InterfaceMethodref constant
           at SC.eval0(Unknown Source)
           ... 44 more
   ```
   
   In my guess, the cause is Janino's limitation 
https://github.com/janino-compiler/janino/issues/69#issuecomment-707620587, and 
I created a patch for a workaround. What do you think about this? 
https://github.com/maosuhan/flink/pull/1




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to