MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / FactorizedTableIterator

Class FactorizedTableIterator

src/include/processor/result/factorized_table.h:270–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268};
269
270class FactorizedTableIterator {
271public:
272 explicit FactorizedTableIterator(FactorizedTable& factorizedTable);
273
274 bool hasNext() {
275 return nextTupleIdx < factorizedTable.getNumTuples() || nextFlatTupleIdx < numFlatTuples;
276 }
277
278 void getNext(FlatTuple& tuple);
279
280 void resetState();
281
282private:
283 // The dataChunkPos may be not consecutive, which means some entries in the
284 // flatTuplePositionsInDataChunk is invalid. We put pair(UINT64_MAX, UINT64_MAX) in the
285 // invalid entries.
286 bool isValidDataChunkPos(uint32_t dataChunkPos) const {
287 return flatTuplePositionsInDataChunk[dataChunkPos].first != UINT64_MAX;
288 }
289
290 void readUnflatColToFlatTuple(ft_col_idx_t colIdx, uint8_t* valueBuffer, FlatTuple& tuple);
291
292 void readFlatColToFlatTuple(ft_col_idx_t colIdx, uint8_t* valueBuffer, FlatTuple& tuple);
293
294 // We put pair(UINT64_MAX, UINT64_MAX) in all invalid entries in
295 // FlatTuplePositionsInDataChunk.
296 void updateInvalidEntriesInFlatTuplePositionsInDataChunk();
297
298 // This function is used to update the number of elements in the dataChunk when we want
299 // to iterate a new tuple.
300 void updateNumElementsInDataChunk();
301
302 // This function updates the flatTuplePositionsInDataChunk, so that getNextFlatTuple() can
303 // correctly outputs the next flat tuple in the current tuple. For example, we want to read
304 // two unFlat columns, which are on different dataChunks A,B and both have 100 columns. The
305 // flatTuplePositionsInDataChunk after the first call to getNextFlatTuple() looks like:
306 // {dataChunkA : [0, 100]}, {dataChunkB : [0, 100]} This function updates the
307 // flatTuplePositionsInDataChunk to: {dataChunkA: [1, 100]}, {dataChunkB: [0, 100]}. Meaning
308 // that the getNextFlatTuple() should read the second element in the first unflat column and
309 // the first element in the second unflat column.
310 void updateFlatTuplePositionsInDataChunk();
311
312 const FactorizedTable& factorizedTable;
313 uint8_t* currentTupleBuffer;
314 uint64_t numFlatTuples;
315 ft_tuple_idx_t nextFlatTupleIdx;
316 ft_tuple_idx_t nextTupleIdx;
317 // This field stores the (nextIdxToReadInDataChunk, numElementsInDataChunk) of each dataChunk.
318 std::vector<std::pair<uint64_t, uint64_t>> flatTuplePositionsInDataChunk;
319};
320
321} // namespace processor
322} // namespace lbug

Callers 2

toStringMethod · 0.50
ArrowQueryResultMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected