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
<[email protected]>

Reply via email to