1+ #include " gpu_query_result.hpp"
2+ #include " duckdb/common/to_string.hpp"
3+ #include " duckdb/main/client_context.hpp"
4+ #include " duckdb/common/box_renderer.hpp"
5+
6+ namespace duckdb {
7+
8+ void GPUResultCollection::SetCapacity (size_t capacity) {
9+ data_chunks = new DataChunk[capacity];
10+ }
11+
12+ void GPUResultCollection::AddChunk (DataChunk& chunk) {
13+ num_rows += chunk.size ();
14+ data_chunks[write_idx].Move (chunk);
15+ write_idx += 1 ;
16+ }
17+
18+ unique_ptr<DataChunk> GPUResultCollection::GetNext () {
19+ // We have returned all of the values then return the empty result
20+ if (read_idx >= write_idx) {
21+ return nullptr ;
22+ }
23+
24+ // Create a result that references the value in the buffer
25+ DataChunk& return_chunk = data_chunks[read_idx];
26+ unique_ptr<DataChunk> result_value = make_uniq<DataChunk>();
27+
28+ result_value->InitializeEmpty (return_chunk.GetTypes ());
29+ result_value->SetCardinality (return_chunk.size ());
30+ for (int col = 0 ; col < return_chunk.data .size (); col++) {
31+ result_value->data [col].Reference (return_chunk.data [col]);
32+ }
33+ read_idx += 1 ;
34+ num_rows -= result_value->size ();
35+
36+ return result_value;
37+ }
38+
39+ GPUQueryResult::GPUQueryResult (StatementType statement_type, StatementProperties properties,
40+ vector<string> names, vector<LogicalType> types, ClientProperties client_properties, unique_ptr<GPUResultCollection> result_collection)
41+ : QueryResult(QueryResultType::MATERIALIZED_RESULT , statement_type, std::move(properties), types,
42+ std::move (names), std::move(client_properties)), result_collection(std::move(result_collection)) {
43+
44+ }
45+
46+ string GPUQueryResult::ToString () {
47+ std::string result (" GPUQueryResult" );
48+ return result;
49+ }
50+
51+ string GPUQueryResult::ToBox (ClientContext &context, const BoxRendererConfig &config) {
52+ std::string result (" BoxedGPUQueryResult" );
53+ return result;
54+ }
55+
56+ idx_t GPUQueryResult::RowCount () const {
57+ idx_t row_count = (idx_t ) result_collection->size ();
58+ return row_count;
59+ }
60+
61+ unique_ptr<DataChunk> GPUQueryResult::Fetch () {
62+ return FetchRaw ();
63+ }
64+
65+ Value GPUQueryResult::GetValue (idx_t column, idx_t index) {
66+ throw InternalException (" GetValue not implemented for GPUQueryResult" );
67+ }
68+
69+ unique_ptr<DataChunk> GPUQueryResult::FetchRaw () {
70+ return result_collection->GetNext ();
71+ }
72+
73+ }
0 commit comments