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

SchemaBuilder: Redefined records should fail fast

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.7.7, 1.8.1
    • Fix Version/s: None
    • Component/s: java
    • Labels:
    • Release Note:
      Schema builder fails fast when encountering redefined records.

      Description

      Overview

      It is currently possible to build an invalid Schema instance using the SchemaBuilder, without any error being thrown. The schema in question is invalid because of redefined record types. These are not picked up by the SchemaBuilder. Failure eventually occurs when calling the Schema.toString() method.

      I suggest that failure should occur much earlier such as at the point of introduction of the redeclared record name in the case of SchemaBuilder. This would make it easier for users to better determine the point of origin of their schema issues.

      Note that there does not appear to be a similar issue with the Schema.parse(String) method which fails fast as expected.

      Test case

      Test case
          Schema a = SchemaBuilder.record("A").fields().optionalInt("y").endRecord();
          Schema b = SchemaBuilder.record("A").fields().optionalString("x").endRecord();
          Schema s = SchemaBuilder
              .record("S")
              .fields()
              .name("a")
              .type(a)
              .noDefault()
              .name("b")
              .type(b)
              .noDefault()
              .endRecord();
          // Does not fail
          
          s.toString();
          // Fails with org.apache.avro.SchemaParseException: Can't redefine: A
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            teabot Elliot West
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development