You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2023/01/04 03:21:08 UTC

[GitHub] [doris] zhbinbin opened a new pull request, #15588: Add the bitmap intersection and difference set for mixed calculation of udaf

zhbinbin opened a new pull request, #15588:
URL: https://github.com/apache/doris/pull/15588

   ## Problem summary
   Add the bitmap set for  mixed calculation of udaf
   Calculate the bitmap intersection, union and difference set of expressions to calculate the count function.
   
   ## Checklist(Required)
   1. Does it affect the original behavior: 
       - [No]
   2. Has unit tests been added:
       - [No]
   3. Has document been added or modified:
       - [Yes]
   4. Does it need to update dependencies:
       - [No ]
   5. Are there any changes that cannot be rolled back:
       - [ No]
   
   ## Further comments
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1129316608


##########
be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:
##########
@@ -70,6 +70,20 @@ AggregateFunctionPtr create_aggregate_function_orthogonal_bitmap_intersect_count
                                                                              result_is_nullable);
 }
 
+AggregateFunctionPtr create_aggregate_function_orthogonal_bitmap_expr_calculate(
+        const std::string& name, const DataTypes& argument_types, const Array& parameters,
+        bool result_is_nullable) {
+    return create_aggregate_function_orthogonal<AggOrthBitMapExprCal>(

Review Comment:
   warning: no matching function for call to 'create_aggregate_function_orthogonal' [clang-diagnostic-error]
   ```cpp
       return create_aggregate_function_orthogonal<AggOrthBitMapExprCal>(
              ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:28:** candidate function template not viable: requires 3 arguments, but 4 were provided
   ```cpp
   AggregateFunctionPtr create_aggregate_function_orthogonal(const std::string& name,
                        ^
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:
##########
@@ -92,5 +106,10 @@
     factory.register_function_both("orthogonal_bitmap_union_count",
                                    create_aggregate_function_orthogonal_bitmap_union_count);
     factory.register_function_both("intersect_count", create_aggregate_function_intersect_count);
+    factory.register_function_both("orthogonal_bitmap_expr_calculate",
+                                   create_aggregate_function_orthogonal_bitmap_expr_calculate);
+    factory.register_function_both(
+            "orthogonal_bitmap_expr_calculate_count",
+            create_aggregate_function_orthogonal_bitmap_expr_calculate_count);

Review Comment:
   warning: reference to type 'const doris::vectorized::AggregateFunctionSimpleFactory::Creator' (aka 'const function<shared_ptr<doris::vectorized::IAggregateFunction> (const basic_string<char> &, const vector<shared_ptr<const doris::vectorized::IDataType>> &, const bool)>') could not bind to an lvalue of type 'doris::vectorized::AggregateFunctionPtr (const std::string &, const doris::vectorized::DataTypes &, const doris::vectorized::Array &, bool)' (aka 'shared_ptr<doris::vectorized::IAggregateFunction> (const basic_string<char> &, const vector<shared_ptr<const doris::vectorized::IDataType>> &, const doris::vectorized::Array &, bool)') [clang-diagnostic-error]
   ```cpp
               create_aggregate_function_orthogonal_bitmap_expr_calculate_count);
               ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_simple_factory.h:109:** passing argument to parameter 'creator' here
   ```cpp
       void register_function_both(const std::string& name, const Creator& creator) {
                                                                           ^
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:
##########
@@ -92,5 +106,10 @@
     factory.register_function_both("orthogonal_bitmap_union_count",
                                    create_aggregate_function_orthogonal_bitmap_union_count);
     factory.register_function_both("intersect_count", create_aggregate_function_intersect_count);
+    factory.register_function_both("orthogonal_bitmap_expr_calculate",
+                                   create_aggregate_function_orthogonal_bitmap_expr_calculate);

Review Comment:
   warning: reference to type 'const doris::vectorized::AggregateFunctionSimpleFactory::Creator' (aka 'const function<shared_ptr<doris::vectorized::IAggregateFunction> (const basic_string<char> &, const vector<shared_ptr<const doris::vectorized::IDataType>> &, const bool)>') could not bind to an lvalue of type 'doris::vectorized::AggregateFunctionPtr (const std::string &, const doris::vectorized::DataTypes &, const doris::vectorized::Array &, bool)' (aka 'shared_ptr<doris::vectorized::IAggregateFunction> (const basic_string<char> &, const vector<shared_ptr<const doris::vectorized::IDataType>> &, const doris::vectorized::Array &, bool)') [clang-diagnostic-error]
   ```cpp
                                      create_aggregate_function_orthogonal_bitmap_expr_calculate);
                                      ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_simple_factory.h:109:** passing argument to parameter 'creator' here
   ```cpp
       void register_function_both(const std::string& name, const Creator& creator) {
                                                                           ^
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:
##########
@@ -70,6 +70,20 @@
                                                                              result_is_nullable);
 }
 
+AggregateFunctionPtr create_aggregate_function_orthogonal_bitmap_expr_calculate(
+        const std::string& name, const DataTypes& argument_types, const Array& parameters,
+        bool result_is_nullable) {
+    return create_aggregate_function_orthogonal<AggOrthBitMapExprCal>(
+            name, argument_types, parameters, result_is_nullable);
+}
+
+AggregateFunctionPtr create_aggregate_function_orthogonal_bitmap_expr_calculate_count(
+        const std::string& name, const DataTypes& argument_types, const Array& parameters,
+        bool result_is_nullable) {
+    return create_aggregate_function_orthogonal<AggOrthBitMapExprCalCount>(

Review Comment:
   warning: no matching function for call to 'create_aggregate_function_orthogonal' [clang-diagnostic-error]
   ```cpp
       return create_aggregate_function_orthogonal<AggOrthBitMapExprCalCount>(
              ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp:28:** candidate function template not viable: requires 3 arguments, but 4 were provided
   ```cpp
   AggregateFunctionPtr create_aggregate_function_orthogonal(const std::string& name,
                        ^
   ```
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463076515

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yuxuan-luo commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yuxuan-luo (via GitHub)" <gi...@apache.org>.
yuxuan-luo commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1547889170

   @morningman 


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1371690077

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1467293053

   run p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1467973040

   PR approved by anyone and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1461832268

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1461436160

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1467403887

   run p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1467972927

   PR approved by at least one committer and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130635049


##########
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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    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 printStack(std::stack<T> stack) {
+        std::string result;
+        while (!stack.empty()) {
+            result = stack.top() + result;
+            stack.pop();
+        }
+        return result;
+    }
+
+    std::string reversePolish(std::string inputStr) {

Review Comment:
   ```suggestion
       std::string reversePolish(const std::string& input_str) {
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463753962

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130645496


##########
be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.h:
##########
@@ -177,6 +178,102 @@ struct AggOrthBitMapIntersectCount : public AggOrthBitmapBaseData<T> {
     Int64 result = 0;
 };
 
+template <typename T>
+struct AggOrthBitmapExprCalBaseData {
+public:
+    using ColVecData = std::conditional_t<IsNumber<T>, ColumnVector<T>, ColumnString>;
+
+    void add(const IColumn** columns, size_t row_num) {
+        const auto& bitmap_col = static_cast<const ColumnBitmap&>(*columns[0]);
+        const auto& data_col = static_cast<const ColVecData&>(*columns[1]);
+        const auto& bitmap_value = bitmap_col.get_element(row_num);
+        std::string update_key = data_col.get_data_at(row_num).to_string();
+        bitmap_expr_cal.update(update_key, bitmap_value);
+    }
+
+    void init_add_key(const IColumn** columns, size_t row_num, int argument_size) {
+        if (first_init) {
+            DCHECK(argument_size > 1);
+            const auto& col = static_cast<const ColVecData&>(*columns[2]);
+            std::string expr = col.get_data_at(row_num).to_string();
+            bitmap_expr_cal.bitmap_calculation_init(expr);
+            first_init = false;
+        }
+    }
+
+protected:
+    doris::BitmapExprCalculation bitmap_expr_cal;
+    bool first_init = true;
+};
+
+template <typename T>
+struct AggOrthBitMapExprCal : public AggOrthBitmapExprCalBaseData<T> {
+public:
+    static constexpr auto name = "orthogonal_bitmap_expr_calculate";
+
+    static DataTypePtr get_return_type() { return std::make_shared<DataTypeBitMap>(); }
+
+    void merge(const AggOrthBitMapExprCal& rhs) {
+        if (rhs.first_init) {
+            return;
+        }
+        result |= rhs.result;
+    }
+
+    void write(BufferWritable& buf) {
+        write_binary(AggOrthBitmapExprCalBaseData<T>::first_init, buf);
+        result = AggOrthBitmapExprCalBaseData<T>::bitmap_expr_cal.bitmap_calculate();
+        DataTypeBitMap::serialize_as_stream(result, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(AggOrthBitmapExprCalBaseData<T>::first_init, buf);
+        DataTypeBitMap::deserialize_as_stream(result, buf);
+    }
+
+    void get(IColumn& to) const {
+        auto& column = static_cast<ColumnBitmap&>(to);
+        column.get_data().emplace_back(result);
+    }
+
+private:
+    BitmapValue result;
+};
+
+template <typename T>
+struct AggOrthBitMapExprCalCount : public AggOrthBitmapExprCalBaseData<T> {
+public:
+    static constexpr auto name = "orthogonal_bitmap_expr_calculate_count";
+
+    static DataTypePtr get_return_type() { return std::make_shared<DataTypeInt64>(); }
+
+    void merge(const AggOrthBitMapExprCalCount& rhs) {
+        if (rhs.first_init) {
+            return;
+        }
+        result += rhs.result;
+    }
+
+    void write(BufferWritable& buf) {
+        write_binary(AggOrthBitmapExprCalBaseData<T>::first_init, buf);
+        result = AggOrthBitmapExprCalBaseData<T>::bitmap_expr_cal.bitmap_calculate_count();
+        write_binary(result, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(AggOrthBitmapExprCalBaseData<T>::first_init, buf);
+        read_binary(result, buf);
+    }
+
+    void get(IColumn& to) const {
+        auto& column = static_cast<ColumnVector<Int64>&>(to);
+        column.get_data().emplace_back(result);
+    }
+
+private:
+    Int64 result = 0;

Review Comment:
   ```suggestion
       int64_t result = 0;
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1460100086

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: Add the bitmap intersection and difference set for mixed calculation of udaf

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1061109039


##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,240 @@
+// 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 "util/bitmap_intersect.h"
+#include <string>
+#include <stack>
+
+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 '|' said and set, the operator '&' stands for intersection, the operator '-' indicates the difference set
+class BitmapExprCalculation: public BitmapIntersect<std::string> {
+public:
+    BitmapExprCalculation() = default;
+
+    explicit BitmapExprCalculation(const char* src) { deserialize(src); }
+    
+    void bitmap_calculation_init(std::string &inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";

Review Comment:
   warning: redundant string initialization [readability-redundant-string-init]
   
   ```suggestion
           std::string bitmapKey;
   ```
   



##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,240 @@
+// 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 "util/bitmap_intersect.h"
+#include <string>
+#include <stack>
+
+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 '|' said and set, the operator '&' stands for intersection, the operator '-' indicates the difference set
+class BitmapExprCalculation: public BitmapIntersect<std::string> {
+public:
+    BitmapExprCalculation() = default;
+
+    explicit BitmapExprCalculation(const char* src) { deserialize(src); }
+    
+    void bitmap_calculation_init(std::string &inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' &&
+                       c != '^' && c != '-' &&
+                       c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+    
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' &&
+                     c != '^' && c != '-' && 
+                     c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+                
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } else if (!values.empty()) {
+            result |= values.top();
+        }
+        LOG(WARNING) << "bitmap_calculate,"<< "result:" << result.cardinality();
+        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:
+    
+    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 printStack(std::stack<T> stack) {
+        std::string result = "";
+        while (!stack.empty())

Review Comment:
   warning: redundant string initialization [readability-redundant-string-init]
   
   ```suggestion
    result;
   ```
   



##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,240 @@
+// 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 "util/bitmap_intersect.h"
+#include <string>
+#include <stack>
+
+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 '|' said and set, the operator '&' stands for intersection, the operator '-' indicates the difference set
+class BitmapExprCalculation: public BitmapIntersect<std::string> {
+public:
+    BitmapExprCalculation() = default;
+
+    explicit BitmapExprCalculation(const char* src) { deserialize(src); }
+    
+    void bitmap_calculation_init(std::string &inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' &&
+                       c != '^' && c != '-' &&
+                       c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+    
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' &&
+                     c != '^' && c != '-' && 
+                     c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+                
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } else if (!values.empty()) {
+            result |= values.top();
+        }
+        LOG(WARNING) << "bitmap_calculate,"<< "result:" << result.cardinality();
+        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:
+    
+    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 printStack(std::stack<T> stack) {
+        std::string result = "";
+        while (!stack.empty())
+        {
+            result = stack.top()+result;
+            stack.pop();
+        }
+        return result;
+    }
+    
+    std::string reversePolish(std::string inputStr) {
+        std::stack<char> polish;
+        std::stack<char> opStack;
+        bool lastIsChar = false;
+        for (int i = 0; i < inputStr.length(); i++) {
+            char curChar = inputStr.at(i);
+            // 如果是字符串
+            if (curChar != '&' && curChar != '|' &&
+                    curChar != '^' && curChar != '-' &&
+                    curChar != '(' && curChar != ')' &&
+                    curChar != ' ' && curChar != '\t') {
+                if (!lastIsChar)
+                    polish.push(' ');
+                polish.push(curChar);

Review Comment:
   warning: statement should be inside braces [readability-braces-around-statements]
   
   ```suggestion
            if (!lastIsChar) {
           polish.push(' ');
   }
   ```
   



##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,240 @@
+// 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 "util/bitmap_intersect.h"
+#include <string>
+#include <stack>
+
+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 '|' said and set, the operator '&' stands for intersection, the operator '-' indicates the difference set
+class BitmapExprCalculation: public BitmapIntersect<std::string> {
+public:
+    BitmapExprCalculation() = default;
+
+    explicit BitmapExprCalculation(const char* src) { deserialize(src); }
+    
+    void bitmap_calculation_init(std::string &inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' &&
+                       c != '^' && c != '-' &&
+                       c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+    
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' &&
+                     c != '^' && c != '-' && 
+                     c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+                
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } else if (!values.empty()) {
+            result |= values.top();
+        }
+        LOG(WARNING) << "bitmap_calculate,"<< "result:" << result.cardinality();
+        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:
+    
+    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 printStack(std::stack<T> stack) {
+        std::string result = "";
+        while (!stack.empty())
+        {
+            result = stack.top()+result;
+            stack.pop();
+        }
+        return result;
+    }
+    
+    std::string reversePolish(std::string inputStr) {
+        std::stack<char> polish;
+        std::stack<char> opStack;
+        bool lastIsChar = false;
+        for (int i = 0; i < inputStr.length(); i++) {
+            char curChar = inputStr.at(i);
+            // 如果是字符串
+            if (curChar != '&' && curChar != '|' &&
+                    curChar != '^' && curChar != '-' &&
+                    curChar != '(' && curChar != ')' &&
+                    curChar != ' ' && curChar != '\t') {
+                if (!lastIsChar)
+                    polish.push(' ');
+                polish.push(curChar);
+                lastIsChar = true;
+                continue;
+            }
+            // 转义字符
+            else if (i != 0 && inputStr.at(i - 1) == '\\') {
+                polish.push(curChar);
+                lastIsChar = true;
+                continue;   
+            }
+            // 为空格
+            else if (curChar == ' ' || curChar == '\t') {
+                lastIsChar = false;
+                continue;
+            }
+            // 否则为操作符
+            else if (curChar == '(') {
+                opStack.push(curChar);
+            }
+            else if (!opStack.empty() && curChar == ')') {
+                while (!opStack.empty() && opStack.top() != '(')
+                {
+                    polish.push(opStack.top());
+                    opStack.pop();
+                }
+                opStack.pop();
+            } else {
+                if (!opStack.empty() && opStack.top() == '(') {
+                    opStack.push(curChar);
+                } else {
+                    if (!opStack.empty() && priority(curChar) > priority(opStack.top())) {
+                        opStack.push(curChar);
+                    } else {
+                        while (!opStack.empty())
+                        {
+                            if (opStack.top() == '(')
+                                break;
+                            if (priority(curChar) <= priority(opStack.top())) {

Review Comment:
   warning: statement should be inside braces [readability-braces-around-statements]
   
   ```suggestion
   op() == '(') {
   }
   ```
   



##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,240 @@
+// 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 "util/bitmap_intersect.h"
+#include <string>
+#include <stack>
+
+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 '|' said and set, the operator '&' stands for intersection, the operator '-' indicates the difference set
+class BitmapExprCalculation: public BitmapIntersect<std::string> {
+public:
+    BitmapExprCalculation() = default;
+
+    explicit BitmapExprCalculation(const char* src) { deserialize(src); }
+    
+    void bitmap_calculation_init(std::string &inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' &&
+                       c != '^' && c != '-' &&
+                       c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+    
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {

Review Comment:
   warning: redundant string initialization [readability-redundant-string-init]
   
   ```suggestion
   alue> values;
   tmapKey = "";bitmapKey
   ```
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: Add the bitmap intersection and difference set for mixed calculation of udaf

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1061220253


##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,230 @@
+// 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 <string>
+#include <stack>
+
+#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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey = "";
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    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 printStack(std::stack<T> stack) {
+        std::string result = "";
+        while (!stack.empty()) {

Review Comment:
   warning: redundant string initialization [readability-redundant-string-init]
   
   ```suggestion
    result;
   ```
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1370633248

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130636445


##########
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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    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 printStack(std::stack<T> stack) {

Review Comment:
   ```suggestion
       std::string print_stack(const std::stack<T>& stack) {
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] zhbinbin commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "zhbinbin (via GitHub)" <gi...@apache.org>.
zhbinbin commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130847119


##########
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:
   good



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463749111

   run feut


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1465505654

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] zhbinbin commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "zhbinbin (via GitHub)" <gi...@apache.org>.
zhbinbin commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130845533


##########
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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    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 printStack(std::stack<T> stack) {

Review Comment:
   remove const , pop has change



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463301878

   run p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463362316

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1460092356

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1465117327

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130632511


##########
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& inputStr) {

Review Comment:
   ```suggestion
       void bitmap_calculation_init(std::string& input_str) {
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1461440537

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong merged pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong merged PR #15588:
URL: https://github.com/apache/doris/pull/15588


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463382287

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1465609635

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] hello-stephen commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by GitBox <gi...@apache.org>.
hello-stephen commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1371742762

   TeamCity pipeline, clickbench performance test result:
    the sum of best hot time: 36.33 seconds
    load time: 649 seconds
    storage size: 17123449725 Bytes
    https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20230105032640_clickbench_pr_73859.html


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1460096024

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1461192159

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1129228250


##########
be/src/util/bitmap_intersect.h:
##########
@@ -17,9 +17,11 @@
 #pragma once
 #include <parallel_hashmap/phmap.h>
 
+#include <sstream>
+#include <string>
+#include "runtime/string_value.h"

Review Comment:
   warning: 'runtime/string_value.h' file not found [clang-diagnostic-error]
   ```cpp
   #include "runtime/string_value.h"
            ^
   ```
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1129303509


##########
be/src/util/bitmap_intersect.h:
##########
@@ -17,9 +17,11 @@
 #pragma once
 #include <parallel_hashmap/phmap.h>
 
+#include <string>
+

Review Comment:
   warning: 'runtime/string_value.h' file not found [clang-diagnostic-error]
   ```cpp
   #include "runtime/string_value.h"
            ^
   ```
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130630921


##########
be/src/util/bitmap_intersect.h:
##########
@@ -84,7 +84,7 @@ inline char* Helper::write_to<StringRef>(const StringRef& v, char* dest) {
 
 template <>
 inline char* Helper::write_to<std::string>(const std::string& v, char* dest) {
-    *(uint32_t*)dest = v.size();
+    *(int32_t*)dest = v.size();

Review Comment:
   int32 maybe overflow



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1467257209

   run p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1131993652


##########
docs/zh-CN/docs/advanced/orthogonal-bitmap-manual.md:
##########
@@ -161,3 +191,10 @@ orthogonal_bitmap_union_count(bitmap_column)
 ```sql
 select orthogonal_bitmap_union_count(user_id) from user_tag_bitmap where tag in (13080800, 11110200);
 ```
+
+bitmap交并差集合混合计算:
+
+```sql
+select orthogonal_bitmap_expr_calculate_count(user_id, tag, '(A|B)&(C-D)&E') from user_str_tag_bitmap where tag in ('A', 'B', 'C', 'D', 'E');

Review Comment:
   how to deal with tag with "& | -"



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463749262

   run p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] chenlinzhong commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "chenlinzhong (via GitHub)" <gi...@apache.org>.
chenlinzhong commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1463748864

   run beut


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130549789


##########
be/src/util/bitmap_expr_calculation.h:
##########
@@ -0,0 +1,230 @@
+// 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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    // 计算表达式的值
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    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 printStack(std::stack<T> stack) {
+        std::string result;
+        while (!stack.empty()) {
+            result = stack.top() + result;
+            stack.pop();
+        }
+        return result;
+    }
+
+    std::string reversePolish(std::string inputStr) {
+        std::stack<char> polish;
+        std::stack<char> opStack;
+        bool lastIsChar = false;
+        for (int i = 0; i < inputStr.length(); i++) {
+            char curChar = inputStr.at(i);
+            // 如果是字符串
+            if (curChar != '&' && curChar != '|' && curChar != '^' && curChar != '-' &&
+                curChar != '(' && curChar != ')' && curChar != ' ' && curChar != '\t') {
+                if (!lastIsChar) {
+                    polish.push(' ');
+                }
+                polish.push(curChar);
+                lastIsChar = true;
+                continue;
+            }
+            // 转义字符
+            else if (i != 0 && inputStr.at(i - 1) == '\\') {
+                polish.push(curChar);
+                lastIsChar = true;
+                continue;
+            }
+            // 为空格
+            else if (curChar == ' ' || curChar == '\t') {
+                lastIsChar = false;
+                continue;
+            }
+            // 否则为操作符
+            else if (curChar == '(') {
+                opStack.push(curChar);
+            } else if (!opStack.empty() && curChar == ')') {
+                while (!opStack.empty() && opStack.top() != '(') {
+                    polish.push(opStack.top());
+                    opStack.pop();
+                }
+                opStack.pop();
+            } else {
+                if (!opStack.empty() && opStack.top() == '(') {
+                    opStack.push(curChar);
+                } else {
+                    if (!opStack.empty() && priority(curChar) > priority(opStack.top())) {
+                        opStack.push(curChar);
+                    } else {
+                        while (!opStack.empty()) {
+                            if (opStack.top() == '(') {
+                                break;
+                            }
+                            if (priority(curChar) <= priority(opStack.top())) {
+                                polish.push(opStack.top());
+                                opStack.pop();
+                            } else {
+                                break;
+                            }
+                        }
+                        opStack.push(curChar);
+                    }
+                }
+            }
+            lastIsChar = false;
+        }
+
+        while (!opStack.empty()) {
+            polish.push(opStack.top());
+            opStack.pop();
+        }
+        return printStack(polish);
+    }
+
+    // bitmap交并差运算 因为数据是放在堆栈中 所以前一个操作数是opB 后一个操作数是opA

Review Comment:
   translate to en



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] github-actions[bot] commented on pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15588:
URL: https://github.com/apache/doris/pull/15588#issuecomment-1461448193

   clang-tidy review says "All clean, LGTM! :+1:"


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [doris] yangzhg commented on a diff in pull request #15588: [Feature](add bitmap udaf) add the bitmap intersection and difference set for mixed calculation of udaf

Posted by "yangzhg (via GitHub)" <gi...@apache.org>.
yangzhg commented on code in PR #15588:
URL: https://github.com/apache/doris/pull/15588#discussion_r1130639916


##########
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& inputStr) {
+        _polish = reversePolish(inputStr);
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c != '&' && c != '|' && c != '^' && c != '-' && c != ' ' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    add_key(bitmapKey);
+                    bitmapKey.clear();
+                }
+            }
+        }
+        if (bitmapKey.length() > 0) {
+            add_key(bitmapKey);
+            bitmapKey.clear();
+        }
+    }
+
+    BitmapValue bitmap_calculate() {
+        std::stack<BitmapValue> values;
+        std::string bitmapKey;
+        for (int i = 0; i < _polish.length(); i++) {
+            char c = _polish.at(i);
+            if (c == ' ') {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+            } else if (c != '&' && c != '|' && c != '^' && c != '-' && c != '\\') {
+                bitmapKey += c;
+            } else if (i != 0 && _polish.at(i - 1) == '\\') {
+                bitmapKey += c;
+            } else if (c == '\\') {
+                continue;
+            } else {
+                if (bitmapKey.length() > 0) {
+                    values.push(_bitmaps[bitmapKey]);
+                    bitmapKey.clear();
+                }
+                if (values.size() >= 2) {
+                    BitmapValue opA = values.top();
+                    values.pop();
+                    BitmapValue opB = values.top();
+                    values.pop();
+                    BitmapValue calResult;
+                    bitmapCalculate(opA, opB, c, calResult);
+                    values.push(calResult);
+                }
+            }
+        }
+        BitmapValue result;
+        if (bitmapKey.length() > 0) {
+            result |= _bitmaps[bitmapKey];
+        } 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:
+    int priority(char c) {

Review Comment:
   ```suggestion
       constexpr int priority(char c) {
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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