@@ -439,4 +439,56 @@ int BufferedTupleStream::compute_row_size(TupleRow* row) const {
439439
440440 return size;
441441}
442+
443+ inline uint8_t * BufferedTupleStream::allocate_row (int size) {
444+ DCHECK (!_closed);
445+
446+ if (UNLIKELY (_write_block == NULL || _write_block->bytes_remaining () < size)) {
447+ bool got_block = false ;
448+ _status = new_block_for_write (size, &got_block);
449+
450+ if (!_status.ok () || !got_block) {
451+ return NULL ;
452+ }
453+ }
454+
455+ DCHECK (_write_block != NULL );
456+ // DCHECK(_write_block->is_pinned());
457+ DCHECK_GE (_write_block->bytes_remaining (), size);
458+ ++_num_rows;
459+ _write_block->add_row ();
460+ return _write_block->allocate <uint8_t >(size);
461+ }
462+
463+ inline void BufferedTupleStream::get_tuple_row (const RowIdx& idx, TupleRow* row) const {
464+ DCHECK (!_closed);
465+ // DCHECK(is_pinned());
466+ DCHECK (!_delete_on_read);
467+ DCHECK_EQ (_blocks.size (), _block_start_idx.size ());
468+ DCHECK_LT (idx.block (), _blocks.size ());
469+
470+ uint8_t * data = _block_start_idx[idx.block ()] + idx.offset ();
471+
472+ if (_nullable_tuple) {
473+ // Stitch together the tuples from the block and the NULL ones.
474+ const int tuples_per_row = _desc.tuple_descriptors ().size ();
475+ uint32_t tuple_idx = idx.idx () * tuples_per_row;
476+
477+ for (int i = 0 ; i < tuples_per_row; ++i) {
478+ const uint8_t * null_word = _block_start_idx[idx.block ()] + (tuple_idx >> 3 );
479+ const uint32_t null_pos = tuple_idx & 7 ;
480+ const bool is_not_null = ((*null_word & (1 << (7 - null_pos))) == 0 );
481+ row->set_tuple (i, reinterpret_cast <Tuple*>(
482+ reinterpret_cast <uint64_t >(data) * is_not_null));
483+ data += _desc.tuple_descriptors ()[i]->byte_size () * is_not_null;
484+ ++tuple_idx;
485+ }
486+ } else {
487+ for (int i = 0 ; i < _desc.tuple_descriptors ().size (); ++i) {
488+ row->set_tuple (i, reinterpret_cast <Tuple*>(data));
489+ data += _desc.tuple_descriptors ()[i]->byte_size ();
490+ }
491+ }
492+ }
493+
442494}
0 commit comments