[
https://issues.apache.org/jira/browse/AVRO-1521?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17235610#comment-17235610
]
Robert Moore commented on AVRO-1521:
------------------------------------
{code:java}
diff --git a/lang/perl/lib/Avro/Schema.pm b/lang/perl/lib/Avro/Schema.pm
index
356c5ba082335cf73d52d4838cd81c8b2ab43548..e303be3beb2c427ea9ba6cc28eb9a729db36a85a
100644
--- a/lang/perl/lib/Avro/Schema.pm
+++ b/lang/perl/lib/Avro/Schema.pm
@@ -312,7 +312,7 @@ sub is_data_valid {
}
if ($type eq 'boolean') {
return 0 if ref $data; # sometimes risky
- return 1 if $data =~ m{yes|no|y|n|t|f|true|false}i;
+ return 1 if $data =~ m{yes|no|y|n|t|f|true|false|0|1}i;
return 0;
}
return 0;
{code}
this doesnt feel like a complete fix, but it does seem to work as a partial
solution to the boolean in union problem (and unlike the other patch ive seen
it will only affect values of 0 and 1 rather than allow any non numeric value
too)
> Inconsistent behavior of Perl API with 'boolean' type
> -----------------------------------------------------
>
> Key: AVRO-1521
> URL: https://issues.apache.org/jira/browse/AVRO-1521
> Project: Apache Avro
> Issue Type: Bug
> Components: perl
> Reporter: John Karp
> Assignee: John Karp
> Priority: Major
>
> The perl boolean serialization code in BinaryEncoder.pm encodes anything
> false to perl, such as 0, '0', '', () and undef, as false, and anything true
> to perl, which is literally everything else, as true.
> Inconsistent with the above serialization, the code used in Schema.pm to
> determine which union branch to use, is checking for boolean-ness with:
> {noformat}
> m{yes|no|y|n|t|f|true|false}i
> {noformat}
> meaning only those particular strings are considered booleans.
> So all those values, including 'no' 'n' 'f' and 'false', still get serialized
> to true.
> We could just standardize on one of the two and use it consistently. But
> neither works that well in unions, because unless you put the boolean type
> last in the union definition, a wide variety of data will be downcast to
> boolean type.
> Perl has no built-in or standardized boolean type, so there's no solution
> like we have in the other language Avro APIs. But we could do as the perl
> JSON module does, and define objects for true and false.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)