You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@arrow.apache.org by Alan Souza via user <us...@arrow.apache.org> on 2022/10/23 12:53:24 UTC

[c++] problem to use macro ARROW_ASSIGN_OR_RAISE with arrow::RecordBatchBuilder::Make

Hello. I am trying to use this macro with the the arrow function arrow::RecordBatchBuilder::Make with this macroHowever I am getting this error:
/usr/bin/c++  -isystem /usr/local/arrow/include -O3 -DNDEBUG -fPIE -std=c++17 -MD -MT benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o -MF benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o.d -o benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o -c /workspaces/cpptest/benchmark/reproducer.cpp
In file included from /usr/local/arrow/include/arrow/buffer.h:29,
                 from /usr/local/arrow/include/arrow/array/data.h:26,
                 from /usr/local/arrow/include/arrow/array/array_base.h:26,
                 from /usr/local/arrow/include/arrow/array.h:37,
                 from /usr/local/arrow/include/arrow/api.h:22,
                 from /workspaces/cpptest/benchmark/reproducer.cpp:5:
/workspaces/cpptest/benchmark/reproducer.cpp: In function ‘int main()’:
/workspaces/cpptest/benchmark/reproducer.cpp:28:5: error: cannot convert ‘const arrow::Status’ to ‘int’ in return
   28 |     ARROW_ASSIGN_OR_RAISE(batch_builder, arrow::RecordBatchBuilder::Make(schema, arrow::default_memory_pool(), nrows));
      |     ^
      |     |
      |     const arrow::Status
ninja: build stopped: subcommand failed.
I am using g++ 12.2.1 (I also have tried with clang++ 14.0.5) with a built arrow library 10 (I also have tried with arrow 9). The strangest thing is that I am able to build  and run the rapidjson conversion example. that uses a similar construct
Without using the macro (the commented out code) works without any issues.

#include <vector>#include <memory>#include <iostream>
#include <arrow/api.h>#include <arrow/result.h>#include <arrow/table_builder.h>#include <arrow/type_traits.h>#include <arrow/util/iterator.h>#include <arrow/util/logging.h>#include <arrow/visit_array_inline.h>
std::shared_ptr<arrow::Schema> ExampleSchema1() { auto f0 = arrow::field("f0", arrow::int32()); auto f1 = arrow::field("f1", arrow::utf8()); auto f2 = arrow::field("f1", arrow::list(arrow::int8())); return arrow::schema({f0, f1, f2});}
int main(){ std::shared_ptr<arrow::Schema> schema = ExampleSchema1(); std::unique_ptr<arrow::RecordBatchBuilder> batch_builder; std::int64_t nrows = 10; ARROW_ASSIGN_OR_RAISE(batch_builder, arrow::RecordBatchBuilder::Make(schema, arrow::default_memory_pool(), nrows)); // arrow::Result<std::unique_ptr<arrow::RecordBatchBuilder>> batch_builder_result = arrow::RecordBatchBuilder::Make(schema,  // arrow::default_memory_pool(), // nrows); // if(!batch_builder_result.ok()){ // std::cerr <<batch_builder_result.status()<<std::endl; // }
 return 0;}
thanks
   
   -    



Re: [c++] problem to use macro ARROW_ASSIGN_OR_RAISE with arrow::RecordBatchBuilder::Make

Posted by Sutou Kouhei <ko...@clear-code.com>.
Hi,

ARROW_ASSIGN_OR_RAISE() may return arrow::Status. So we
can't use it in "int main()". Please define a function that
returns arrow::Status and use it from main() like
https://github.com/apache/arrow/blob/master/cpp/examples/minimal_build/example.cc
.

Thanks,
-- 
kou

In <19...@mail.yahoo.com>
  "[c++] problem to use macro ARROW_ASSIGN_OR_RAISE with arrow::RecordBatchBuilder::Make" on Sun, 23 Oct 2022 12:53:24 +0000 (UTC),
  "Alan Souza via user" <us...@arrow.apache.org> wrote:

> Hello. I am trying to use this macro with the the arrow function
> arrow::RecordBatchBuilder::Make with this macro
> However I am getting this error:
> 
> /usr/bin/c++  -isystem /usr/local/arrow/include -O3 -DNDEBUG -fPIE -std=c++17
> -MD -MT benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o -MF
> benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o.d -o
> benchmark/CMakeFiles/reproducer.exe.dir/reproducer.cpp.o -c
> /workspaces/cpptest/benchmark/reproducer.cpp
> In file included from /usr/local/arrow/include/arrow/buffer.h:29,
>                  from /usr/local/arrow/include/arrow/array/data.h:26,
>                  from /usr/local/arrow/include/arrow/array/array_base.h:26,
>                  from /usr/local/arrow/include/arrow/array.h:37,
>                  from /usr/local/arrow/include/arrow/api.h:22,
>                  from /workspaces/cpptest/benchmark/reproducer.cpp:5:
> /workspaces/cpptest/benchmark/reproducer.cpp: In function ‘int main()’:
> /workspaces/cpptest/benchmark/reproducer.cpp:28:5: error: cannot convert
> ‘const arrow::Status’ to ‘int’ in return
>    28 |     ARROW_ASSIGN_OR_RAISE(batch_builder,
> arrow::RecordBatchBuilder::Make(schema, arrow::default_memory_pool(), nrows));
>       |     ^
>       |     |
>       |     const arrow::Status
> ninja: build stopped: subcommand failed.
> 
> I am using g++ 12.2.1 (I also have tried with clang++ 14.0.5) with a built
> arrow library 10 (I also have tried with arrow 9). The strangest thing is that
> I am able to build  and run the rapidjson conversion example. that uses a
> similar construct
> 
> Without using the macro (the commented out code) works without any issues.
> 
> #include <vector>
> #include <memory>
> #include <iostream>
> 
> #include <arrow/api.h>
> #include <arrow/result.h>
> #include <arrow/table_builder.h>
> #include <arrow/type_traits.h>
> #include <arrow/util/iterator.h>
> #include <arrow/util/logging.h>
> #include <arrow/visit_array_inline.h>
> 
> std::shared_ptr<arrow::Schema> ExampleSchema1() {
> auto f0 = arrow::field("f0", arrow::int32());
> auto f1 = arrow::field("f1", arrow::utf8());
> auto f2 = arrow::field("f1", arrow::list(arrow::int8()));
> return arrow::schema({f0, f1, f2});
> }
> 
> int main(){
> std::shared_ptr<arrow::Schema> schema = ExampleSchema1();
> std::unique_ptr<arrow::RecordBatchBuilder> batch_builder;
> std::int64_t nrows = 10;
> ARROW_ASSIGN_OR_RAISE(batch_builder, arrow::RecordBatchBuilder::Make(schema,
> arrow::default_memory_pool(), nrows));
> // arrow::Result<std::unique_ptr<arrow::RecordBatchBuilder>>
> batch_builder_result = arrow::RecordBatchBuilder::Make(schema,
> // arrow::default_memory_pool(),
> // nrows);
> // if(!batch_builder_result.ok()){
> // std::cerr <<batch_builder_result.status()<<std::endl;
> // }
> 
> return 0;
> }
> 
> thanks
> 
> *