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/07/23 11:33:13 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #1409: Add dict page

imay commented on a change in pull request #1409: Add dict page
URL: https://github.com/apache/incubator-doris/pull/1409#discussion_r306265081
 
 

 ##########
 File path: be/src/olap/rowset/segment_v2/binary_dict_page.cpp
 ##########
 @@ -0,0 +1,223 @@
+// 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/binary_dict_page.h"
+
+#include "util/slice.h" // for Slice
+#include "gutil/strings/substitute.h" // for Substitute
+#include "runtime/mem_pool.h"
+
+#include "olap/rowset/segment_v2/bitshuffle_page.h"
+#include "olap/rowset/segment_v2/rle_page.h"
+
+namespace doris {
+namespace segment_v2 {
+
+using strings::Substitute;
+
+BinaryDictPageBuilder::BinaryDictPageBuilder(const PageBuilderOptions& options) :
+    _options(options),
+    _finished(false),
+    _data_page_builder(nullptr),
+    _dict_builder(nullptr),
+    _encoding_type(DICT_ENCODING) {
+    // initially use DICT_ENCODING
+    // TODO: the data page builder type can be created by Factory according to user config
+    _data_page_builder.reset(new BitshufflePageBuilder<OLAP_FIELD_TYPE_INT>(options));
+    PageBuilderOptions dict_builder_options;
+    dict_builder_options.data_page_size = _options.dict_page_size;
+    _dict_builder.reset(new BinaryPlainPageBuilder(dict_builder_options));
+    reset();
+}
+
+bool BinaryDictPageBuilder::is_page_full() {
+    if (_data_page_builder->is_page_full()) {
+        return true;
+    }
+    if (_encoding_type == DICT_ENCODING && _dict_builder->is_page_full()) {
+        return true;
+    }
+    return false;
+}
+
+Status BinaryDictPageBuilder::add(const uint8_t* vals, size_t* count) {
+    if (_encoding_type == DICT_ENCODING) {
+        DCHECK(!_finished);
+        DCHECK_GT(*count, 0);
+        const Slice* src = reinterpret_cast<const Slice*>(vals);
+        size_t num_added = 0;
+        uint32_t value_code = -1;
+        for (int i = 0; i < *count; ++i, ++src) {
+            auto ret = _dictionary.find(*src);
+            size_t add_count = 1;
+            if (ret != _dictionary.end()) {
+                value_code = ret->second;
+            } else {
+                if (_dict_builder->is_page_full()) {
+                    break;
+                }
+                char* item_mem = _arena.Allocate(src->size);
+                if (item_mem == nullptr) {
+                    return Status::Corruption(Substitute("memory allocate failed, size:$0", src->size));
 
 Review comment:
   it is not corruption error, MemoryAllocFailed

----------------------------------------------------------------
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