You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/04/08 01:20:32 UTC

[incubator-doris] branch master updated: [feature](vectorized) support vexplode_bitmap (#8890)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new dbbc6549bd [feature](vectorized) support vexplode_bitmap (#8890)
dbbc6549bd is described below

commit dbbc6549bd12e597bc879e730a18a24315f6fe71
Author: Pxl <95...@qq.com>
AuthorDate: Fri Apr 8 09:20:26 2022 +0800

    [feature](vectorized) support vexplode_bitmap (#8890)
---
 be/src/exprs/table_function/explode_bitmap.h       |  5 +-
 .../table_function/table_function_factory.cpp      | 13 ++--
 be/src/vec/CMakeLists.txt                          |  1 +
 .../vec/exprs/table_function/vexplode_bitmap.cpp   | 81 ++++++++++++++++++++++
 .../table_function/vexplode_bitmap.h}              | 27 +++++---
 be/src/vec/functions/function_fake.cpp             |  1 +
 be/src/vec/functions/function_fake.h               |  8 +++
 7 files changed, 120 insertions(+), 16 deletions(-)

diff --git a/be/src/exprs/table_function/explode_bitmap.h b/be/src/exprs/table_function/explode_bitmap.h
index 2abb1603e0..c75559d023 100644
--- a/be/src/exprs/table_function/explode_bitmap.h
+++ b/be/src/exprs/table_function/explode_bitmap.h
@@ -33,13 +33,12 @@ public:
 
     virtual Status forward(bool* eos) override;
 
-private:
+protected:
     void _reset_iterator();
 
-private:
     // Read from tuple row.
     // if _cur_bitmap_owned is true, need to delete it when deconstruction
-    BitmapValue* _cur_bitmap = nullptr;
+    const BitmapValue* _cur_bitmap = nullptr;
     bool _cur_bitmap_owned = false;
     // iterator of _cur_bitmap
     BitmapValueIterator* _cur_iter = nullptr;
diff --git a/be/src/exprs/table_function/table_function_factory.cpp b/be/src/exprs/table_function/table_function_factory.cpp
index c347d245eb..7dcce8c9c5 100644
--- a/be/src/exprs/table_function/table_function_factory.cpp
+++ b/be/src/exprs/table_function/table_function_factory.cpp
@@ -22,9 +22,10 @@
 #include "exprs/table_function/explode_json_array.h"
 #include "exprs/table_function/explode_split.h"
 #include "exprs/table_function/table_function.h"
+#include "vec/exprs/table_function/vexplode_bitmap.h"
+#include "vec/exprs/table_function/vexplode_json_array.h"
 #include "vec/exprs/table_function/vexplode_numbers.h"
 #include "vec/exprs/table_function/vexplode_split.h"
-#include "vec/exprs/table_function/vexplode_json_array.h"
 
 namespace doris {
 
@@ -36,13 +37,15 @@ struct TableFunctionCreator {
 template <>
 struct TableFunctionCreator<ExplodeJsonArrayTableFunction> {
     ExplodeJsonArrayType type;
-    TableFunction* operator()() { return new ExplodeJsonArrayTableFunction(type); }
+    TableFunction* operator()() const { return new ExplodeJsonArrayTableFunction(type); }
 };
 
 template <>
 struct TableFunctionCreator<vectorized::VExplodeJsonArrayTableFunction> {
     ExplodeJsonArrayType type;
-    TableFunction* operator()() { return new vectorized::VExplodeJsonArrayTableFunction(type); }
+    TableFunction* operator()() const {
+        return new vectorized::VExplodeJsonArrayTableFunction(type);
+    }
 };
 
 inline auto ExplodeJsonArrayIntCreator =
@@ -76,7 +79,9 @@ const std::unordered_map<std::pair<std::string, bool>, std::function<TableFuncti
                  TableFunctionCreator<vectorized::VExplodeNumbersTableFunction>()},
                 {{"explode_json_array_int", true}, VExplodeJsonArrayIntCreator},
                 {{"explode_json_array_double", true}, VExplodeJsonArrayDoubleCreator},
-                {{"explode_json_array_string", true}, VExplodeJsonArrayStringCreator}};
+                {{"explode_json_array_string", true}, VExplodeJsonArrayStringCreator},
+                {{"explode_bitmap", true},
+                 TableFunctionCreator<vectorized::VExplodeBitmapTableFunction>()}};
 
 Status TableFunctionFactory::get_fn(const std::string& fn_name, bool is_vectorized,
                                     ObjectPool* pool, TableFunction** fn) {
diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt
index d51cd8baf3..886de1326d 100644
--- a/be/src/vec/CMakeLists.txt
+++ b/be/src/vec/CMakeLists.txt
@@ -113,6 +113,7 @@ set(VEC_FILES
   exprs/vinfo_func.cpp
   exprs/table_function/vexplode_split.cpp
   exprs/table_function/vexplode_numbers.cpp
+  exprs/table_function/vexplode_bitmap.cpp
   functions/array/function_array_index.cpp
   functions/array/function_array_element.cpp
   functions/array/function_array_register.cpp
diff --git a/be/src/vec/exprs/table_function/vexplode_bitmap.cpp b/be/src/vec/exprs/table_function/vexplode_bitmap.cpp
new file mode 100644
index 0000000000..0dec849980
--- /dev/null
+++ b/be/src/vec/exprs/table_function/vexplode_bitmap.cpp
@@ -0,0 +1,81 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "vec/exprs/table_function/vexplode_bitmap.h"
+
+#include "util/bitmap_value.h"
+#include "vec/exprs/vexpr.h"
+
+namespace doris::vectorized {
+
+VExplodeBitmapTableFunction::VExplodeBitmapTableFunction() {
+    _fn_name = "vexplode_bitmap";
+}
+
+Status VExplodeBitmapTableFunction::process_init(vectorized::Block* block) {
+    CHECK(_vexpr_context->root()->children().size() == 1)
+            << "VExplodeNumbersTableFunction must be have 1 children but have "
+            << _vexpr_context->root()->children().size();
+
+    int value_column_idx = -1;
+    _vexpr_context->root()->children()[0]->execute(_vexpr_context, block, &value_column_idx);
+    _value_column = block->get_by_position(value_column_idx).column;
+
+    return Status::OK();
+}
+
+Status VExplodeBitmapTableFunction::process_row(size_t row_idx) {
+    _eos = false;
+    _is_current_empty = false;
+    _cur_size = 0;
+    _cur_offset = 0;
+
+    StringRef value = _value_column->get_data_at(row_idx);
+
+    if (value.data == nullptr) {
+        _is_current_empty = true;
+    } else {
+        _cur_bitmap = reinterpret_cast<const BitmapValue*>(value.data);
+        _cur_bitmap_owned = false;
+
+        _cur_size = _cur_bitmap->cardinality();
+        if (_cur_size == 0) {
+            _is_current_empty = true;
+        } else {
+            _reset_iterator();
+        }
+    }
+
+    _is_current_empty = (_cur_size == 0);
+    return Status::OK();
+}
+
+Status VExplodeBitmapTableFunction::process_close() {
+    _value_column = nullptr;
+    return Status::OK();
+}
+
+Status VExplodeBitmapTableFunction::get_value_length(int64_t* length) {
+    if (_is_current_empty) {
+        *length = -1;
+    } else {
+        *length = sizeof(uint64_t);
+    }
+    return Status::OK();
+}
+
+} // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_fake.cpp b/be/src/vec/exprs/table_function/vexplode_bitmap.h
similarity index 60%
copy from be/src/vec/functions/function_fake.cpp
copy to be/src/vec/exprs/table_function/vexplode_bitmap.h
index eb6e875980..5e46ab20c8 100644
--- a/be/src/vec/functions/function_fake.cpp
+++ b/be/src/vec/exprs/table_function/vexplode_bitmap.h
@@ -15,17 +15,26 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "vec/functions/function_fake.h"
+#pragma once
+
+#include "exprs/table_function/explode_bitmap.h"
+#include "exprs/table_function/table_function.h"
+#include "util/bitmap_value.h"
+#include "vec/columns/column.h"
 
 namespace doris::vectorized {
 
-void register_function_fake(SimpleFunctionFactory& factory) {
-    factory.register_function<FunctionFake<FunctionEsqueryImpl>>();
-    factory.register_function<FunctionFake<FunctionExplodeSplitImpl>>();
-    factory.register_function<FunctionFake<FunctionExplodeNumbersImpl>>();
-    factory.register_function<FunctionFake<FunctionExplodeJsonArrayDoubleImpl>>();
-    factory.register_function<FunctionFake<FunctionExplodeJsonArrayIntImpl>>();
-    factory.register_function<FunctionFake<FunctionExplodeJsonArrayStringImpl>>();
-}
+class VExplodeBitmapTableFunction : public ExplodeBitmapTableFunction {
+public:
+    VExplodeBitmapTableFunction();
+
+    Status process_init(vectorized::Block* block) override;
+    Status process_row(size_t row_idx) override;
+    Status process_close() override;
+    Status get_value_length(int64_t* length) override;
+
+private:
+    ColumnPtr _value_column;
+};
 
 } // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_fake.cpp b/be/src/vec/functions/function_fake.cpp
index eb6e875980..9deacb2afa 100644
--- a/be/src/vec/functions/function_fake.cpp
+++ b/be/src/vec/functions/function_fake.cpp
@@ -26,6 +26,7 @@ void register_function_fake(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionFake<FunctionExplodeJsonArrayDoubleImpl>>();
     factory.register_function<FunctionFake<FunctionExplodeJsonArrayIntImpl>>();
     factory.register_function<FunctionFake<FunctionExplodeJsonArrayStringImpl>>();
+    factory.register_function<FunctionFake<FunctionExplodeBitmapImpl>>();
 }
 
 } // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_fake.h b/be/src/vec/functions/function_fake.h
index 6e70eb8343..c7e536d6ea 100644
--- a/be/src/vec/functions/function_fake.h
+++ b/be/src/vec/functions/function_fake.h
@@ -67,6 +67,14 @@ struct FunctionExplodeJsonArrayDoubleImpl {
         return std::make_shared<DataTypeFloat64>();
     }
 };
+
+struct FunctionExplodeBitmapImpl {
+    static constexpr auto name = "explode_bitmap";
+    static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
+        return std::make_shared<DataTypeInt64>();
+    }
+};
+
 //FunctionFake is use for some function call expr only work at prepare/open phase, do not support execute().
 template <typename Impl>
 class FunctionFake : public IFunction {


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