imay commented on a change in pull request #2471: add block split bloom filter
URL: https://github.com/apache/incubator-doris/pull/2471#discussion_r358192371
 
 

 ##########
 File path: be/src/olap/rowset/segment_v2/bloom_filter_index_writer.cpp
 ##########
 @@ -0,0 +1,187 @@
+// 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/bloom_filter_index_writer.h"
+
+#include <map>
+#include <roaring/roaring.hh>
+
+#include "env/env.h"
+#include "olap/rowset/segment_v2/common.h"
+#include "olap/rowset/segment_v2/encoding_info.h"
+#include "olap/rowset/segment_v2/indexed_column_writer.h"
+#include "olap/rowset/segment_v2/bloom_filter.h" // for BloomFilterOptions, 
BloomFilter
+#include "olap/types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/mem_tracker.h"
+#include "util/faststring.h"
+#include "util/slice.h"
+
+namespace doris {
+namespace segment_v2 {
+
+namespace {
+
+template<typename CppType>
+struct BloomFilterTraits {
+    using ValueDict = std::set<CppType>;
+};
+
+template<>
+struct BloomFilterTraits<Slice> {
+    using ValueDict = std::set<Slice, Slice::Comparator>;
+};
+
+// Builder for bloom filter. In doris, bloom filter index is used in
+// high cardinality key columns and none-agg value columns for high 
selectivity and storage
+// efficiency.
+// This builder builds a bloom filter page by every data page, with a page id 
index.
+// Meanswhile, It adds an ordinal index to load bloom filter index according 
to requirement.
+//
+template <FieldType field_type>
+class BloomFilterIndexWriterImpl : public BloomFilterIndexWriter {
+public:
+    using CppType = typename CppTypeTraits<field_type>::CppType;
+    using ValueDict = typename BloomFilterTraits<CppType>::ValueDict;
+
+    explicit BloomFilterIndexWriterImpl(const BloomFilterOptions& bf_options,
+            const TypeInfo* typeinfo)
+        : _bf_options(bf_options), _typeinfo(typeinfo),
+          _tracker(), _pool(&_tracker), _has_null(false) { }
+
+    ~BloomFilterIndexWriterImpl() = default;
+
+    void add_values(const void* values, size_t count) override {
+        const CppType* v = (const CppType*)values;
+        for (int i = 0; i < count; ++i) {
+            if (_values.find(*v) == _values.end()) {
+                CppType new_value;
+                _typeinfo->deep_copy(&new_value, v, &_pool);
 
 Review comment:
   If type is not string, there is no need to copy.

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

Reply via email to