Skip to content

Commit

Permalink
refactor ut of bitmap not new object
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Apr 28, 2022
1 parent f3ce1fc commit 31dee43
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 99 deletions.
34 changes: 17 additions & 17 deletions be/src/vec/aggregate_functions/aggregate_function_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ AggregateFunctionPtr create_aggregate_function_row_number(const std::string& nam
}

template <template <typename> class AggregateFunctionTemplate, template <typename> class Data,
bool is_nullable, bool is_copy = false>
bool arg_is_nullable, bool is_copy = false>
static IAggregateFunction* create_function_single_value(const String& name,
const DataTypes& argument_types,
const Array& parameters) {
Expand All @@ -71,64 +71,64 @@ static IAggregateFunction* create_function_single_value(const String& name,
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return new AggregateFunctionTemplate< \
Data<LeadAndLagData<TYPE, is_nullable, false, StoreType>>>(argument_types);
Data<LeadAndLagData<TYPE, arg_is_nullable, false, StoreType>>>(argument_types);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH

if (which.is_decimal()) {
return new AggregateFunctionTemplate<
Data<LeadAndLagData<Int128, is_nullable, false, StoreType>>>(argument_types);
Data<LeadAndLagData<Int128, arg_is_nullable, false, StoreType>>>(argument_types);
}
if (which.is_date_or_datetime()) {
return new AggregateFunctionTemplate<
Data<LeadAndLagData<Int64, is_nullable, false, StoreType>>>(argument_types);
Data<LeadAndLagData<Int64, arg_is_nullable, false, StoreType>>>(argument_types);
}
if (which.is_string_or_fixed_string()) {
return new AggregateFunctionTemplate<
Data<LeadAndLagData<StringRef, is_nullable, true, StoreType>>>(argument_types);
Data<LeadAndLagData<StringRef, arg_is_nullable, true, StoreType>>>(argument_types);
}
DCHECK(false) << "with unknowed type, failed in create_aggregate_function_leadlag";
return nullptr;
}

template <bool is_nullable>
template <bool arg_is_nullable>
AggregateFunctionPtr create_aggregate_function_lag(const std::string& name,
const DataTypes& argument_types,
const Array& parameters,
const bool result_is_nullable) {
return AggregateFunctionPtr(
create_function_single_value<WindowFunctionData, WindowFunctionLagData, is_nullable>(
name, argument_types, parameters));
create_function_single_value<WindowFunctionData, WindowFunctionLagData,
arg_is_nullable>(name, argument_types, parameters));
}

template <bool is_nullable>
template <bool arg_is_nullable>
AggregateFunctionPtr create_aggregate_function_lead(const std::string& name,
const DataTypes& argument_types,
const Array& parameters,
const bool result_is_nullable) {
return AggregateFunctionPtr(
create_function_single_value<WindowFunctionData, WindowFunctionLeadData, is_nullable>(
name, argument_types, parameters));
create_function_single_value<WindowFunctionData, WindowFunctionLeadData,
arg_is_nullable>(name, argument_types, parameters));
}

template <bool is_nullable>
template <bool arg_is_nullable>
AggregateFunctionPtr create_aggregate_function_first(const std::string& name,
const DataTypes& argument_types,
const Array& parameters,
const bool result_is_nullable) {
return AggregateFunctionPtr(
create_function_single_value<WindowFunctionData, WindowFunctionFirstData, is_nullable>(
name, argument_types, parameters));
create_function_single_value<WindowFunctionData, WindowFunctionFirstData,
arg_is_nullable>(name, argument_types, parameters));
}

template <bool is_nullable>
template <bool arg_is_nullable>
AggregateFunctionPtr create_aggregate_function_last(const std::string& name,
const DataTypes& argument_types,
const Array& parameters,
const bool result_is_nullable) {
return AggregateFunctionPtr(
create_function_single_value<WindowFunctionData, WindowFunctionLastData, is_nullable>(
name, argument_types, parameters));
create_function_single_value<WindowFunctionData, WindowFunctionLastData,
arg_is_nullable>(name, argument_types, parameters));
}

AggregateFunctionPtr create_aggregate_function_replace_if_not_null(const std::string& name,
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/aggregate_functions/aggregate_function_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct CopiedValue : public Value {
std::string _copied_value;
};

template <typename T, bool is_nullable, bool is_string, typename StoreType = Value>
template <typename T, bool arg_is_nullable, bool is_string, typename StoreType = Value>
struct LeadAndLagData {
public:
bool has_init() const { return _is_init; }
Expand All @@ -193,7 +193,7 @@ struct LeadAndLagData {
}

void insert_result_into(IColumn& to) const {
if constexpr (is_nullable) {
if constexpr (arg_is_nullable) {
if (_data_value.is_null()) {
auto& col = assert_cast<ColumnNullable&>(to);
col.insert_default();
Expand Down
135 changes: 55 additions & 80 deletions be/test/vec/function/function_bitmap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,157 +26,135 @@ TEST(function_bitmap_test, function_bitmap_min_test) {
std::string func_name = "bitmap_min";
InputTypeSet 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}, Null()},
BitmapValue bitmap1(1);
BitmapValue bitmap2({1, 9999999});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1}, (int64_t)1},
{{&bitmap2}, (int64_t)1},
{{&empty_bitmap}, Null()},
{{Null()}, Null()}};

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete empty_bitmap;
}
TEST(function_bitmap_test, function_bitmap_max_test) {
std::string func_name = "bitmap_max";
InputTypeSet 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)9999999},
{{empty_bitmap}, Null()},
BitmapValue bitmap1(1);
BitmapValue bitmap2({1, 9999999});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1}, (int64_t)1},
{{&bitmap2}, (int64_t)9999999},
{{&empty_bitmap}, Null()},
{{Null()}, Null()}};

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete empty_bitmap;
}

