You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2023/01/07 10:20:07 UTC
[GitHub] [flink] maosuhan commented on a diff in pull request #21613: [FLINK-30093][formats] Fix compile errors for google.protobuf.Timestamp type
maosuhan commented on code in PR #21613:
URL: https://github.com/apache/flink/pull/21613#discussion_r1063983345
##########
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/util/PbFormatUtils.java:
##########
@@ -72,14 +71,33 @@ public static String getStrongCamelCaseJsonName(String name) {
return ProtobufInternalUtils.underScoreToCamelCase(name, true);
}
- public static String getOuterProtoPrefix(String name) {
- name = name.replace('$', '.');
- int index = name.lastIndexOf('.');
- if (index != -1) {
- // include dot
- return name.substring(0, index + 1);
+ public static String getOuterProtoPrefix(Descriptors.Descriptor descriptor) {
+ String javaPackageName = descriptor.getFile().getOptions().getJavaPackage();
+ if (javaPackageName.isEmpty()) {
Review Comment:
what about use descriptor.getFile().getOptions().hasJavaPackage() to check existence of java package option?
##########
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/util/PbFormatUtils.java:
##########
@@ -28,26 +28,25 @@
/** Protobuf function util. */
public class PbFormatUtils {
- public static String getFullJavaName(Descriptors.Descriptor descriptor, String outerProtoName) {
+ public static String getFullJavaName(Descriptors.Descriptor descriptor) {
if (null != descriptor.getContainingType()) {
// nested type
- String parentJavaFullName =
- getFullJavaName(descriptor.getContainingType(), outerProtoName);
+ String parentJavaFullName = getFullJavaName(descriptor.getContainingType());
return parentJavaFullName + "." + descriptor.getName();
} else {
// top level message
+ String outerProtoName = getOuterProtoPrefix(descriptor);
return outerProtoName + descriptor.getName();
}
}
- public static String getFullJavaName(
- Descriptors.EnumDescriptor enumDescriptor, String outerProtoName) {
+ public static String getFullJavaName(Descriptors.EnumDescriptor enumDescriptor) {
if (null != enumDescriptor.getContainingType()) {
- return getFullJavaName(enumDescriptor.getContainingType(), outerProtoName)
+ return getFullJavaName(enumDescriptor.getContainingType())
+ "."
+ enumDescriptor.getName();
} else {
- return outerProtoName + enumDescriptor.getName();
+ return enumDescriptor.getFullName();
Review Comment:
fullName of enumDescriptor is determine by package option. If user specify different java_package and the enum is at the top level, the result is not correct.
##########
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/deserialize/ProtoToRowConverter.java:
##########
@@ -58,16 +58,15 @@ public class ProtoToRowConverter {
public ProtoToRowConverter(RowType rowType, PbFormatConfig formatConfig)
throws PbCodegenException {
try {
- String outerPrefix =
- PbFormatUtils.getOuterProtoPrefix(formatConfig.getMessageClassName());
Descriptors.Descriptor descriptor =
PbFormatUtils.getDescriptor(formatConfig.getMessageClassName());
+ String outerPrefix = PbFormatUtils.getOuterProtoPrefix(descriptor);
Review Comment:
It seems PbFormatContext.oterPrefix is actually not used in the code logic. Is it possible to remove outerPrefix in PbFormatContext?
##########
flink-formats/flink-protobuf/src/test/proto/test_simple_noouter_nomulti.proto:
##########
@@ -21,18 +21,17 @@ package org.apache.flink.formats.protobuf.proto;
option java_package = "org.apache.flink.formats.protobuf.testproto";
message SimpleTestNoouterNomulti {
Review Comment:
What about rename this file to test_simple_nomulti.proto as you do?
##########
flink-formats/flink-protobuf/src/test/proto/test_timestamp.proto:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+syntax = "proto3";
+package org.apache.flink.formats.protobuf.proto;
+import "google/protobuf/timestamp.proto";
+option java_package = "org.apache.flink.formats.protobuf.testproto";
+option java_multiple_files = false;
+
+message TimestampTest {
Review Comment:
change this file name to test_timestamp_nomulti.proto
##########
flink-formats/flink-protobuf/src/test/proto/test_simple_noouter_nomulti.proto:
##########
@@ -21,18 +21,17 @@ package org.apache.flink.formats.protobuf.proto;
option java_package = "org.apache.flink.formats.protobuf.testproto";
message SimpleTestNoouterNomulti {
Review Comment:
Also set multiple_files=false explicitly ?
##########
flink-formats/flink-protobuf/src/test/proto/test_simple_outer_nomulti.proto:
##########
@@ -22,18 +22,17 @@ option java_package = "org.apache.flink.formats.protobuf.testproto";
option java_outer_classname = "SimpleTestOuterNomultiProto";
Review Comment:
set java_multiple_files=false explicitly as test_timestamp_outer_nomulti.proto do?
##########
flink-formats/flink-protobuf/src/test/proto/test_simple.proto:
##########
@@ -22,28 +22,25 @@ option java_package = "org.apache.flink.formats.protobuf.testproto";
option java_multiple_files = true;
Review Comment:
what about rename this file to test_simple_multi.proto so that the name convention is the same as timestamp?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org