It can't tell from your use what type to return/cast the value to so
its failing.

    default_value.value<int64_t>();

will try to do it as an int64_t to match the long.  Alternatively you
should be able to do

    int64_t value = default_value.value();

and it can guess the type there.

I suspect your problem lives in encode_type and what it's doing with
the last parameter.

On Tue, Nov 19, 2019 at 11:04 AM Mark Petronic <markpetro...@gmail.com> wrote:
>
> I am getting back into C++ but don't have much experience with templates so I 
> am a reaching out for a hint here. I am trying to iterate over all the 
> NodePrt nodes starting with the root node using avro::NodePtr& root = 
> schema.root(); But I just cannot figure out how to code up the method call to 
> get the default value from a primitive whose schema defines one. For example, 
> a simple schema like this:
>
> {
>     "name": "simple_schema",
>     "type": "record",
>     "fields": [
>         {
>             "name": "int_stat",
>             "type": "long",
>             "default": 999
>         }
>     ]
> }
>
> I want to get my hands on that 999 value. Here is a snippet of a method that 
> gets a NodePtr to an Avro record, retrieves the defaultValueAt(i) just fine, 
> but how do I code up the call to retrieve the value() 999?
>
> What should the return value look like given the default could be various 
> types depending on the schema?
> What should this call look like?  default_value.value();
>
> Thanks for any insight and guidance!!!
>
> void Encoder::encode_record(
>         const avro::NodePtr& n,
>         const csv_data_map& csv_data,
>         avro::EncoderPtr encoder) const
> {
>     size_t c = n->leaves();
>     cout << "Processing Avro record, name = " << n->name() << endl;
>     for (size_t i = 0; i < c; ++i) {
>         avro::GenericDatum default_value = n->defaultValueAt(i);
>         // THIS IS THE PROBLEM PART I CANNOT FIGURE OUT
>         default_value.value();
>         encode_type(n->leafAt(i), n->nameAt(i), csv_data, encoder, 
> default_value);
>     }
> }
>
> Building file: ../src/encoder.cpp
> Invoking: GCC C++ Compiler
> g++ -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP 
> -MF"src/encoder.d" -MT"src/encoder.o" -o "src/encoder.o" "../src/encoder.cpp"
> ../src/encoder.cpp: In member function ‘void Encoder::encode_record(const 
> NodePtr&, const csv_data_map&, avro::EncoderPtr) const’:
> ../src/encoder.cpp:257:29: error: no matching function for call to 
> ‘avro::GenericDatum::value()’
>          default_value.value();
>                              ^
> ../src/encoder.cpp:257:29: note: candidates are:
> In file included from ../src/encoder.cpp:7:0:
> /usr/local/include/avro/GenericDatum.hh:98:35: note: template<class T> const 
> T& avro::GenericDatum::value() const
>      template<typename T> const T& value() const;
>                                    ^
> /usr/local/include/avro/GenericDatum.hh:98:35: note:   template argument 
> deduction/substitution failed:
> ../src/encoder.cpp:257:29: note:   couldn't deduce template parameter ‘T’
>          default_value.value();
>                              ^
> In file included from ../src/encoder.cpp:7:0:
> /usr/local/include/avro/GenericDatum.hh:109:29: note: template<class T> T& 
> avro::GenericDatum::value()
>      template<typename T> T& value();
>                              ^
> /usr/local/include/avro/GenericDatum.hh:109:29: note:   template argument 
> deduction/substitution failed:
> ../src/encoder.cpp:257:29: note:   couldn't deduce template parameter ‘T’
>          default_value.value();
>                              ^
> make: *** [src/encoder.o] Error 1
>
>

Reply via email to