avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Braden McDaniel <bra...@endoframe.com>
Subject avro-cpp GenericDatum API behavior breaking change 1.7.6 to 1.7.7
Date Tue, 15 Sep 2015 17:53:18 GMT
It appears that a change was introduced to the avro::GenericDatum 
implementation between 1.7.6 and 1.7.7 that causes unions to be handled 
differently.

The 1.7.6 implementation does this:

   inline Type AVRO_DECL GenericDatum::type() const {
       return (type_ == AVRO_UNION) ?
           boost::any_cast<GenericUnion>(&value_)->type() : type_;
   }

   template<typename T>
   const T& GenericDatum::value() const {
       return (type_ == AVRO_UNION) ?
           boost::any_cast<GenericUnion>(&value_)->value<T>() :
           *boost::any_cast<T>(&value_);
   }

   template<typename T>
   T& GenericDatum::value() {
       return (type_ == AVRO_UNION) ?
           boost::any_cast<GenericUnion>(&value_)->value<T>() :
           *boost::any_cast<T>(&value_);
   }

…whereas the 1.7.7 implementation does this:

   /**
    * The avro data type this datum holds.
    */
   Type type() const {
       return type_;
   }

   /**
    * Returns the value held by this datum.
    * T The type for the value. This must correspond to the
    * avro type returned by type().
    */
   template<typename T> const T& value() const {
       return *boost::any_cast<T>(&value_);
   }

   /**
    * Returns the reference to the value held by this datum, which
    * can be used to change the contents. Please note that only
    * value can be changed, the data type of the value held cannot
    * be changed.
    *
    * T The type for the value. This must correspond to the
    * avro type returned by type().
    */
   template<typename T> T& value() {
       return *boost::any_cast<T>(&value_);
   }

The result of this is that, if the underlying value is an AVRO_UNION, 
calls to GenericDatum::type and GenericDatum::value<> that previously 
resolved to the union member type no longer do so (and user code relying 
on that behavior has been broken).

This change apparently was made to as part of the changes for 
AVRO-1474; however, looking at the comments in that issue, it's not 
clear to me why it was required for that fix.

So, my question is this: is this behavior change deliberate and client 
code should be updated for it, or is it a bug that should be fixed in 
avro-cpp?

-- 
Braden McDaniel
<braden@endoframe.com>

Mime
View raw message