I'm trying to pass a pyarrow
table to c++
via pybind11
. In this example I'm simply trying to print the number of rows of a pyarrow
table passed from python
.
#include <pybind11/pybind11.h>
#include <Python.h>
#include <iostream>
#include <arrow/python/pyarrow.h>
// Convert pyarrow table to native C++ object and print its contents
void print_table(PyObject* py_table)
{
// convert pyobject to table
auto status = arrow::py::unwrap_table(py_table);
if (!status.ok())
{
std::cout << "Error converting pyarrow table to arrow table" << std::endl;
return;
}
std::shared_ptr<arrow::Table> table = status.ValueOrDie();
std::cout << "Table has " << table->num_rows() << " rows" << std::endl;
}
PYBIND11_MODULE(df_test, m)
{
arrow::py::import_pyarrow();
m.doc() = "Pyarrow Extensions";
m.def("print_table", &print_table);
}
However I get the following error:
error: member access into incomplete type 'std::shared_ptr<arrow::Table>::element_type' (aka 'arrow::Table')
std::cout << "Table has " << table->num_rows() << " rows" << std::endl;
How do I fix this error?
The error tells you that the c++ class arrow::Table
is missing its full definition. That is often the case if the class is only declared in some header but not defined.
To fix the error, you probably need to add an #include
statement.
The definition might be in the header "arrow/table.h" as suggested in the comments, but I am not familiar with the Apache arrow framework so you may have to checkout the documentation.