Skip to content

Commit 3e325d6

Browse files
[c++, r, python] read_next clean-up (#3450) (#3480)
Co-authored-by: nguyenv <[email protected]>
1 parent 241dccf commit 3e325d6

File tree

6 files changed

+26
-87
lines changed

6 files changed

+26
-87
lines changed

apis/python/src/tiledbsoma/managed_query.cc

-20
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void load_managed_query(py::module& m) {
6161
py::arg("ctx"),
6262
py::arg("name") = "unnamed")
6363

64-
.def("setup_read", &ManagedQuery::setup_read)
6564
.def("is_empty_query", &ManagedQuery::is_empty_query)
6665
.def("is_complete", &ManagedQuery::is_complete)
6766

@@ -117,25 +116,6 @@ void load_managed_query(py::module& m) {
117116
"if_not_empty"_a = false,
118117
"replace"_a = false)
119118

120-
.def(
121-
"submit_read",
122-
&ManagedQuery::submit_read,
123-
py::call_guard<py::gil_scoped_release>())
124-
.def(
125-
"results",
126-
[](ManagedQuery& mq) -> std::optional<py::object> {
127-
try {
128-
// Release python GIL before reading data
129-
py::gil_scoped_release release;
130-
auto tbl = mq.results();
131-
// Acquire python GIL before accessing python objects
132-
py::gil_scoped_acquire acquire;
133-
return to_table(std::make_optional(tbl));
134-
} catch (const std::exception& e) {
135-
throw TileDBSOMAError(e.what());
136-
}
137-
})
138-
139119
.def(
140120
"next",
141121
[](ManagedQuery& mq) -> std::optional<py::object> {

apis/r/src/riterator.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,7 @@ Rcpp::XPtr<tdbs::SOMAArray> sr_setup(
169169
// [[Rcpp::export]]
170170
bool sr_complete(Rcpp::XPtr<tdbs::SOMAArray> sr) {
171171
check_xptr_tag<tdbs::SOMAArray>(sr);
172-
bool complt = sr->is_complete(true);
173-
bool initial = sr->is_initial_read();
174-
bool res = complt && !initial; // completed transfer if query status
175-
// complete and query ran once
176-
spdl::debug(
177-
"[sr_complete] Complete query test {} (compl {} initial {})",
178-
res,
179-
complt,
180-
initial);
181-
return res;
172+
return sr->results_complete();
182173
}
183174

184175
//' @noRd

libtiledbsoma/src/soma/managed_query.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1252,4 +1252,4 @@ bool ManagedQuery::_extend_and_evolve_schema<std::string>(
12521252
}
12531253
return false;
12541254
}
1255-
}; // namespace tiledbsoma
1255+
}; // namespace tiledbsoma

libtiledbsoma/src/soma/managed_query.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,6 @@ class ManagedQuery {
286286
std::unique_ptr<ArrowSchema> arrow_schema,
287287
std::unique_ptr<ArrowArray> arrow_array);
288288

289-
/**
290-
* @brief Configure query and allocate result buffers for reads.
291-
*
292-
*/
293-
void setup_read();
294-
295289
std::optional<std::shared_ptr<ArrayBuffers>> read_next();
296290

297291
/**
@@ -380,19 +374,6 @@ class ManagedQuery {
380374
return buffers_->at(name)->string_view(index);
381375
}
382376

383-
/**
384-
* @brief Submit the query.
385-
*
386-
*/
387-
void submit_read();
388-
389-
/**
390-
* @brief Return results from the query.
391-
*
392-
* @return std::shared_ptr<ArrayBuffers>
393-
*/
394-
std::shared_ptr<ArrayBuffers> results();
395-
396377
/**
397378
* @brief Submit the write query.
398379
*
@@ -445,6 +426,25 @@ class ManagedQuery {
445426
//= private non-static
446427
//===================================================================
447428

429+
/**
430+
* @brief Configure query and allocate result buffers for reads.
431+
*
432+
*/
433+
void setup_read();
434+
435+
/**
436+
* @brief Submit the query.
437+
*
438+
*/
439+
void submit_read();
440+
441+
/**
442+
* @brief Return results from the query.
443+
*
444+
* @return std::shared_ptr<ArrayBuffers>
445+
*/
446+
std::shared_ptr<ArrayBuffers> results();
447+
448448
/**
449449
* @brief Check if column name is contained in the query results.
450450
*
@@ -880,4 +880,4 @@ bool ManagedQuery::_extend_and_evolve_schema<std::string>(
880880

881881
}; // namespace tiledbsoma
882882

883-
#endif
883+
#endif

libtiledbsoma/src/soma/soma_array.cc

+1-24
Original file line numberDiff line numberDiff line change
@@ -269,30 +269,7 @@ void SOMAArray::reset(
269269
}
270270

271271
std::optional<std::shared_ptr<ArrayBuffers>> SOMAArray::read_next() {
272-
// If the query is complete, return `std::nullopt`
273-
if (mq_->is_complete(true)) {
274-
return std::nullopt;
275-
}
276-
277-
// Configure query and allocate result buffers
278-
mq_->setup_read();
279-
280-
// Continue to submit the empty query on first read to return empty results
281-
if (mq_->is_empty_query()) {
282-
if (first_read_next_) {
283-
first_read_next_ = false;
284-
return mq_->results();
285-
} else {
286-
return std::nullopt;
287-
}
288-
}
289-
290-
first_read_next_ = false;
291-
292-
mq_->submit_read();
293-
294-
// Return the results, possibly incomplete
295-
return mq_->results();
272+
return mq_->read_next();
296273
}
297274

298275
void SOMAArray::set_column_data(

libtiledbsoma/test/unit_managed_query.cc

+3-12
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ TEST_CASE("ManagedQuery: Basic execution test") {
128128
auto [array, d0, a0, _] = create_array(uri, *ctx);
129129

130130
auto mq = ManagedQuery(array, ctx);
131-
mq.setup_read();
132-
133-
mq.submit_read();
134-
auto results = mq.results();
131+
auto results = mq.read_next();
135132
REQUIRE(mq.results_complete());
136133

137134
auto num_cells = mq.total_num_cells();
@@ -152,10 +149,7 @@ TEST_CASE("ManagedQuery: Select test") {
152149
auto mq = ManagedQuery(array, ctx);
153150
mq.select_columns({attr_name});
154151
mq.select_points<std::string>(dim_name, {"a"});
155-
mq.setup_read();
156-
157-
mq.submit_read();
158-
auto results = mq.results();
152+
auto results = mq.read_next();
159153
REQUIRE(mq.results_complete());
160154

161155
auto num_cells = mq.total_num_cells();
@@ -178,10 +172,7 @@ TEST_CASE("ManagedQuery: Validity test") {
178172
auto [array, d0, a0, a0_valids] = create_array(uri, *ctx);
179173

180174
auto mq = ManagedQuery(array, ctx);
181-
mq.setup_read();
182-
183-
mq.submit_read();
184-
auto results = mq.results();
175+
auto results = mq.read_next();
185176
REQUIRE(mq.results_complete());
186177

187178
auto num_cells = mq.total_num_cells();

0 commit comments

Comments
 (0)