QueryResult and QuerySummary
QueryResult
captures all information related to the execution of a query. Each returned tuple is wrapped into a FlatTuple where each entry is wrapped as a Value. You can also obtain a QuerySummary
from a QueryResult, to learn profiling information, such as execution time, about the query you executed.
Example
unique_ptr<QueryResult> result = connection.query("MATCH (a:person) RETURN COUNT(*);");
if (!result->isSuccess()) {
std::cout << result->getErrorMessage() << endl;
}
while (result->hasNext()) {
auto row = result->getNext();
std::cout << row->getResultValue(0)->getInt64Val() << std::endl;
}
Available APIs
class kuzu::main::QueryResult
QueryResult stores the result of a query execution.
getColumnDataTypes
std::vector<common::DataType> getColumnDataTypes ()
Returns:
- dataType of each column in query result.
getColumnNames
std::vector<std::string> getColumnNames ()
Returns:
- name of each column in query result.
getErrorMessage
std::string getErrorMessage ()
Returns:
- error message of the query execution if the query fails.
getNext
std::shared_ptr<processor::FlatTuple> getNext ()
Returns:
- next flat tuple in the query result.
getNumColumns
size_t getNumColumns ()
Returns:
- number of columns in query result.
getNumTuples
uint64_t getNumTuples ()
Returns:
- num of tuples in query result.
getQuerySummary
QuerySummary* getQuerySummary ()
Returns:
- query summary which stores the execution time, compiling time, plan and query options.
bool hasNext ()
Returns:
- whether there are more tuples to read.
isSuccess
bool isSuccess ()
Returns:
- query is executed successfully or not.
writeToCSV
void writeToCSV (const std::string & fileName, char delimiter = ',', char escapeCharacter = ''', char newline = 'n')
writes the query result to a csv file.
Parameters
fileName
name of the csv file.delimiter
delimiter of the csv file.escapeCharacter
escape character of the csv file.newline
newline character of the csv file.
class kuzu::main::QuerySummary
QuerySummary stores the execution time, plan, compiling time and query options of a query.
getCompilingTime
double getCompilingTime ()
Returns:
- query compiling time.
getExecutionTime
double getExecutionTime ()
Returns:
- query execution time.
getPlan
std::string getPlan ()
Returns:
- physical plan for query in string format.