@@ -90,20 +90,17 @@ void PyQueryResult::close() {
9090
9191namespace {
9292
93- py::array_t <int64_t > copyToNumpyArray (const std::vector<int64_t >& values) {
94- auto result = py::array_t <int64_t >(values.size ());
95- auto * data = static_cast <int64_t *>(result.request ().ptr );
96- std::copy (values.begin (), values.end (), data);
97- return result;
93+ py::object importCSRArrowArray (lbug::main::ArrowQueryResult::CSRArrowArray& array) {
94+ auto arrayImportFunc = importCache->pyarrow .lib .Array ._import_from_c ();
95+ return arrayImportFunc ((std::uint64_t )&array.array , (std::uint64_t )&array.schema );
9896}
9997
100- py::dict buildCSRResult (std::vector<int64_t > indptr, std::vector<int64_t > indices,
101- std::vector<int64_t > edgeIDs, bool includeEdgeIDs) {
98+ py::dict buildCSRResult (lbug::main::ArrowQueryResult::CSRArrowArrays arrays) {
10299 py::dict result;
103- result[" indptr" ] = copyToNumpyArray ( indptr);
104- result[" indices" ] = copyToNumpyArray ( indices);
105- if (includeEdgeIDs ) {
106- result[" edge_ids" ] = copyToNumpyArray ( edgeIDs);
100+ result[" indptr" ] = importCSRArrowArray (arrays. indptr );
101+ result[" indices" ] = importCSRArrowArray (arrays. indices );
102+ if (arrays. edgeIDs . has_value () ) {
103+ result[" edge_ids" ] = importCSRArrowArray (*arrays. edgeIDs );
107104 } else {
108105 result[" edge_ids" ] = py::none ();
109106 }
@@ -377,9 +374,7 @@ lbug::pyarrow::Table PyQueryResult::getAsArrow(std::int64_t chunkSize,
377374py::dict PyQueryResult::getCSR () {
378375 if (auto * arrowQueryResult = dynamic_cast <lbug::main::ArrowQueryResult*>(queryResult);
379376 arrowQueryResult != nullptr && arrowQueryResult->hasCSRMetadata ()) {
380- const auto & metadata = arrowQueryResult->getCSRMetadata ();
381- return buildCSRResult (metadata.indptr , metadata.indices , metadata.edgeIDs ,
382- metadata.hasEdgeIDs );
377+ return buildCSRResult (arrowQueryResult->getCSRArrowArrays ());
383378 }
384379 throw RuntimeException (
385380 " CSR export is only supported for Arrow query results with native CSR metadata." );
0 commit comments