Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++/python] Add SOMAArray::stats to get query stats #1927

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apis/python/src/tiledbsoma/pytiledbsoma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ PYBIND11_MODULE(pytiledbsoma, m) {
"platform_config"_a = py::dict(),
"timestamp"_a = py::none())

.def("stats", &SOMAArray::stats)

.def(
"set_condition",
[](SOMAArray& reader,
Expand Down
4 changes: 4 additions & 0 deletions libtiledbsoma/src/soma/managed_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void ManagedQuery::reset() {
query_submitted_ = false;
}

std::string ManagedQuery::stats() {
return query_->stats();
}

void ManagedQuery::select_columns(
const std::vector<std::string>& names, bool if_not_empty) {
// Return if we are selecting all columns (columns_ is empty) and we want to
Expand Down
7 changes: 7 additions & 0 deletions libtiledbsoma/src/soma/managed_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class ManagedQuery {
*/
void reset();

/**
* @brief Returns a JSON-formatted string of the stats.
*
* @return std::string
*/
std::string stats();

/**
* @brief Select columns names to query (dim and attr). If the
* `if_not_empty` parameter is `true`, the column will be selected iff the
Expand Down
4 changes: 4 additions & 0 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ void SOMAArray::reset(
submitted_ = false;
}

std::string SOMAArray::stats() {
return mq_->stats();
}

std::optional<std::shared_ptr<ArrayBuffers>> SOMAArray::read_next() {
// If the query is complete, return `std::nullopt`
if (mq_->is_complete(true)) {
Expand Down
7 changes: 7 additions & 0 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ class SOMAArray {
std::string_view batch_size = "auto",
ResultOrder result_order = ResultOrder::automatic);

/**
* @brief Returns a JSON-formatted string of the stats.
*
* @return std::string
*/
std::string stats();

/**
* @brief Set the dimension slice using one point
*
Expand Down
14 changes: 13 additions & 1 deletion libtiledbsoma/test/test_soma_array.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python

import os
import json

import pyarrow as pa

import tiledbsoma.pytiledbsoma as clib

VERBOSE = False
Expand Down Expand Up @@ -51,6 +51,18 @@ def test_soma_array_obs():
assert sr.results_complete()
assert arrow_table.num_rows == 2638

def test_soma_array_stats():
"""Get query stats from an obs array."""

name = "obs"
uri = os.path.join(SOMA_URI, name)
sr = clib.SOMAArray(uri)
sr.read_next()
stats = json.loads(sr.stats())

assert "Context.StorageManager.Query.Reader.dowork.sum" in stats["timers"]
assert "Context.StorageManager.Query.Reader.dowork.avg" in stats["timers"]
assert "Context.StorageManager.Query.Reader.loop_num" in stats["counters"]

def test_soma_array_var():
"""Read all values from var array into an arrow table."""
Expand Down
Loading