gaodayue commented on a change in pull request #2050: segment_v2: Support bitmap index build URL: https://github.com/apache/incubator-doris/pull/2050#discussion_r341096027
########## File path: be/src/olap/rowset/segment_v2/index_page.cpp ########## @@ -0,0 +1,124 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "olap/rowset/segment_v2/index_page.h" + +#include <string> + +#include "common/logging.h" +#include "util/coding.h" + +namespace doris { +namespace segment_v2 { + +void IndexPageBuilder::add(const Slice& key, const PagePointer& ptr) { + DCHECK(!_finished) << "must reset() after finish() to add new entry"; + _entry_offsets.push_back(_buffer.size()); + put_length_prefixed_slice(&_buffer, key); + ptr.encode_to(&_buffer); +} + +bool IndexPageBuilder::is_full() const { + // estimate size of IndexPageFooterPB to be 16 + return _buffer.size() + _entry_offsets.size() * sizeof(uint32_t) + 16 > _index_page_size; +} + +Slice IndexPageBuilder::finish() { + DCHECK(!_finished) << "already called finish()"; + for (uint32_t offset : _entry_offsets) { + put_fixed32_le(&_buffer, offset); + } + IndexPageFooterPB footer; + footer.set_num_entries(_entry_offsets.size()); + footer.set_type(_is_leaf ? IndexPageFooterPB::LEAF : IndexPageFooterPB::INTERNAL); Review comment: Yeah, we planned to implement one-level index first, then extend to multi-level BTree index in future PR ---------------------------------------------------------------- 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org