github-actions[bot] commented on code in PR #15588: URL: https://github.com/apache/doris/pull/15588#discussion_r1130750593
########## be/src/util/bitmap_expr_calculation.h: ########## @@ -0,0 +1,217 @@ +// 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 <stack> +#include <string> + +#include "util/bitmap_intersect.h" + +namespace doris { + +// Compute the intersection union difference set of two or more bitmaps +// Usage: orthogonal_bitmap_parse_calculate(bitmap_column, filter_column, input_string) +// Example: orthogonal_bitmap_expr_calculate(user_id, event, '(A|B)&(C-D)'), meaning find the intersection union difference set of user_id in all A/B/C/D 4 bitmaps +// Operation symbol: +// the operator '|' stands for union, the operator '&' stands for intersection, the operator '-' indicates the difference set, the operator '^' stands for xor +class BitmapExprCalculation : public BitmapIntersect<std::string> { +public: + BitmapExprCalculation() = default; + + explicit BitmapExprCalculation(const char* src) { deserialize(src); } + + void bitmap_calculation_init(std::string& input_str) { + _polish = reverse_polish(input_str); + std::string bitmap_key; + for (int i = 0; i < _polish.length(); i++) { + char c = _polish.at(i); + if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') { + bitmap_key += c; + } else if (i != 0 && _polish.at(i - 1) == '\\') { + bitmap_key += c; + } else if (c == '\\') { + continue; + } else { + if (bitmap_key.length() > 0) { + add_key(bitmap_key); + bitmap_key.clear(); + } + } + } + if (bitmap_key.length() > 0) { + add_key(bitmap_key); + bitmap_key.clear(); + } + } + + BitmapValue bitmap_calculate() { + std::stack<BitmapValue> values; + std::string bitmap_key; + for (int i = 0; i < _polish.length(); i++) { + char c = _polish.at(i); + if (c == ' ') { + if (bitmap_key.length() > 0) { + values.push(_bitmaps[bitmap_key]); + bitmap_key.clear(); + } + } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') { + bitmap_key += c; + } else if (i != 0 && _polish.at(i - 1) == '\\') { + bitmap_key += c; + } else if (c == '\\') { + continue; + } else { + if (bitmap_key.length() > 0) { + values.push(_bitmaps[bitmap_key]); + bitmap_key.clear(); + } + if (values.size() >= 2) { + BitmapValue op_a = values.top(); + values.pop(); + BitmapValue op_b = values.top(); + values.pop(); + BitmapValue cal_result; + bitmap_calculate(op_a, op_b, c, cal_result); + values.push(cal_result); + } + } + } + BitmapValue result; + if (bitmap_key.length() > 0) { + result |= _bitmaps[bitmap_key]; + } else if (!values.empty()) { + result |= values.top(); + } + return result; + } + + // calculate the bitmap value by expr bitmap calculate + int64_t bitmap_calculate_count() { + if (_bitmaps.empty()) { + return 0; + } + return bitmap_calculate().cardinality(); + } + +private: + constexpr int priority(char c) { + switch (c) { + case '&': + return 1; + case '|': + return 1; + case '^': + return 1; + case '-': + return 1; + default: + return 0; + } + } + + template <class T> + std::string print_stack(const std::stack<T>& stack) { + std::string result; + while (!stack.empty()) { + result = stack.top() + result; + stack.pop(); Review Comment: warning: 'this' argument to member function 'pop' has type 'const std::stack<char>', but function is not marked const [clang-diagnostic-error] ```cpp stack.pop(); ^ ``` **be/src/util/bitmap_expr_calculation.h:192:** in instantiation of function template specialization 'doris::BitmapExprCalculation::print_stack<char>' requested here ```cpp return print_stack(polish); ^ ``` **/usr/include/c++/11/bits/stl_stack.h:271:** 'pop' declared here ```cpp pop() ^ ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
