Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-36609

Protobuf Format not support proto3

    XMLWordPrintableJSON

Details

    Description

      Currently, though ProtoToRowConverter try to handle PROTO3  as follows:

      public ProtoToRowConverter(RowType rowType, PbFormatConfig formatConfig)
              throws PbCodegenException {
          try {
              Descriptors.Descriptor descriptor =
                      PbFormatUtils.getDescriptor(formatConfig.getMessageClassName());
              Class<?> messageClass =
                      Class.forName(
                              formatConfig.getMessageClassName(),
                              true,
                              Thread.currentThread().getContextClassLoader());
              String fullMessageClassName = PbFormatUtils.getFullJavaName(descriptor);
              boolean readDefaultValuesForPrimitiveTypes = formatConfig.isReadDefaultValues();
              if (descriptor.getFile().getSyntax() == Syntax.PROTO3) {
                  // pb3 always read default values for primitive types
                  readDefaultValuesForPrimitiveTypes = true;
              }
      //...
      } 

      However, protoc will compile message of PROTO3 as 
      FileDescriptor rather than Descriptor, thus the following code will throw exception:

      public static Descriptors.Descriptor getDescriptor(String className) {
          try {
              Class<?> pbClass =
                      Class.forName(className, true, Thread.currentThread().getContextClassLoader());
              return (Descriptors.Descriptor)
                      pbClass.getMethod(PbConstant.PB_METHOD_GET_DESCRIPTOR).invoke(null);
          } catch (Exception e) {
              throw new IllegalArgumentException(
                      String.format("get %s descriptors error!", className), e);
          }
      } 

      Attachments

        1. image-2024-10-28-14-11-17-931.png
          223 kB
          Hongshun Wang

        Issue Links

          Activity

            People

              loserwang1024 Hongshun Wang
              loserwang1024 Hongshun Wang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: