chaoyli commented on a change in pull request #1775: add predicate filter(#1652) URL: https://github.com/apache/incubator-doris/pull/1775#discussion_r335457102
########## File path: be/src/olap/selection_vector.h ########## @@ -0,0 +1,172 @@ +// 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 <memory> + +#include "util/bitmap.h" + +namespace doris { + +// Bit-vector representing the selection status of each row in a row block. +// +// It is used to scan data with column predicate. +// the bit in the selection vector is used to indicate whether the given row is live. +class SelectionVector { +public: + // Construct a new vector. The bits are initially in an indeterminate state. + // Call set_all_true() if you require all rows to be initially selected. + explicit SelectionVector(size_t row_capacity) + : _n_rows(row_capacity), + _n_bytes(BitmapSize(row_capacity)), + _bitmap(new uint8_t[_n_bytes]) { + CHECK_GT(_n_bytes, 0); + set_all_false(); + } + + // returen the number of selected rows. + size_t count_selected() const { + return Bits::Count(_bitmap.get(), _n_bytes); + } + + // Return true if any rows are selected, or false + // This is equivalent to (count_selected() > 0), but faster. + inline bool any_selected() const; + + bool is_row_selected(size_t row) const { + DCHECK_LT(row, _n_rows); + return BitmapTest(_bitmap.get(), row); + } + + void set_row_selected(size_t row) { Review comment: I found many function in this Class only used in unit test. I have a suggestion that you can integrated this unit test into RowBlockV2, all branches also will be covered. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
