You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Heye Vöcking (JIRA)" <ji...@apache.org> on 2015/01/22 16:42:34 UTC

[jira] [Updated] (AVRO-1635) C++ schema aware encoders throw tr1::bad_weak_ptr exception for recursive schema

     [ https://issues.apache.org/jira/browse/AVRO-1635?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Heye Vöcking updated AVRO-1635:
-------------------------------
    Description: 
Encoding an object with a recursive schema fails when using a jsonEncoder or a validatingEncoder. Here is an example:

Output:
{noformat}
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >'
  what():  tr1::bad_weak_ptr
{noformat}

{code:title=container.json|borderStyle=solid}
{
  "name": "Container",
  "doc": "Container to demonstrate the weak_ptr exception.",
  "type": "record",
  "fields": [{
    "name": "field",
    "type": {
      "name": "Object",
      "type": "record",
      "fields": [{
        "name": "value",
        "type": [
          "string",
          {"type": "map", "values": "Object"}
        ]
      }]
    }
  }]
}
{code}

{code:title=example.cc|borderStyle=solid}
#include <fstream>

#include <avro/Compiler.hh>
#include <avro/Encoder.hh>
#include <avro/Stream.hh>
#include <avro/ValidSchema.hh>

#include "container.hh"

int
main()
{
    std::ifstream ifs("container.json");
    avro::ValidSchema schema;
    avro::compileJsonSchema(ifs, schema);

    std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();

    // Either one fails, here we use the jsonEncoder
    // avro::EncoderPtr encoder = avro::jsonEncoder(schema);
    avro::EncoderPtr encoder = avro::validatingEncoder(schema, avro::binaryEncoder());
    
    // Note that a encoder that does not know the schema does not fail
    // avro::EncoderPtr encoder = avro::binaryEncoder();

    encoder->init(*out);

    Container container;
    std::map<std::string, Object > object;

    // Note that it doesn't fail if we don't insert a value into the map
    // object["a"].value.set_string("x");

    container.field.value.set_map(object);
    avro::encode(*encoder, container);

    return 0;
}
{code}

  was:
Encoding an object with a recursive schema fails when using a jsonEncoder or a validatingEncoder. Here is an example:

Output:
{noformat}
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >'
  what():  tr1::bad_weak_ptr
{noformat}

{code:title=container.json|borderStyle=solid}
{
  "name": "Container",
  "doc": "Container to demonstrate the weak_ptr exception.",
  "type": "record",
  "fields": [{
    "name": "field",
    "type": {
      "name": "Object",
      "type": "record",
      "fields": [{
        "name": "value",
        "type": [
          "string",
          {"type": "map", "values": "Object"}
        ]
      }]
    }
  }]
}
{code}

{code:title=example.cc|borderStyle=solid}
#include <fstream>

#include <avro/Compiler.hh>
#include <avro/Encoder.hh>
#include <avro/Stream.hh>
#include <avro/ValidSchema.hh>

#include "container.hh"

int
main()
{
    std::ifstream ifs("container.json");
    avro::ValidSchema schema;
    avro::compileJsonSchema(ifs, schema);

    std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();

    // Either one fails, here we use the jsonEncoder
    // avro::EncoderPtr encoder = avro::jsonEncoder(schema);
    avro::EncoderPtr encoder = avro::validatingEncoder(schema, avro::binaryEncoder());

    encoder->init(*out);

    Container container;
    std::map<std::string, Object > object;

    // Note that it doesn't fail if we don't insert a value into the map
    // object["a"].value.set_string("x");

    container.field.value.set_map(object);
    avro::encode(*encoder, container);

    return 0;
}
{code}


> C++ schema aware encoders throw tr1::bad_weak_ptr exception for recursive schema
> --------------------------------------------------------------------------------
>
>                 Key: AVRO-1635
>                 URL: https://issues.apache.org/jira/browse/AVRO-1635
>             Project: Avro
>          Issue Type: Bug
>          Components: c++
>    Affects Versions: 1.7.7
>         Environment: Ubuntu 12.04, gcc 4.6.4
>            Reporter: Heye Vöcking
>              Labels: avro, c++, encode, recursive, schema
>
> Encoding an object with a recursive schema fails when using a jsonEncoder or a validatingEncoder. Here is an example:
> Output:
> {noformat}
> terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >'
>   what():  tr1::bad_weak_ptr
> {noformat}
> {code:title=container.json|borderStyle=solid}
> {
>   "name": "Container",
>   "doc": "Container to demonstrate the weak_ptr exception.",
>   "type": "record",
>   "fields": [{
>     "name": "field",
>     "type": {
>       "name": "Object",
>       "type": "record",
>       "fields": [{
>         "name": "value",
>         "type": [
>           "string",
>           {"type": "map", "values": "Object"}
>         ]
>       }]
>     }
>   }]
> }
> {code}
> {code:title=example.cc|borderStyle=solid}
> #include <fstream>
> #include <avro/Compiler.hh>
> #include <avro/Encoder.hh>
> #include <avro/Stream.hh>
> #include <avro/ValidSchema.hh>
> #include "container.hh"
> int
> main()
> {
>     std::ifstream ifs("container.json");
>     avro::ValidSchema schema;
>     avro::compileJsonSchema(ifs, schema);
>     std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
>     // Either one fails, here we use the jsonEncoder
>     // avro::EncoderPtr encoder = avro::jsonEncoder(schema);
>     avro::EncoderPtr encoder = avro::validatingEncoder(schema, avro::binaryEncoder());
>     
>     // Note that a encoder that does not know the schema does not fail
>     // avro::EncoderPtr encoder = avro::binaryEncoder();
>     encoder->init(*out);
>     Container container;
>     std::map<std::string, Object > object;
>     // Note that it doesn't fail if we don't insert a value into the map
>     // object["a"].value.set_string("x");
>     container.field.value.set_map(object);
>     avro::encode(*encoder, container);
>     return 0;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)