TEST(function_bitmap_test, function_bitmap_to_string_test) {
std::string func_name = "bitmap_to_string";
InputTypeSet 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}, std::string("1")},
{{bitmap2}, std::string("1,9999999")},
{{empty_bitmap}, std::string("")},
BitmapValue bitmap1(1);
BitmapValue bitmap2({1, 9999999});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1}, std::string("1")},
{{&bitmap2}, std::string("1,9999999")},
{{&empty_bitmap}, std::string("")},
{{Null()}, Null()}};

check_function<DataTypeString, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete empty_bitmap;
}

TEST(function_bitmap_test, function_bitmap_and_count) {
std::string func_name = "bitmap_and_count";
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap};
auto bitmap1 = new BitmapValue(std::vector<uint64_t>({1, 2, 3}));
auto bitmap2 = new BitmapValue(std::vector<uint64_t>({3, 4, 5}));
auto empty_bitmap = new BitmapValue();
DataSet data_set = {{{bitmap1, empty_bitmap}, (int64_t)0},
{{bitmap1, bitmap1}, (int64_t)3},
{{bitmap1, bitmap2}, (int64_t)1}};
BitmapValue bitmap1({1, 2, 3});
BitmapValue bitmap2({3, 4, 5});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)0},
{{&bitmap1, &bitmap1}, (int64_t)3},
{{&bitmap1, &bitmap2}, (int64_t)1}};

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete empty_bitmap;

{
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap, TypeIndex::BitMap};
BitmapValue bitmap1({33, 1, 2019});
BitmapValue bitmap2({0, 33, std::numeric_limits<uint64_t>::min()});
BitmapValue bitmap3({33, 5, std::numeric_limits<uint64_t>::max()});
auto empty_bitmap = new BitmapValue(); //test empty
BitmapValue empty_bitmap; //test empty

DataSet data_set = {{{&bitmap1, &bitmap2, empty_bitmap}, (int64_t)0},
DataSet data_set = {{{&bitmap1, &bitmap2, &empty_bitmap}, (int64_t)0},
{{&bitmap1, &bitmap2, &bitmap3}, (int64_t)1}, //33
{{&bitmap1, &bitmap2, Null()}, Null()},
{{&bitmap1, &bitmap3, &bitmap3}, (int64_t)1}}; //33

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete empty_bitmap;
}
}

TEST(function_bitmap_test, function_bitmap_or_count) {
std::string func_name = "bitmap_or_count";
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap};
auto bitmap1 = new BitmapValue(std::vector<uint64_t>({1, 2, 3}));
auto bitmap2 = new BitmapValue(std::vector<uint64_t>({1, 2, 3, 4}));
auto bitmap3 = new BitmapValue(std::vector<uint64_t>({2, 3}));
auto empty_bitmap = new BitmapValue();
DataSet data_set = {{{bitmap1, empty_bitmap}, (int64_t)3},
{{bitmap2, bitmap3}, (int64_t)4},
{{bitmap1, bitmap3}, (int64_t)3}};

BitmapValue bitmap1({1, 2, 3});
BitmapValue bitmap2({1, 2, 3, 4});
BitmapValue bitmap3({2, 3});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)3},
{{&bitmap2, &bitmap3}, (int64_t)4},
{{&bitmap1, &bitmap3}, (int64_t)3}};

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete bitmap3;
delete empty_bitmap;

{
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap, TypeIndex::BitMap};
BitmapValue bitmap1({1024, 1, 2019});
BitmapValue bitmap2({0, 33, std::numeric_limits<uint64_t>::min()});
BitmapValue bitmap3({33, 5, std::numeric_limits<uint64_t>::max()}); //18446744073709551615
auto empty_bitmap = new BitmapValue(); //test empty
BitmapValue empty_bitmap; //test empty

DataSet data_set = {{{&bitmap1, &bitmap2, empty_bitmap}, (int64_t)5}, //0,1,33,1024,2019
DataSet data_set = {{{&bitmap1, &bitmap2, &empty_bitmap}, (int64_t)5}, //0,1,33,1024,2019
{{&bitmap1, &bitmap2, &bitmap3},
(int64_t)7}, //0,1,5,33,1024,2019,18446744073709551615
{{&bitmap1, empty_bitmap, Null()}, Null()},
{{&bitmap1, &empty_bitmap, Null()}, Null()},
{{&bitmap1, &bitmap3, &bitmap3},
(int64_t)6}}; //1,5,33,1024,2019,18446744073709551615

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete empty_bitmap;
}
}

