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

[java] AllowNull causes unexpected resolution failure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.7
    • 1.8.0
    • None
    • None

    Description

      If I try to read data serialized with a hand-written schema using a reflected schema generated by AllowNull, even though all of the individual types can be read. Here is a failing test:

        public static class Point {
          double x;
          double y;
        }
      
        public static class Circle {
          Point center;
          double radius;
        }
      
        @Test
        public void testAllowNull() throws Exception {
          new SchemaValidatorBuilder()
              .canBeReadStrategy()
              .validateLatest().validate(
              SchemaBuilder.record("Circle").fields()
                  .name("center").type().record("Point").fields()
                  .requiredDouble("x")
                  .requiredDouble("y")
                  .endRecord().noDefault()
                  .requiredDouble("radius")
                  .endRecord(),
              Arrays.asList(ReflectData.AllowNull.get().getSchema(Circle.class)));
        }
      

      The problem is that the ResolvingGrammarGenerator can't resolve a record with a nullable record unless the two have the same full name.

      It is more work, but I think the check should be whether there is a readable record in the union. Another alternative is to special case a nullable union and allow the record-level resolution only in that case.

      Attachments

        1. AVRO-1590-3.patch
          12 kB
          Ryan Blue
        2. AVRO-1590-2.patch
          8 kB
          Ryan Blue
        3. AVRO-1590-1.patch
          6 kB
          Ryan Blue

        Activity

          People

            rdblue Ryan Blue
            rdblue Ryan Blue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: