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

Perl API doesn't raise warning/error when encoding record with spurious fields

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Patch Available
    • Minor
    • Resolution: Unresolved
    • None
    • 1.9.0
    • perl
    • None
    • Perl API: Raise error when serializing record field not included in schema
    • perl

    Description

      When serializing a record with a field that isn't specified in the schema, there should be some sort of warning or error. Otherwise, a simple typo in a field name can lead to silent loss of that field's data.

      Test case that should pass but currently fails:

      {
          my $schema = Avro::Schema->parse(<<EOJ);
                {
                "type": "record",
                "name": "test",
                "fields" : [
                {"name": "a", "type": "long"}
                ]
                }
      EOJ
          my $enc = '';
          eval {
              Avro::BinaryEncoder->encode(
                  schema => $schema,
                  data => { a => 27, b => 'foo' },
                  emit_cb => sub { $enc .= ${ $_[0] } },
              );
          };
          isa_ok $@, 'Avro::BinaryEncoder::Error';
      }
      

      Attachments

        1. AVRO-1460.patch
          2 kB
          John Karp

        Activity

          People

            jkarp John Karp
            jkarp John Karp
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: