Skip to content

Commit

Permalink
add getExecutionTime, getCompilingTime, and getNumTuples to python api
Browse files Browse the repository at this point in the history
  • Loading branch information
lehners committed Jun 22, 2023
1 parent 8dead37 commit bdd6de1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tools/python_api/src_cpp/include/py_query_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class PyQueryResult {

bool isSuccess() const;

double getExecutionTime();

double getCompilingTime();

size_t getNumTuples();

private:
static py::dict getPyDictFromProperties(
const std::vector<std::pair<std::string, std::unique_ptr<kuzu::common::Value>>>&
Expand Down
17 changes: 16 additions & 1 deletion tools/python_api/src_cpp/py_query_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ void PyQueryResult::initialize(py::handle& m) {
.def("getColumnNames", &PyQueryResult::getColumnNames)
.def("getColumnDataTypes", &PyQueryResult::getColumnDataTypes)
.def("resetIterator", &PyQueryResult::resetIterator)
.def("isSuccess", &PyQueryResult::isSuccess);
.def("isSuccess", &PyQueryResult::isSuccess)
.def("getCompilingTime", &PyQueryResult::getCompilingTime)
.def("getExecutionTime", &PyQueryResult::getExecutionTime)
.def("getNumTuples", &PyQueryResult::getNumTuples);
// PyDateTime_IMPORT is a macro that must be invoked before calling any other cpython datetime
// macros. One could also invoke this in a separate function like constructor. See
// https://docs.python.org/3/c-api/datetime.html for details.
Expand Down Expand Up @@ -236,3 +239,15 @@ py::dict PyQueryResult::convertNodeIdToPyDict(const nodeID_t& nodeId) {
idDict["table"] = py::cast(nodeId.tableID);
return idDict;
}

double PyQueryResult::getExecutionTime() {
return queryResult->getQuerySummary()->getExecutionTime();

Check warning on line 244 in tools/python_api/src_cpp/py_query_result.cpp

View check run for this annotation

Codecov / codecov/patch

tools/python_api/src_cpp/py_query_result.cpp#L243-L244

Added lines #L243 - L244 were not covered by tests
}

double PyQueryResult::getCompilingTime() {
return queryResult->getQuerySummary()->getCompilingTime();

Check warning on line 248 in tools/python_api/src_cpp/py_query_result.cpp

View check run for this annotation

Codecov / codecov/patch

tools/python_api/src_cpp/py_query_result.cpp#L247-L248

Added lines #L247 - L248 were not covered by tests
}

size_t PyQueryResult::getNumTuples() {
return queryResult->getNumTuples();

Check warning on line 252 in tools/python_api/src_cpp/py_query_result.cpp

View check run for this annotation

Codecov / codecov/patch

tools/python_api/src_cpp/py_query_result.cpp#L251-L252

Added lines #L251 - L252 were not covered by tests
}
45 changes: 45 additions & 0 deletions tools/python_api/src_py/query_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class QueryResult:
get_as_torch_geometric()
Converts the nodes and rels in query result into a PyTorch Geometric graph representation
torch_geometric.data.Data or torch_geometric.data.HeteroData.
get_execution_time()
Get the time in ms which was required for executing the query.
get_compiling_time()
Get the time in ms which was required for compiling the query.
def get_num_tuples(self):
Get the number of tuples which the query returned.
"""

def __init__(self, connection, query_result):
Expand Down Expand Up @@ -359,3 +368,39 @@ def get_as_torch_geometric(self):

converter = TorchGeometricResultConverter(self)
return converter.get_as_torch_geometric()

def get_execution_time(self):
"""
Get the time in ms which was required for executing the query.
Returns
-------
double
Query execution time as double in ms.
"""
self.check_for_query_result_close()
return self._query_result.getExecutionTime()

def get_compiling_time(self):
"""
Get the time in ms which was required for compiling the query.
Returns
-------
double
Query compile time as double in ms.
"""
self.check_for_query_result_close()
return self._query_result.getCompilingTime()

def get_num_tuples(self):
"""
Get the number of tuples which the query returned.
Returns
-------
int
Number of tuples.
"""
self.check_for_query_result_close()
return self._query_result.getNumTuples()

0 comments on commit bdd6de1

Please sign in to comment.