[
https://issues.apache.org/jira/browse/ARROW-16340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17613274#comment-17613274
]
Yue Ni edited comment on ARROW-16340 at 10/6/22 1:23 AM:
---------------------------------------------------------
[~kou] sorry it is not open source at this moment, but the binding itself is a
just very thin wrapper for the C++ library. The code looks like this:
{code:java}
// pyarrow.h is included here
#include <arrow/python/pyarrow.h>
#include <memory>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
class SearchContext {
public:
// ...
SearchContext() {
// here pyarrow module is initialized
auto result = arrow::py::import_pyarrow();
// ...
}
pybind11::object search(const string &sql) {
// call the C++ library to run the search and get the result as an arrow
table
auto table = get_exec_context()->search(sql);
// use pyarrow's C++ API to wrap the Arrow C++ table as a pyarrow table
instance
return _wrap_table(table);
}
// ...
private:
pybind11::object _wrap_table(std::shared_ptr<arrow::Table> table) {
// this is where pyarrow.h is used, the wrap_table API
return
pybind11::reinterpret_steal<pybind11::object(arrow::py::wrap_table(table));
}
}
// the above SearchContext class is exposed via pybind11 so that users can use
them in Python
PYBIND11_MODULE(my_py_binding, m) {
py::class_<SearchContext>(m, "SearchContext")
.def(pybind11::init<const std::string &>())
.def("search", &SearchContext::search, py::arg("sql") = "");
// ....
}{code}
Here are the materials we referred to when we authored this binding initially
(probably two years ago), we don't revisit if there is better approach since it
is working for us until now.
[1]
[https://arrow.apache.org/docs/python/integration/extending.html#_CPPv4N5arrow5arrow2py10wrap_tableERKNSt10shared_ptrI5TableEE]
[2]
[https://stackoverflow.com/questions/57863751/how-to-convert-pyarrow-table-to-arrow-table-when-interfacing-between-pyarrow-in]
was (Author: niyue):
[~kou] sorry it is not open source at this moment, but the binding itself is a
just very thin wrapper for the C++ library. The code looks like this:
{code:java}
// pyarrow.h is included here
#include <arrow/python/pyarrow.h>
#include <memory>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
class SearchContext {
public:
// ...
SearchContext() {
// here pyarrow module is initialized
auto result = arrow::py::import_pyarrow();
// ...
}
pybind11::object search(const string &sql) {
// call the C++ library to run the search and get the result as an arrow
table
auto table = get_exec_context()->search(sql);
// use pyarrow's C++ API to wrap the Arrow C++ table as a pyarrow table
instance
return _wrap_table(table);
}
// ...
private:
pybind11::object _wrap_table(std::shared_ptr<arrow::Table> table) {
// this is where pyarrow.h is used, the wrap_table API
return
pybind11::reinterpret_steal<pybind11::object(arrow::py::wrap_table(table));
}
}{code}
Here are the materials we referred to when we authored this binding initially
(probably two years ago), we don't revisit if there is better approach since it
is working for us until now.
[1]
[https://arrow.apache.org/docs/python/integration/extending.html#_CPPv4N5arrow5arrow2py10wrap_tableERKNSt10shared_ptrI5TableEE]
[2]
[https://stackoverflow.com/questions/57863751/how-to-convert-pyarrow-table-to-arrow-table-when-interfacing-between-pyarrow-in]
> [C++][Python] Move all Python related code into PyArrow
> -------------------------------------------------------
>
> Key: ARROW-16340
> URL: https://issues.apache.org/jira/browse/ARROW-16340
> Project: Apache Arrow
> Issue Type: Improvement
> Components: C++, Python
> Reporter: Alenka Frim
> Assignee: Alenka Frim
> Priority: Major
> Labels: pull-request-available
> Fix For: 10.0.0
>
> Time Spent: 33h 10m
> Remaining Estimate: 0h
>
> Move {{src/arrow/python}} directory into {{pyarrow}} and arrange PyArrow to
> build it.
> More details can be found on this thread:
> https://lists.apache.org/thread/jbxyldhqff4p9z53whhs95y4jcomdgd2
--
This message was sent by Atlassian Jira
(v8.20.10#820010)