TEST(function_bitmap_test, function_bitmap_xor_count) {
std::string func_name = "bitmap_xor_count";
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap};
auto bitmap1 = new BitmapValue(std::vector<uint64_t>({1, 2, 3}));
auto bitmap2 = new BitmapValue(std::vector<uint64_t>({1, 2, 3, 4}));
auto bitmap3 = new BitmapValue(std::vector<uint64_t>({2, 3}));
auto bitmap4 = new BitmapValue(std::vector<uint64_t>({1, 2, 6}));
auto empty_bitmap = new BitmapValue();
DataSet data_set = {{{bitmap1, empty_bitmap}, (int64_t)3},
{{bitmap2, bitmap3}, (int64_t)2},
{{bitmap1, bitmap4}, (int64_t)2}};

BitmapValue bitmap1({1, 2, 3});
BitmapValue bitmap2({1, 2, 3, 4});
BitmapValue bitmap3({2, 3});
BitmapValue bitmap4({1, 2, 6});
BitmapValue empty_bitmap;
DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)3},
{{&bitmap2, &bitmap3}, (int64_t)2},
{{&bitmap1, &bitmap4}, (int64_t)2}};

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete bitmap1;
delete bitmap2;
delete bitmap3;
delete bitmap4;
delete empty_bitmap;

{
InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap, TypeIndex::BitMap};
BitmapValue bitmap1({1024, 1, 2019});
BitmapValue bitmap2({0, 33, std::numeric_limits<uint64_t>::min()});
BitmapValue bitmap3({33, 5, std::numeric_limits<uint64_t>::max()});
auto empty_bitmap = new BitmapValue(); //test empty
BitmapValue empty_bitmap; //test empty

DataSet data_set = {
{{&bitmap1, &bitmap2, empty_bitmap}, (int64_t)5}, //0,1,33,1024,2019
{{&bitmap1, &bitmap2, &empty_bitmap}, (int64_t)5}, //0,1,33,1024,2019
{{&bitmap1, &bitmap2, &bitmap3}, (int64_t)6}, //0,1,5,1024,2019,18446744073709551615
{{&bitmap1, empty_bitmap, Null()}, Null()},
{{&bitmap1, &empty_bitmap, Null()}, Null()},
{{&bitmap1, &bitmap3, &bitmap3}, (int64_t)3}}; //1,1024,2019

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete empty_bitmap;
}
}

Expand All @@ -186,15 +164,14 @@ TEST(function_bitmap_test, function_bitmap_and_not_count) {
BitmapValue bitmap1({1, 2, 3});
BitmapValue bitmap2({3, 4, std::numeric_limits<uint64_t>::min()});
BitmapValue bitmap3({33, 5, std::numeric_limits<uint64_t>::max()});
auto empty_bitmap = new BitmapValue();
BitmapValue empty_bitmap;

DataSet data_set = {{{&bitmap1, empty_bitmap}, (int64_t)3}, //1,2,3
DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)3}, //1,2,3
{{&bitmap2, Null()}, Null()},
{{&bitmap2, &bitmap3}, (int64_t)3}, //0,3,4
{{&bitmap1, &bitmap2}, (int64_t)2}}; //1,2

check_function<DataTypeInt64, true>(func_name, input_types, data_set);
delete empty_bitmap;
}
TEST(function_bitmap_test, function_bitmap_has_all) {
std::string func_name = "bitmap_has_all";
Expand All @@ -207,18 +184,16 @@ TEST(function_bitmap_test, function_bitmap_has_all) {
BitmapValue bitmap3 = BitmapValue({0, 1, 2});
BitmapValue bitmap4 = BitmapValue({0, 1, 2, std::numeric_limits<uint64_t>::max()});
BitmapValue bitmap5 = BitmapValue({0, 1, 2});
auto empty_bitmap1 = new BitmapValue();
auto empty_bitmap2 = new BitmapValue();
BitmapValue empty_bitmap1;
BitmapValue empty_bitmap2;

DataSet data_set = {{{&bitmap1, &bitmap2}, uint8(true)},
{{empty_bitmap1, empty_bitmap2}, uint8(true)},
{{&empty_bitmap1, &empty_bitmap2}, uint8(true)},
{{&bitmap3, &bitmap4}, uint8(false)},
{{&bitmap4, &bitmap5}, uint8(true)},
{{Null(), empty_bitmap1}, Null()}};
{{Null(), &empty_bitmap1}, Null()}};

check_function<DataTypeUInt8, true>(func_name, input_types, data_set);
delete empty_bitmap1;
delete empty_bitmap2;
}

} // namespace doris::vectorized

0 comments on commit 31dee43

Please sign in to comment.