Skip to content

Commit

Permalink
[Function] Support function bitmap_min on vectorized engine (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel39 authored Oct 9, 2021
1 parent 70ca6e1 commit 11cc743
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
24 changes: 24 additions & 0 deletions be/src/vec/functions/function_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,35 @@ struct BitmapHasAny {
}
};

struct NameBitmapMin {
static constexpr auto name = "bitmap_min";
};

struct BitmapMin {
using ReturnType = DataTypeInt64;
static constexpr auto TYPE_INDEX = TypeIndex::BitMap;
using Type = DataTypeBitMap::FieldType;
using ReturnColumnType = ColumnVector<Int64>;
using ReturnColumnContainer = ColumnVector<Int64>::Container;

static Status vector(const std::vector<BitmapValue>& data, ReturnColumnContainer& res) {
int size = data.size();
res.reserve(size);
for (int i = 0; i < size; ++i) {
auto min = const_cast<std::vector<BitmapValue>&>(data)[i].minimum();
res.push_back(min.val);
}
return Status::OK();
}
};

using FunctionBitmapEmpty = FunctionConst<BitmapEmpty, false>;
using FunctionToBitmap = FunctionUnaryToType<ToBitmapImpl, NameToBitmap>;
using FunctionBitmapFromString = FunctionUnaryToType<BitmapFromString,NameBitmapFromString>;
using FunctionBitmapHash = FunctionUnaryToType<BitmapHash, NameBitmapHash>;

using FunctionBitmapCount = FunctionUnaryToType<BitmapCount, NameBitmapCount>;
using FunctionBitmapMin = FunctionUnaryToType<BitmapMin, NameBitmapMin>;

using FunctionBitmapAnd =
FunctionBinaryToType<DataTypeBitMap, DataTypeBitMap, BitmapAnd, NameBitmapAnd>;
Expand All @@ -301,6 +324,7 @@ void register_function_bitmap(SimpleFunctionFactory& factory) {
factory.register_function<FunctionBitmapFromString>();
factory.register_function<FunctionBitmapHash>();
factory.register_function<FunctionBitmapCount>();
factory.register_function<FunctionBitmapMin>();
factory.register_function<FunctionBitmapAnd>();
factory.register_function<FunctionBitmapOr>();
factory.register_function<FunctionBitmapXor>();
Expand Down
3 changes: 2 additions & 1 deletion be/test/vec/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/test/vec/function")

ADD_BE_TEST(function_abs_test)
ADD_BE_TEST(function_bitmap_test)
ADD_BE_TEST(function_comparison_test)
ADD_BE_TEST(function_math_test)
ADD_BE_TEST(function_string_test)
ADD_BE_TEST(function_time_test)
ADD_BE_TEST(function_math_test)
51 changes: 51 additions & 0 deletions be/test/vec/function/function_bitmap_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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/functions/function_totype.h"

#include <gtest/gtest.h>

#include "util/bitmap_value.h"
#include "function_test_util.h"

namespace doris {

using vectorized::Null;
using vectorized::DataSet;
using vectorized::TypeIndex;

TEST(function_bitmap_test, function_bitmap_min_test) {
std::string func_name = "bitmap_min";
std::vector<std::any> input_types = {TypeIndex::BitMap};

auto bitmap1 = new BitmapValue(1);
auto bitmap2 = new BitmapValue(std::vector<uint64_t>({1, 9999999}));
auto empty_bitmap = new BitmapValue();
DataSet data_set = {
{{bitmap1}, (int64_t) 1},
{{bitmap2}, (int64_t) 1},
{{empty_bitmap}, (int64_t) 0},
{{Null()}, Null()}};

vectorized::check_function<vectorized::DataTypeInt64, true>(func_name, input_types, data_set);
}

} // namespace doris

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
16 changes: 16 additions & 0 deletions be/test/vec/function/function_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "exec/schema_scanner.h"
#include "runtime/row_batch.h"
#include "runtime/tuple_row.h"
#include "util/bitmap_value.h"
#include "vec/columns/column_complex.h"
#include "vec/functions/function_string.h"
#include "vec/functions/function_string_to_string.h"
#include "vec/functions/simple_function_factory.h"
Expand Down Expand Up @@ -103,6 +105,20 @@ void check_function(const std::string& func_name, const std::vector<std::any>& i
insert_column_to_block<DataTypeString>(columns, ctn, std::move(col),
std::move(null_map), block, col_name, i,
is_const, row_size);
} else if (tp == TypeIndex::BitMap) {
auto col = ColumnBitmap::create();
for (int j = 0; j < row_size; j++) {
if (data_set[j].first[i].type() == typeid(Null)) {
null_map_data[j] = true;
col->insert_default();
continue;
}
BitmapValue* bitmap = std::any_cast<BitmapValue*>(data_set[j].first[i]);
col->insert_value(*bitmap);
}
insert_column_to_block<DataTypeBitMap>(columns, ctn, std::move(col),
std::move(null_map), block, col_name, i,
is_const, row_size);
} else if (tp == TypeIndex::Int32) {
auto col = ColumnInt32::create();

Expand Down

0 comments on commit 11cc743

Please sign in to comment.