avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Karp (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1460) Perl API doesn't raise warning/error when encoding record with spurious fields
Date Fri, 13 Jun 2014 02:32:01 GMT

    [ https://issues.apache.org/jira/browse/AVRO-1460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14030176#comment-14030176
] 

John Karp commented on AVRO-1460:
---------------------------------

Okay, I looked at the ruby and python implementations; I didn't realize until now they were
also quietly ignoring record fields that were not included in the schema. So if we want consistency
between APIs, the perl implementation should also ignore them without warning/errors -- by
default.

But for the use cases I work with, the data structures are being assembled with a particular
schema in mind, and if there's a mismatch between the input data structure and the schema,
its generally the result of a bug, so making the issue obvious saves the user time. I can
add a named optional argument to BinaryEncoder::encode, perhaps 'reject_unknown_fields'? (BinaryEncoder
is just a namespace right now, not a class, so we can't add state/settings to it.)

> Perl API doesn't raise warning/error when encoding record with spurious fields
> ------------------------------------------------------------------------------
>
>                 Key: AVRO-1460
>                 URL: https://issues.apache.org/jira/browse/AVRO-1460
>             Project: Avro
>          Issue Type: Improvement
>          Components: perl
>            Reporter: John Karp
>            Assignee: John Karp
>            Priority: Minor
>             Fix For: 1.7.7
>
>         Attachments: AVRO-1460.patch
>
>
> 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:
> {noformat}
> {
>     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';
> }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message