You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2019/08/01 12:56:32 UTC

[GitHub] [incubator-doris] gaodayue commented on a change in pull request #1572: Add new format short key index

gaodayue commented on a change in pull request #1572: Add new format short key index
URL: https://github.com/apache/incubator-doris/pull/1572#discussion_r309664107
 
 

 ##########
 File path: be/src/olap/short_key_index.h
 ##########
 @@ -0,0 +1,197 @@
+// 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.
+
+#pragma once
+
+#include <cstdint>
+#include <iterator>
+#include <string>
+#include <vector>
+
+#include "common/status.h"
+#include "gen_cpp/segment_v2.pb.h"
+#include "util/faststring.h"
+#include "util/slice.h"
+
+namespace doris {
+
+// Used to encode a segment short key indices to binary format. This version
+// only accepts binary key, client should assure that input key is sorted,
+// otherwise error could happens. This builder would arrange data in following
+// format.
+//      index = encoded_keys + encoded_offsets + footer + footer_size + checksum
+//      encoded_keys = binary_key + [, ...]
+//      encoded_offsets = encoded_offset + [, ...]
+//      encoded_offset = variant32
+//      footer = ShortKeyFooterPB
+//      footer_size = fixed32
+//      checksum = fixed32
+// Usage:
+//      ShortKeyIndexBuilder builder(segment_id, num_rows_per_block);
+//      builder.add_item(key1);
+//      ...
+//      builder.add_item(keyN);
+//      builder.finalize(segment_size, num_rows, &slices);
+// TODO(zc):
+// 1. If this can leverage binary page to save key and offset data
+// 2. Extending this to save in a BTree like struct, which can index full key
+//    more than short key
+class ShortKeyIndexBuilder {
+public:
+    ShortKeyIndexBuilder(uint32_t segment_id,
+                         uint32_t num_rows_per_block) {
+        _footer.set_segment_id(segment_id);
+        _footer.set_num_rows_per_block(num_rows_per_block);
+    }
+    
+    Status add_item(const Slice& key);
+
+    Status finalize(uint32_t segment_size, uint32_t num_rows, std::vector<Slice>* slices);
+
+private:
+    segment_v2::ShortKeyFooterPB _footer;
+
+    faststring _key_buf;
+    faststring _offset_buf;
+    std::string _footer_buf;
+    std::vector<uint32_t> _offsets;
 
 Review comment:
   it's not used

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org