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



##########
File path: 
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/PbFormatUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * 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;
+
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.MapType;
+
+import com.google.protobuf.Descriptors;
+
+/** Protobuf function util. */
+public class PbFormatUtils {
+
+    /**
+     * protobuf code has a bug that, f_abc_7d will be convert to fAbc7d in 
{@code
+     * com.google.protobuf.Descriptors.FileDescriptor.getJsonName()}, but 
actually we need fAbc7D.
+     */
+    public static String fieldNameToJsonName(String name) {
+        final int length = name.length();
+        StringBuilder result = new StringBuilder(length);
+        boolean isNextUpperCase = false;
+        for (int i = 0; i < length; i++) {
+            char ch = name.charAt(i);
+            if (ch == '_') {
+                isNextUpperCase = true;
+            } else if (isNextUpperCase) {
+                if ('a' <= ch && ch <= 'z') {
+                    ch = (char) (ch - 'a' + 'A');
+                    isNextUpperCase = false;
+                }
+                result.append(ch);
+            } else {
+                result.append(ch);
+            }
+        }
+        return result.toString();
+    }
+
+    public static String getFullJavaName(Descriptors.Descriptor descriptor) {
+        String javaPackageName = 
descriptor.getFile().getOptions().getJavaPackage();

Review comment:
       It seems that `javaPackageName` is empty in some cases.
   In this case, it is better to use `descriptor.getFile().getPackage()` to get 
the java package name.
   ```suggestion
           String javaPackageName = 
descriptor.getFile().getOptions().getJavaPackage();
           if (javaPackageName.isEmpty()) {
               javaPackageName = descriptor.getFile().getPackage();
           }
   ```




-- 
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:
[email protected]


Reply via email to