MCPcopy Create free account
hub / github.com/duckdb/duckdb / RenderingResultIterator

Class RenderingResultIterator

tools/shell/shell_renderer.cpp:99–182  ·  view source on GitHub ↗

RenderingResultIterator is an iterator that EITHER (1) iterates over a query result (2) iterates over a materialized result

Source from the content-addressed store, hash-verified

97// (1) iterates over a query result
98// (2) iterates over a materialized result
99struct RenderingResultIterator {
100public:
101 explicit RenderingResultIterator(optional_ptr<RenderingQueryResult> result_p) : result(result_p) {
102 if (!result) {
103 return;
104 }
105 auto &query_result = result->result;
106 auto nCol = query_result.ColumnCount();
107 row_data.data.resize(nCol, string());
108 row_data.is_null.resize(nCol, false);
109 row_data.row_index = 0;
110 chunk_idx = 0;
111 row_in_chunk = 0;
112
113 if (!result->exhausted_result && Finished()) {
114 result->TryConvertChunk();
115 }
116 AssignData();
117 }
118
119 optional_ptr<RenderingQueryResult> result;
120 RowData row_data;
121 idx_t chunk_idx;
122 idx_t row_in_chunk;
123
124public:
125 bool Finished() {
126 return row_data.row_index >= result->loaded_row_count;
127 }
128
129 void AssignData() {
130 if (Finished()) {
131 result = nullptr;
132 return;
133 }
134 // read from the materialized rows
135 auto &chunk = *result->chunks[chunk_idx];
136 idx_t column_count = chunk.ColumnCount();
137 if (row_data.data.size() != column_count) {
138 row_data.data.resize(column_count);
139 }
140 for (idx_t c = 0; c < column_count; c++) {
141 auto &vector = chunk.data[c];
142 if (duckdb::FlatVector::IsNull(vector, row_in_chunk)) {
143 row_data.data[c] = duckdb::string_t(result->renderer.NullValue());
144 row_data.is_null[c] = true;
145 } else {
146 row_data.data[c] = duckdb::FlatVector::GetData<duckdb::string_t>(chunk.data[c])[row_in_chunk];
147 row_data.is_null[c] = false;
148 }
149 }
150 }
151
152 void Next() {
153 if (!result) {
154 return;
155 }
156 // iterate to next position

Callers 2

beginMethod · 0.70
endMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected