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

Perl Encoder: schema validation of union of records warns when passing over an invalid schema with a long field

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      When searching for a valid schema to encode a field that is a union of records, the Perl encoder warns if the payload doesn't contain a long field required in one of the records' schemas.

      Example. The following snippet:

      my $schema = Avro::Schema->parse(<<EOJ);
      [
          {
              "type": "record",
              "name": "rectangle",
              "fields": [{ "name": "width", "type": "long" }, { "name": "height", "type": "long"}]
          },
          {
              "type": "record",
              "name": "square",
              "fields": [{ "name": "dim", "type": "long" }]
          }
      ]
      EOJ
      my $enc = '';
      Avro::BinaryEncoder->encode(
          schema  => $schema,
          data    => { dim => 10 },
          emit_cb => sub {
              $enc .= ${ $_[0] }
          },
      );
      

      Throws the following warnings:

      Use of uninitialized value $data in pack at ...avro/lang/perl/lib/Avro/Schema.pm line 287.
      Use of uninitialized value $data in string eq at ...avro/lang/perl/lib/Avro/Schema.pm line 289.
      

      The same doesn't happen if width and height are int's.

      This behavior unnecessarily pollutes the logs and can even cause failures in the cases where the encoder is called from a context that doesn't allow warnings.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mhcuervo Miguel
            mhcuervo Miguel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Time Spent - 0.5h Remaining Estimate - 1.5h
                1.5h
                Logged:
                Time Spent - 0.5h Remaining Estimate - 1.5h
                0.5h

                Slack

                  Issue deployment