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

Field alias not working due to Schema.getFieldAlias return null for fields not aliased

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4.1
    • 1.5.0
    • java
    • None
    • Reviewed

    Description

      When field alias is used, I get NullPointerException in Schema.Field.hashCode() because Field.name is null. This is because Schema.getFieldAlias return null for non-aliased field. Currently the code is as below:

      private static String getFieldAlias(Name record, String field,
      Map<Name, Map<String, String>> fieldAliases) {
      Map<String, String> recordAliases = fieldAliases.get(record);
      if(recordAliases == null)

      { return field; }
      return recordAliases.get(field);
      }

      Given recordAliases only has aliases, it should return field itself if it's not in recordAliases as below:

      private static String getFieldAlias(Name record, String field,
      Map<Name, Map<String, String>> fieldAliases) {
      Map<String, String> recordAliases = fieldAliases.get(record);
      if(recordAliases == null) { return field; }

      String ret = recordAliases.get(field);
      if (ret == null) ret = field;
      return ret;
      }

      Attachments

        1. aliased-reader.avpr
          3 kB
          Xiaolu Ye
        2. AVRO-759.patch
          2 kB
          Doug Cutting
        3. AvroAliasTest.java
          1 kB
          Xiaolu Ye
        4. reader.avpr
          3 kB
          Xiaolu Ye

        Activity

          People

            xiaoluye Xiaolu Ye
            xiaoluye Xiaolu Ye
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: