imay commented on a change in pull request #1341: Add plain page URL: https://github.com/apache/incubator-doris/pull/1341#discussion_r295755216
########## File path: be/src/olap/rowset/segment_v2/plain_page.h ########## @@ -0,0 +1,170 @@ +#pragma once + +#include "util/coding.h" +#include "util/faststring.h" +#include "olap/olap_common.h" +#include "olap/types.h" +#include "olap/rowset/segment_v2/page_builder.h" +#include "olap/rowset/segment_v2/page_decoder.h" +#include "olap/rowset/segment_v2/options.h" + +namespace doris { + +namespace segment_v2 { + +static const size_t plainPageHeaderSize = sizeof(uint32_t) * 2; + +template<FieldType Type> +class PlainPageBuilder : public PageBuilder { +public: + PlainPageBuilder(const PageBuilderOptions *options) : + _options(options) { + // Reserve enough space for the block, plus a bit of slop since + // we often overrun the block by a few values. + _buffer.reserve(plainPageHeaderSize + _options->data_page_size + 1024); + reset(); + } + + bool is_page_full() override { + return _buffer.size() > _options->data_page_size; + } + + Status add(const uint8_t *vals, size_t *count) override { + size_t old_size = _buffer.size(); + _buffer.resize(old_size + *count * SIZE_OF_TYPE); + memcpy(&_buffer[old_size], vals, *count * SIZE_OF_TYPE); + _count += *count; + return Status::OK(); + } + + Status get_dictionary_page(Slice *dictionary_page) override { + return Status::NotSupported("get_dictionary_page not supported in plain page builder"); + } + + Slice finish(const rowid_t page_first_rowid) override { + encode_fixed32_le((uint8_t *) &_buffer[0], _count); + encode_fixed32_le((uint8_t *) &_buffer[4], page_first_rowid); + return Slice(_buffer.data(), plainPageHeaderSize + _count * SIZE_OF_TYPE); + } + + void reset() override { + _count = 0; + _buffer.clear(); + _buffer.resize(plainPageHeaderSize); + } + + size_t count() const { + return _count; + } + + // this api will release the memory ownership of encoded data + // Note: + // release() should be called after finish + // reset() should be called after this function before reuse the builder + void release() override { + uint8_t *ret = _buffer.release(); + (void) ret; + } + +private: + faststring _buffer; + const PageBuilderOptions *_options; Review comment: you should copy this option. This option maybe a variable in stack, which would be invalid when you use later ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org