Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3077

Ability of select string deserializing mode by configuration

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.10.1
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      Current Java generator modifies the source schema to add a property to describe the way a reader decodes a string. (see AVRO-2918)

      I think this is a design problem. The way a reader deserializes a string shouldn't modify the schema (the schema describes the structure of avro message, not the way a reader converts to a usable form).

      On the other hand, a reader might require the strings as a CharSequence because it knows how to handle them and other as a String.

      The only way to do this now is modifying the schema itself in each reader. If you use Avro with other technologies like Kafka (or confluent) It migth be non-viable.

       

      I think that the way a reader decodes messages should be specified by the reader and It'll be desirable to specify this using a configuration.

       

      Maybe if a System property (like useCustomCoders feature) or something similar could be added to modify the default value for String decoding.

      Form GenericDatumReader

       

          protected Class findStringClass(Schema schema) {
                  String name = schema.getProp(GenericData.STRING_PROP);
                  if (name == null)
                    return CharSequence.class;
      
                  switch (GenericData.StringType.valueOf(name)) {
                  case String:
                    return String.class;
                  default:
                    return CharSequence.class;
                  }
                }
      

      Maybe adding a "forced" configuration may help: if reader configures string representation, use it, if not do it the current way.

       

      And do something similar in SpecificDatumReader

       

       

       

       

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                emenaceb Emilio Jose Mena Cebrian
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: