Kùzu C++ API
Loading...
Searching...
No Matches
query_result.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include "api.h"
6#include "arrow.h"
7#include "types.h"
8#include "kuzu_fwd.h"
9#include "flat_tuple.h"
10#include "query_summary.h"
11
12namespace kuzu {
13namespace main {
14
19 friend class Connection;
20 friend class ClientContext;
21 class QueryResultIterator {
22 private:
23 QueryResult* currentResult;
24
25 public:
26 QueryResultIterator() = default;
27
28 explicit QueryResultIterator(QueryResult* startResult) : currentResult(startResult) {}
29
30 void operator++() {
31 if (currentResult) {
32 currentResult = currentResult->nextQueryResult.get();
33 }
34 }
35
36 bool isEnd() const { return currentResult == nullptr; }
37
38 bool hasNextQueryResult() const { return currentResult->nextQueryResult != nullptr; }
39
40 QueryResult* getCurrentResult() const { return currentResult; }
41 };
42
43public:
48
49 explicit QueryResult(const PreparedSummary& preparedSummary);
57 KUZU_API bool isSuccess() const;
61 KUZU_API std::string getErrorMessage() const;
65 KUZU_API size_t getNumColumns() const;
69 KUZU_API std::vector<std::string> getColumnNames() const;
73 KUZU_API std::vector<common::LogicalType> getColumnDataTypes() const;
77 KUZU_API uint64_t getNumTuples() const;
86 KUZU_API bool hasNext() const;
95
96 std::unique_ptr<QueryResult> nextQueryResult;
100 KUZU_API std::shared_ptr<processor::FlatTuple> getNext();
104 KUZU_API std::string toString();
105
110
111 processor::FactorizedTable* getTable() { return factorizedTable.get(); }
112
120 KUZU_API std::unique_ptr<ArrowSchema> getArrowSchema() const;
121
133 KUZU_API std::unique_ptr<ArrowArray> getNextArrowChunk(int64_t chunkSize);
134
135private:
136 void setColumnHeader(std::vector<std::string> columnNames,
137 std::vector<common::LogicalType> columnTypes);
138 void initResultTableAndIterator(std::shared_ptr<processor::FactorizedTable> factorizedTable_);
139 void validateQuerySucceed() const;
140
141private:
142 // execution status
143 bool success = true;
144 std::string errMsg;
145
146 // header information
147 std::vector<std::string> columnNames;
148 std::vector<common::LogicalType> columnDataTypes;
149 // data
150 std::shared_ptr<processor::FactorizedTable> factorizedTable;
151 std::unique_ptr<processor::FlatTupleIterator> iterator;
152 std::shared_ptr<processor::FlatTuple> tuple;
153
154 // execution statistics
155 std::unique_ptr<QuerySummary> querySummary;
156
157 // query iterator
158 QueryResultIterator queryResultIterator;
159};
160
161} // namespace main
162} // namespace kuzu
#define KUZU_API
Definition api.h:25
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:57
Connection is used to interact with a Database instance. Each Connection is thread-safe....
Definition connection.h:14
QueryResult stores the result of a query execution.
Definition query_result.h:18
KUZU_API QueryResult * getNextQueryResult()
std::unique_ptr< QueryResult > nextQueryResult
Definition query_result.h:96
KUZU_API bool isSuccess() const
KUZU_API size_t getNumColumns() const
KUZU_API std::vector< std::string > getColumnNames() const
KUZU_API std::string toString()
KUZU_API QuerySummary * getQuerySummary() const
KUZU_API std::string getErrorMessage() const
KUZU_API std::unique_ptr< ArrowArray > getNextArrowChunk(int64_t chunkSize)
Returns the next chunk of the query result as an arrow array.
KUZU_API std::vector< common::LogicalType > getColumnDataTypes() const
QueryResult(const PreparedSummary &preparedSummary)
KUZU_API uint64_t getNumTuples() const
KUZU_API bool hasNextQueryResult() const
KUZU_API QueryResult()
Used to create a QueryResult object for the failing query.
KUZU_API std::shared_ptr< processor::FlatTuple > getNext()
KUZU_API ~QueryResult()
Deconstructs the QueryResult object.
KUZU_API std::unique_ptr< ArrowSchema > getArrowSchema() const
Returns the arrow schema of the query result.
KUZU_API void resetIterator()
Resets the result tuple iterator.
processor::FactorizedTable * getTable()
Definition query_result.h:111
KUZU_API bool hasNext() const
QuerySummary stores the execution time, plan, compiling time and query options of a query.
Definition query_summary.h:20
Definition array_utils.h:7
PreparedSummary stores the compiling time and query options of a query.
Definition query_summary.h:12