From dfa2528b5e100a82d1cf90a03534f4ef3ba75af1 Mon Sep 17 00:00:00 2001 From: TengJianPing <18241664+jacktengg@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:49:58 +0800 Subject: [PATCH] [fix](bitmap) fix wrong result of bitmap count functions for null values (#17849) bitmap count functions result is null when there are null values, which is not right: --- be/src/vec/functions/function.cpp | 8 - be/src/vec/functions/function.h | 8 + be/src/vec/functions/function_bitmap.cpp | 153 +++++++++- .../functions/function_bitmap_variadic.cpp | 37 ++- be/test/vec/function/function_bitmap_test.cpp | 6 +- .../bitmap_functions/test_bitmap_function.out | 105 ++++++- .../test_bitmap_function_nereids.out | 251 --------------- .../bitmap_functions/test_bitmap_function.out | 105 ++++++- .../test_bitmap_function.groovy | 288 +++++++++++++++--- .../test_bitmap_function_nereids.groovy | 195 ------------ .../test_bitmap_function.groovy | 285 ++++++++++++++--- 11 files changed, 859 insertions(+), 582 deletions(-) delete mode 100644 regression-test/data/nereids_syntax_p0/test_bitmap_function_nereids.out delete mode 100644 regression-test/suites/nereids_syntax_p0/test_bitmap_function_nereids.groovy diff --git a/be/src/vec/functions/function.cpp b/be/src/vec/functions/function.cpp index cdeff0678a..7acc9560cb 100644 --- a/be/src/vec/functions/function.cpp +++ b/be/src/vec/functions/function.cpp @@ -97,13 +97,6 @@ ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& block, const Colum result_null_map_column); } -namespace { - -struct NullPresence { - bool has_nullable = false; - bool has_null_constant = false; -}; - NullPresence get_null_presence(const Block& block, const ColumnNumbers& args) { NullPresence res; @@ -136,7 +129,6 @@ bool all_arguments_are_constant(const Block& block, const ColumnNumbers& args) { } return true; } -} // namespace inline Status PreparedFunctionImpl::_execute_skipped_constant_deal( FunctionContext* context, Block& block, const ColumnNumbers& args, size_t result, diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h index 5af021656d..1abccd13be 100644 --- a/be/src/vec/functions/function.h +++ b/be/src/vec/functions/function.h @@ -47,6 +47,14 @@ template auto has_variadic_argument_types(T&& arg) -> decltype(T::get_variadic_argument_types()) {}; void has_variadic_argument_types(...); +struct NullPresence { + bool has_nullable = false; + bool has_null_constant = false; +}; + +NullPresence get_null_presence(const Block& block, const ColumnNumbers& args); +[[maybe_unused]] NullPresence get_null_presence(const ColumnsWithTypeAndName& args); + /// The simplest executable object. /// Motivation: /// * Prepare something heavy once before main execution loop instead of doing it for each block. diff --git a/be/src/vec/functions/function_bitmap.cpp b/be/src/vec/functions/function_bitmap.cpp index 6cb254fe3b..01991f1b2f 100644 --- a/be/src/vec/functions/function_bitmap.cpp +++ b/be/src/vec/functions/function_bitmap.cpp @@ -489,9 +489,9 @@ struct BitmapAndNotCount { using T0 = typename LeftDataType::FieldType; using T1 = typename RightDataType::FieldType; using TData = std::vector; - using ResTData = typename ColumnVector::Container; + using ResTData = typename ColumnVector::Container::value_type; - static Status vector_vector(const TData& lvec, const TData& rvec, ResTData& res) { + static Status vector_vector(const TData& lvec, const TData& rvec, ResTData* res) { size_t size = lvec.size(); BitmapValue mid_data; for (size_t i = 0; i < size; ++i) { @@ -504,6 +504,153 @@ struct BitmapAndNotCount { } }; +void update_bitmap_op_count(int64_t* __restrict count, const NullMap& null_map) { + static constexpr int64_t flags[2] = {-1, 0}; + size_t size = null_map.size(); + auto* __restrict null_map_data = null_map.data(); + for (size_t i = 0; i < size; ++i) { + count[i] &= flags[null_map_data[i]]; + } +} + +// for bitmap_and_count, bitmap_xor_count and bitmap_and_not_count, +// result is 0 for rows that if any column is null value +ColumnPtr handle_bitmap_op_count_null_value(ColumnPtr& src, const Block& block, + const ColumnNumbers& args, size_t result, + size_t input_rows_count) { + auto* nullable = assert_cast(src.get()); + ColumnPtr src_not_nullable = nullable->get_nested_column_ptr(); + MutableColumnPtr src_not_nullable_mutable = (*std::move(src_not_nullable)).assume_mutable(); + auto* __restrict count_data = + assert_cast(src_not_nullable_mutable.get())->get_data().data(); + + for (const auto& arg : args) { + const ColumnWithTypeAndName& elem = block.get_by_position(arg); + if (!elem.type->is_nullable()) { + continue; + } + + bool is_const = is_column_const(*elem.column); + /// Const Nullable that are NULL. + if (is_const && assert_cast(elem.column.get())->only_null()) { + return block.get_by_position(result).type->create_column_const(input_rows_count, 0); + } + if (is_const) { + continue; + } + + if (auto* nullable = assert_cast(elem.column.get())) { + const ColumnPtr& null_map_column = nullable->get_null_map_column_ptr(); + const NullMap& src_null_map = + assert_cast(*null_map_column).get_data(); + + update_bitmap_op_count(count_data, src_null_map); + } + } + + return src; +} + +Status execute_bitmap_op_count_null_to_zero( + FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, + size_t input_rows_count, + const std::function& + exec_impl_func) { + NullPresence null_presence = get_null_presence(block, arguments); + + if (null_presence.has_null_constant) { + block.get_by_position(result).column = + block.get_by_position(result).type->create_column_const(input_rows_count, 0); + } else if (null_presence.has_nullable) { + auto [temporary_block, new_args, new_result] = + create_block_with_nested_columns(block, arguments, result); + RETURN_IF_ERROR(exec_impl_func(context, temporary_block, new_args, new_result, + temporary_block.rows())); + block.get_by_position(result).column = handle_bitmap_op_count_null_value( + temporary_block.get_by_position(new_result).column, block, arguments, result, + input_rows_count); + } else { + return exec_impl_func(context, block, arguments, result, input_rows_count); + } + return Status::OK(); +} + +class FunctionBitmapAndNotCount : public IFunction { +public: + using LeftDataType = DataTypeBitMap; + using RightDataType = DataTypeBitMap; + using ResultDataType = typename BitmapAndNotCount::ResultDataType; + + static constexpr auto name = "bitmap_and_not_count"; + static FunctionPtr create() { return std::make_shared(); } + String get_name() const override { return name; } + size_t get_number_of_arguments() const override { return 2; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + bool return_nullable = false; + // result is nullable only when any columns is nullable for bitmap_and_not_count + for (size_t i = 0; i < arguments.size(); ++i) { + if (arguments[i]->is_nullable()) { + return_nullable = true; + break; + } + } + auto result_type = std::make_shared(); + return return_nullable ? make_nullable(result_type) : result_type; + } + + bool use_default_implementation_for_constants() const override { return true; } + + bool use_default_implementation_for_nulls() const override { + // for bitmap_and_not_count, result is always not null, and if the bitmap op result is null, + // the count is 0 + return false; + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + DCHECK_EQ(arguments.size(), 2); + + return execute_bitmap_op_count_null_to_zero( + context, block, arguments, result, input_rows_count, + std::bind((Status(FunctionBitmapAndNotCount::*)( + FunctionContext*, Block&, const ColumnNumbers&, size_t, size_t)) & + FunctionBitmapAndNotCount::execute_impl_internal, + this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + std::placeholders::_4, std::placeholders::_5)); + } + + Status execute_impl_internal(FunctionContext* context, Block& block, + const ColumnNumbers& arguments, size_t result, + size_t input_rows_count) { + const auto& left = block.get_by_position(arguments[0]); + auto lcol = left.column->convert_to_full_column_if_const(); + const auto& right = block.get_by_position(arguments[1]); + auto rcol = right.column->convert_to_full_column_if_const(); + + using ResultType = typename ResultDataType::FieldType; + using ColVecResult = ColumnVector; + + typename ColVecResult::MutablePtr col_res = ColVecResult::create(); + auto& vec_res = col_res->get_data(); + vec_res.resize(block.rows()); + + const ColumnBitmap* l_bitmap_col = assert_cast(lcol.get()); + const ColumnBitmap* r_bitmap_col = assert_cast(rcol.get()); + BitmapAndNotCount::vector_vector( + l_bitmap_col->get_data(), r_bitmap_col->get_data(), vec_res.data()); + + auto& result_info = block.get_by_position(result); + if (result_info.type->is_nullable()) { + block.replace_by_position( + result, ColumnNullable::create(std::move(col_res), + ColumnUInt8::create(input_rows_count, 0))); + } else { + block.replace_by_position(result, std::move(col_res)); + } + return Status::OK(); + } +}; + struct NameBitmapContains { static constexpr auto name = "bitmap_contains"; }; @@ -780,8 +927,6 @@ using FunctionBitmapNot = FunctionBinaryToType; using FunctionBitmapAndNot = FunctionBinaryToType; -using FunctionBitmapAndNotCount = FunctionBinaryToType; using FunctionBitmapContains = FunctionBinaryToType; diff --git a/be/src/vec/functions/function_bitmap_variadic.cpp b/be/src/vec/functions/function_bitmap_variadic.cpp index bbc0309808..fbd5942422 100644 --- a/be/src/vec/functions/function_bitmap_variadic.cpp +++ b/be/src/vec/functions/function_bitmap_variadic.cpp @@ -132,6 +132,12 @@ BITMAP_FUNCTION_COUNT_VARIADIC(BitmapOrCount, bitmap_or_count, |=); BITMAP_FUNCTION_COUNT_VARIADIC(BitmapAndCount, bitmap_and_count, &=); BITMAP_FUNCTION_COUNT_VARIADIC(BitmapXorCount, bitmap_xor_count, ^=); +Status execute_bitmap_op_count_null_to_zero( + FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, + size_t input_rows_count, + const std::function& + exec_impl_func); + template class FunctionBitMapVariadic : public IFunction { public: @@ -147,7 +153,7 @@ public: DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { using ResultDataType = typename Impl::ResultDataType; - if (std::is_same_v || std::is_same_v) { + if (std::is_same_v || is_count()) { bool return_nullable = false; // result is nullable only when any columns is nullable for bitmap_or and bitmap_or_count for (size_t i = 0; i < arguments.size(); ++i) { @@ -165,8 +171,10 @@ public: bool use_default_implementation_for_constants() const override { return true; } bool use_default_implementation_for_nulls() const override { - // result is null only when all columns is null for bitmap_or and bitmap_or_count - if (std::is_same_v || std::is_same_v) { + // result is null only when all columns is null for bitmap_or. + // for count functions, result is always not null, and if the bitmap op result is null, + // the count is 0 + if (std::is_same_v || is_count()) { return false; } else { return true; @@ -175,6 +183,23 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { + if (std::is_same_v || std::is_same_v) { + return execute_bitmap_op_count_null_to_zero( + context, block, arguments, result, input_rows_count, + std::bind((Status(FunctionBitMapVariadic::*)(FunctionContext*, Block&, + const ColumnNumbers&, size_t, + size_t)) & + FunctionBitMapVariadic::execute_impl_internal, + this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)); + } else { + return execute_impl_internal(context, block, arguments, result, input_rows_count); + } + } + + Status execute_impl_internal(FunctionContext* context, Block& block, + const ColumnNumbers& arguments, size_t result, + size_t input_rows_count) { size_t argument_size = arguments.size(); ColumnPtr argument_columns[argument_size]; @@ -212,6 +237,12 @@ public: } return Status::OK(); } + +private: + bool is_count() const { + return (std::is_same_v || std::is_same_v || + std::is_same_v); + } }; using FunctionBitmapOr = FunctionBitMapVariadic; diff --git a/be/test/vec/function/function_bitmap_test.cpp b/be/test/vec/function/function_bitmap_test.cpp index fadb858242..b58b597aad 100644 --- a/be/test/vec/function/function_bitmap_test.cpp +++ b/be/test/vec/function/function_bitmap_test.cpp @@ -87,7 +87,7 @@ TEST(function_bitmap_test, function_bitmap_and_count) { DataSet data_set = {{{&bitmap1, &bitmap2, &empty_bitmap}, (int64_t)0}, {{&bitmap1, &bitmap2, &bitmap3}, (int64_t)1}, //33 - {{&bitmap1, &bitmap2, Null()}, Null()}, + {{&bitmap1, &bitmap2, Null()}, (int64_t)0}, {{&bitmap1, &bitmap3, &bitmap3}, (int64_t)1}}; //33 check_function(func_name, input_types, data_set); @@ -151,7 +151,7 @@ TEST(function_bitmap_test, function_bitmap_xor_count) { DataSet data_set = { {{&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()}, (int64_t)0}, {{&bitmap1, &bitmap3, &bitmap3}, (int64_t)3}}; //1,1024,2019 check_function(func_name, input_types, data_set); @@ -167,7 +167,7 @@ TEST(function_bitmap_test, function_bitmap_and_not_count) { BitmapValue empty_bitmap; DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)3}, //1,2,3 - {{&bitmap2, Null()}, Null()}, + {{&bitmap2, Null()}, (int64_t)0}, {{&bitmap2, &bitmap3}, (int64_t)3}, //0,3,4 {{&bitmap1, &bitmap2}, (int64_t)2}}; //1,2 diff --git a/regression-test/data/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.out b/regression-test/data/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.out index 29e1234dca..57a71aceb9 100644 --- a/regression-test/data/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.out +++ b/regression-test/data/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.out @@ -189,23 +189,23 @@ true 3 \N \N 5 \N 4 \N \N 5 \N --- !sql -- +-- !sql_bitmap_and_count1 -- 0 --- !sql -- +-- !sql_bitmap_and_count2 -- 3 --- !sql -- +-- !sql_bitmap_and_count3 -- 1 --- !sql -- +-- !sql_bitmap_and_count4 -- 2 --- !sql -- +-- !sql_bitmap_and_count5 -- 0 --- !sql -- -\N +-- !sql_bitmap_and_count6 -- +0 -- !sql_bitmap_or_count1 -- 3 @@ -237,23 +237,95 @@ true -- !sql -- \N --- !sql -- +-- !sql_bitmap_xor_count1 -- 4 --- !sql -- +-- !sql_bitmap_xor_count2 -- 0 --- !sql -- +-- !sql_bitmap_xor_count3 -- 6 --- !sql -- +-- !sql_bitmap_xor_count4 -- 3 --- !sql -- +-- !sql_bitmap_xor_count5 -- 3 --- !sql -- -\N +-- !sql_bitmap_xor_count6 -- +0 + +-- !sql_bitmap_and_count7 -- +1 1 +2 1 +3 0 +4 0 + +-- !sql_bitmap_xor_count7 -- +1 2 +2 2 +3 0 +4 0 + +-- !sql_bitmap_and_not_count3 -- +1 1 +2 1 +3 0 +4 0 + +-- !sql_bitmap_and_count8 -- +1 2 +2 2 +3 1 +4 1 + +-- !sql_bitmap_xor_count8 -- +1 3 +2 3 +3 1 +4 1 + +-- !sql_bitmap_and_not_count4 -- +1 2 +2 2 +3 1 +4 1 + +-- !sql_bitmap_and_count9 -- +1 1 +2 1 + +-- !sql_bitmap_xor_count9 -- +1 2 +2 2 + +-- !sql_bitmap_and_not_count5 -- +1 1 +2 1 + +-- !sql_bitmap_and_count10 -- +1 1 +2 3 + +-- !sql_bitmap_xor_count10 -- +1 2 +2 1 + +-- !sql_bitmap_and_not_count6 -- +1 1 +2 1 + +-- !sql_bitmap_and_count11 -- +1 2 +2 4 + +-- !sql_bitmap_xor_count11 -- +1 3 +2 2 + +-- !sql_bitmap_and_not_count7 -- +1 2 +2 2 -- !sql -- 0 @@ -264,9 +336,12 @@ true -- !sql -- 2 --- !sql -- +-- !sql_bitmap_and_not_count1 -- 2 +-- !sql_bitmap_and_not_count2 -- +0 + -- !sql -- 1,2,3,4,5 diff --git a/regression-test/data/nereids_syntax_p0/test_bitmap_function_nereids.out b/regression-test/data/nereids_syntax_p0/test_bitmap_function_nereids.out deleted file mode 100644 index acbc116f38..0000000000 --- a/regression-test/data/nereids_syntax_p0/test_bitmap_function_nereids.out +++ /dev/null @@ -1,251 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !sql -- -0 - --- !sql -- -1 - --- !sql -- -1 - --- !sql -- -1,2 - --- !sql -- - - --- !sql -- -\N - --- !sql -- -false - --- !sql -- -true - --- !sql -- -0 - --- !sql -- - - --- !sql -- -0,1,2 - --- !sql -- -\N - --- !sql -- -false - --- !sql -- -true - --- !sql -- -true - --- !sql -- -false - --- !sql_bitmap_hash1 -- -1 - --- !sql_bitmap_hash2 -- -1 - --- !sql_bitmap_hash3 -- -0 - --- !sql_bitmap_hash64_1 -- -1 - --- !sql_bitmap_hash64_2 -- -1 - --- !sql_bitmap_hash64_3 -- -0 - --- !sql_bitmap_or1 -- -2 - --- !sql_bitmap_or2 -- -1 - --- !sql_bitmap_or3 -- -1,2 - --- !sql_bitmap_or4 -- -0,1,2,10 - --- !sql_bitmap_or5 -- -0,1,2,10 - --- !sql_bitmap_or6 -- -1,2,3,4,5,10 - --- !sql -- -0 - --- !sql -- -3 - --- !sql -- -1 - --- !sql -- -2 - --- !sql -- -0 - --- !sql -- -\N - --- !sql_bitmap_or_count1 -- -3 - --- !sql_bitmap_or_count2 -- -3 - --- !sql_bitmap_or_count3 -- -5 - --- !sql_bitmap_or_count4 -- -6 - --- !sql_bitmap_or_count5 -- -6 - --- !sql -- -2 - --- !sql -- -1,4 - --- !sql -- -1,3,5 - --- !sql -- -1,3,5 - --- !sql -- -\N - --- !sql -- -4 - --- !sql -- -0 - --- !sql -- -6 - --- !sql -- -3 - --- !sql -- -3 - --- !sql -- -\N - --- !sql -- -0 - --- !sql -- -5 - --- !sql -- -2 - --- !sql -- -2 - --- !sql -- -1,2,3,4,5 - --- !sql -- -2 - --- !sql -- -1,2,3 - --- !sql -- -4,5 - --- !sql -- -0,1,2 - --- !sql -- -2,3 - --- !sql -- -2,3,5 - --- !sql -- -\N - --- !sql -- - - --- !sql -- -1 - --- !sql -- -1,2 - --- !sql -- -1 \N -2 \N - --- !sql -- -1 3 -2 2 - --- !sql -- -1 3 -2 2 - --- !sql -- -2 - --- !sql -- -1,4 - --- !sql -- -1,3,5 - --- !sql -- -1,3,5 - --- !sql -- -\N - --- !sql -- -1 - --- !sql -- - - --- !sql -- -\N - --- !sql -- -9999999999 - --- !sql -- -4 1,2,3 -3 1,2,3,4,5 - --- !sql -- -3 - --- !sql -- -\N - --- !sql -- -0 - --- !sql -- -0 - diff --git a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out index c3cccfbba5..8cb5e56a7f 100644 --- a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out +++ b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out @@ -189,23 +189,23 @@ true 3 \N \N 5 \N 4 \N \N 5 \N --- !sql -- +-- !sql_bitmap_and_count1 -- 0 --- !sql -- +-- !sql_bitmap_and_count2 -- 3 --- !sql -- +-- !sql_bitmap_and_count3 -- 1 --- !sql -- +-- !sql_bitmap_and_count4 -- 2 --- !sql -- +-- !sql_bitmap_and_count5 -- 0 --- !sql -- -\N +-- !sql_bitmap_and_count6 -- +0 -- !sql_bitmap_or_count1 -- 3 @@ -237,23 +237,95 @@ true -- !sql -- \N --- !sql -- +-- !sql_bitmap_xor_count1 -- 4 --- !sql -- +-- !sql_bitmap_xor_count2 -- 0 --- !sql -- +-- !sql_bitmap_xor_count3 -- 6 --- !sql -- +-- !sql_bitmap_xor_count4 -- 3 --- !sql -- +-- !sql_bitmap_xor_count5 -- 3 --- !sql -- -\N +-- !sql_bitmap_xor_count6 -- +0 + +-- !sql_bitmap_and_count7 -- +1 1 +2 1 +3 0 +4 0 + +-- !sql_bitmap_xor_count7 -- +1 2 +2 2 +3 0 +4 0 + +-- !sql_bitmap_and_not_count3 -- +1 1 +2 1 +3 0 +4 0 + +-- !sql_bitmap_and_count8 -- +1 2 +2 2 +3 1 +4 1 + +-- !sql_bitmap_xor_count8 -- +1 3 +2 3 +3 1 +4 1 + +-- !sql_bitmap_and_not_count4 -- +1 2 +2 2 +3 1 +4 1 + +-- !sql_bitmap_and_count9 -- +1 1 +2 1 + +-- !sql_bitmap_xor_count9 -- +1 2 +2 2 + +-- !sql_bitmap_and_not_count5 -- +1 1 +2 1 + +-- !sql_bitmap_and_count10 -- +1 1 +2 3 + +-- !sql_bitmap_xor_count10 -- +1 2 +2 1 + +-- !sql_bitmap_and_not_count6 -- +1 1 +2 1 + +-- !sql_bitmap_and_count11 -- +1 2 +2 4 + +-- !sql_bitmap_xor_count11 -- +1 3 +2 2 + +-- !sql_bitmap_and_not_count7 -- +1 2 +2 2 -- !sql -- 0 @@ -264,9 +336,12 @@ true -- !sql -- 2 --- !sql -- +-- !sql_bitmap_and_not_count1 -- 2 +-- !sql_bitmap_and_not_count2 -- +0 + -- !sql -- 1,2,3,4,5 diff --git a/regression-test/suites/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy b/regression-test/suites/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy index a3245e266b..4f8d6416dd 100644 --- a/regression-test/suites/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy @@ -58,20 +58,20 @@ suite("test_bitmap_function") { // BITMAP_OR qt_sql_bitmap_or1 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(2))) cnt """ - qt_sql_bitmap_or2 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt """ - qt_sql_bitmap_or3 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ + qt_sql_bitmap_or2 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt """ + qt_sql_bitmap_or3 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ // TODO: fix constant fold of bitmap_or and enable this case - // qt_sql_bitmap_or4 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) """ - qt_sql_bitmap_or5 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) """ - qt_sql_bitmap_or6 """ select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ + // qt_sql_bitmap_or4 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) """ + qt_sql_bitmap_or5 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) """ + qt_sql_bitmap_or6 """ select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ // TODO: fix constant fold of bitmap_or and enable this case - // qt_sql_bitmap_or7 """ select bitmap_count(bitmap_or(to_bitmap(1), null)) cnt """ + // qt_sql_bitmap_or7 """ select bitmap_count(bitmap_or(to_bitmap(1), null)) cnt """ // bitmap_or of all nullable column - sql """ DROP TABLE IF EXISTS test_bitmap_or1 """ - sql """ DROP TABLE IF EXISTS test_bitmap_or2 """ + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ DROP TABLE IF EXISTS test_bitmap2 """ sql """ - CREATE TABLE test_bitmap_or1 ( + CREATE TABLE test_bitmap1 ( dt INT(11) NULL, id bitmap BITMAP_UNION NULL ) ENGINE=OLAP @@ -83,7 +83,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or1 + test_bitmap1 values (1, to_bitmap(11)), (2, to_bitmap(22)), @@ -91,7 +91,7 @@ suite("test_bitmap_function") { (4, to_bitmap(44)); """ sql """ - CREATE TABLE test_bitmap_or2 ( + CREATE TABLE test_bitmap2 ( dt INT(11) NULL, id bitmap BITMAP_UNION NULL ) ENGINE=OLAP @@ -103,7 +103,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or2 + test_bitmap2 values (1, to_bitmap(111)), (2, to_bitmap(222)), @@ -114,7 +114,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -123,7 +123,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -132,7 +132,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -142,7 +142,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -152,7 +152,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt """ @@ -161,16 +161,16 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt """ // bitmap_or of NOT NULLABLE column and nullable column - sql """ DROP TABLE IF EXISTS test_bitmap_or1 """ + sql """ DROP TABLE IF EXISTS test_bitmap1 """ sql """ - CREATE TABLE test_bitmap_or1 ( + CREATE TABLE test_bitmap1 ( dt INT(11) NULL, id bitmap BITMAP_UNION NOT NULL ) ENGINE=OLAP @@ -182,7 +182,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or1 + test_bitmap1 values (1, to_bitmap(11)), (2, to_bitmap(22)), @@ -194,7 +194,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -203,7 +203,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -212,7 +212,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -222,7 +222,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -232,7 +232,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt """ @@ -241,7 +241,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt @@ -267,8 +267,8 @@ suite("test_bitmap_function") { r.dt rdt, r.id rid from - test_bitmap_or1 l - left join test_bitmap_or2 r on l.dt = r.dt + test_bitmap1 l + left join test_bitmap2 r on l.dt = r.dt where r.id is null); """ sql """ @@ -279,8 +279,8 @@ suite("test_bitmap_function") { r.dt rdt, r.id rid from - test_bitmap_or1 l - right join test_bitmap_or2 r on l.dt = r.dt + test_bitmap1 l + right join test_bitmap2 r on l.dt = r.dt where l.id is null); """ @@ -292,12 +292,13 @@ suite("test_bitmap_function") { qt_sql_bitmap_or23 """ select v1.ldt, v1.rdt, v2.ldt, v2.rdt, bitmap_to_string(bitmap_or(v1.rid, v2.lid)) from v1, v2 order by v1.ldt, v2.rdt; """ // bitmap_and_count - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL) """ + qt_sql_bitmap_and_count1 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ + qt_sql_bitmap_and_count2 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ + qt_sql_bitmap_and_count3 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ + qt_sql_bitmap_and_count4 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')) """ + qt_sql_bitmap_and_count5 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()) """ + // TODO: fix constant fold and enable this case + // qt_sql_bitmap_and_count6 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL) """ // bitmap_or_count qt_sql_bitmap_or_count1 """ select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ @@ -315,12 +316,209 @@ suite("test_bitmap_function") { qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ // BITMAP_XOR_COUNT - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ + qt_sql_bitmap_xor_count1 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ + qt_sql_bitmap_xor_count2 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ + qt_sql_bitmap_xor_count3 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')) """ + qt_sql_bitmap_xor_count4 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ + qt_sql_bitmap_xor_count5 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ + // TODO: fix constant fold and enable this case + // qt_sql_bitmap_xor_count6 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ + + // bitmap_and_count, bitmap_xor_count, bitmap_and_not_count of all nullable column + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ DROP TABLE IF EXISTS test_bitmap2 """ + sql """ + CREATE TABLE test_bitmap1 ( + dt INT(11) NULL, + id bitmap BITMAP_UNION NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap1 + values + (1, bitmap_from_string("11,111")), + (2, bitmap_from_string("22,222")), + (3, bitmap_from_string("33,333")), + (4, bitmap_from_string("44,444")); + """ + sql """ + CREATE TABLE test_bitmap2 ( + dt INT(11) NULL, + id bitmap BITMAP_UNION NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap2 + values + (1, bitmap_from_string("11,1111")), + (2, bitmap_from_string("22,2222")), + (5, bitmap_from_string("55,5555")); + """ + qt_sql_bitmap_and_count7 """ + select + l.dt, + bitmap_and_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_xor_count7 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_not_count3 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_count8 """ + select + l.dt, + bitmap_and_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_xor_count8 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_not_count4 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_count9 """ + select + l.dt, + bitmap_and_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + qt_sql_bitmap_xor_count9 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + qt_sql_bitmap_and_not_count5 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + // bitmap_and_count, bitmap_xor_count, bitmap_and_not_count of all not nullable column + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ + CREATE TABLE test_bitmap1 ( + dt INT(11) NOT NULL, + id1 bitmap BITMAP_UNION NOT NULL, + id2 bitmap BITMAP_UNION NOT NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap1 + values + (1, bitmap_from_string("11,1111"), bitmap_from_string("11,111")), + (2, bitmap_from_string("22,222,2222,22222"), bitmap_from_string("22,222,2222")) + """ + qt_sql_bitmap_and_count10 """ + select + dt, + bitmap_and_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_xor_count10 """ + select + dt, + bitmap_xor_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_not_count6 """ + select + dt, + bitmap_and_not_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_count11 """ + select + dt, + bitmap_and_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_xor_count11 """ + select + dt, + bitmap_xor_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_not_count7 """ + select + dt, + bitmap_and_not_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ // BITMAP_NOT qt_sql """ select bitmap_count(bitmap_not(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt """ @@ -330,7 +528,9 @@ suite("test_bitmap_function") { qt_sql """ select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt """ // BITMAP_AND_NOT_COUNT - qt_sql """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt """ + qt_sql_bitmap_and_not_count1 """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt """ + // TODO: fix constant fold and enable this case + // qt_sql_bitmap_and_not_count2 """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),null) cnt """ // BITMAP_SUBSET_IN_RANGE qt_sql """ select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 0, 9)) value """ diff --git a/regression-test/suites/nereids_syntax_p0/test_bitmap_function_nereids.groovy b/regression-test/suites/nereids_syntax_p0/test_bitmap_function_nereids.groovy deleted file mode 100644 index 0ca43b64a2..0000000000 --- a/regression-test/suites/nereids_syntax_p0/test_bitmap_function_nereids.groovy +++ /dev/null @@ -1,195 +0,0 @@ -// 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. - -suite("test_bitmap_function_nereids") { - sql 'set enable_fallback_to_original_planner=false;' - sql 'set enable_nereids_planner=true;' - // BITMAP_AND - qt_sql """ select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(2))) cnt """ - qt_sql """ select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(1))) cnt """ - qt_sql """ select bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(1))) """ - qt_sql """ select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ - qt_sql """ select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty())) """ - qt_sql """ select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),NULL)) """ - - // BITMAP_CONTAINS - qt_sql """ select bitmap_contains(to_bitmap(1),2) cnt """ - qt_sql """ select bitmap_contains(to_bitmap(1),1) cnt """ - - // BITMAP_EMPTY - qt_sql """ select bitmap_count(bitmap_empty()) """ - - // BITMAP_FROM_STRING - qt_sql """ select bitmap_to_string(bitmap_empty()) """ - qt_sql """ select bitmap_to_string(bitmap_from_string("0, 1, 2")) """ - qt_sql """ select bitmap_from_string("-1, 0, 1, 2") """ - - // BITMAP_HAS_ANY - qt_sql """ select bitmap_has_any(to_bitmap(1),to_bitmap(2)) cnt """ - qt_sql """ select bitmap_has_any(to_bitmap(1),to_bitmap(1)) cnt """ - - // BITMAP_HAS_ALL - qt_sql """ select bitmap_has_all(bitmap_from_string("0, 1, 2"), bitmap_from_string("1, 2")) cnt """ - qt_sql """ select bitmap_has_all(bitmap_empty(), bitmap_from_string("1, 2")) cnt """ - - // BITMAP_HASH - qt_sql_bitmap_hash1 """ select bitmap_count(bitmap_hash('hello')) """ - qt_sql_bitmap_hash2 """ select bitmap_count(bitmap_hash('')) """ - qt_sql_bitmap_hash3 """ select bitmap_count(bitmap_hash(null)) """ - - // BITMAP_HASH64 - qt_sql_bitmap_hash64_1 """ select bitmap_count(bitmap_hash64('hello')) """ - qt_sql_bitmap_hash64_2 """ select bitmap_count(bitmap_hash64('')) """ - qt_sql_bitmap_hash64_3 """ select bitmap_count(bitmap_hash64(null)) """ - - // BITMAP_OR - qt_sql_bitmap_or1 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(2))) cnt """ - qt_sql_bitmap_or2 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt """ - qt_sql_bitmap_or3 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ - // TODO: fix constant fold of bitmap_or and enable this case - // qt_sql_bitmap_or4 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) """ - qt_sql_bitmap_or5 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) """ - qt_sql_bitmap_or6 """ select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ - - // bitmap_and_count - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL) """ - - // bitmap_or_count - qt_sql_bitmap_or_count1 """ select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ - qt_sql_bitmap_or_count2 """ select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'))""" - qt_sql_bitmap_or_count3 """ select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql_bitmap_or_count4 """ select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), bitmap_empty()) """ - // TODO: fix constant fold of bitmap_or and enable this case - // qt_sql_bitmap_or_count5 """ select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), NULL) """ - - // BITMAP_XOR - qt_sql """ select bitmap_count(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ - - // BITMAP_XOR_COUNT - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ - - // BITMAP_NOT - qt_sql """ select bitmap_count(bitmap_not(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt """ - qt_sql """ select bitmap_to_string(bitmap_not(bitmap_from_string('2,3,5'),bitmap_from_string('1,2,3,4'))) """ - - // BITMAP_AND_NOT - qt_sql """ select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt """ - - // BITMAP_AND_NOT_COUNT - qt_sql """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt """ - - // BITMAP_SUBSET_IN_RANGE - qt_sql """ select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 0, 9)) value """ - qt_sql """ select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 2, 3)) value """ - - // BITMAP_SUBSET_LIMIT - qt_sql """ select bitmap_to_string(bitmap_subset_limit(bitmap_from_string('1,2,3,4,5'), 0, 3)) value """ - qt_sql """ select bitmap_to_string(bitmap_subset_limit(bitmap_from_string('1,2,3,4,5'), 4, 3)) value """ - - // SUB_BITMAP - qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), 0, 3)) value """ - qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), -3, 2)) value """ - qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), 2, 100)) value """ - - // BITMAP_TO_STRING - qt_sql """ select bitmap_to_string(null) """ - qt_sql """ select bitmap_to_string(bitmap_empty()) """ - qt_sql """ select bitmap_to_string(to_bitmap(1)) """ - qt_sql """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ - - // BITMAP_UNION - def bitmapUnionTable = "test_bitmap_union" - sql """ DROP TABLE IF EXISTS ${bitmapUnionTable} """ - sql """ create table if not exists ${bitmapUnionTable} (page_id int,user_id bitmap bitmap_union) aggregate key (page_id) distributed by hash (page_id) PROPERTIES("replication_num" = "1") """ - - sql """ insert into ${bitmapUnionTable} values(1, to_bitmap(1)); """ - sql """ insert into ${bitmapUnionTable} values(1, to_bitmap(2)); """ - sql """ insert into ${bitmapUnionTable} values(1, to_bitmap(3)); """ - sql """ insert into ${bitmapUnionTable} values(2, to_bitmap(1)); """ - sql """ insert into ${bitmapUnionTable} values(2, to_bitmap(2)); """ - - qt_sql """ select page_id, bitmap_union(user_id) from ${bitmapUnionTable} group by page_id order by page_id """ - qt_sql """ select page_id, bitmap_count(bitmap_union(user_id)) from ${bitmapUnionTable} group by page_id order by page_id """ - qt_sql """ select page_id, count(distinct user_id) from ${bitmapUnionTable} group by page_id order by page_id """ - - sql """ drop table ${bitmapUnionTable} """ - - // BITMAP_XOR - qt_sql """ select bitmap_count(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt; """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))); """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))); """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())); """ - qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)); """ - - // TO_BITMAP - qt_sql """ select bitmap_count(to_bitmap(10)) """ - qt_sql """ select bitmap_to_string(to_bitmap(-1)) """ - - // BITMAP_MAX - qt_sql """ select bitmap_max(bitmap_from_string('')) value; """ - qt_sql """ select bitmap_max(bitmap_from_string('1,9999999999')) value """ - - // INTERSECT_COUNT - def intersectCountTable = "test_intersect_count" - sql """ DROP TABLE IF EXISTS ${intersectCountTable} """ - sql """ create table if not exists ${intersectCountTable} (dt int (11),page varchar (10),user_id bitmap BITMAP_UNION ) DISTRIBUTED BY HASH(dt) BUCKETS 2 PROPERTIES("replication_num" = "1") """ - - - sql """ insert into ${intersectCountTable} values(3,"110001", to_bitmap(1)); """ - sql """ insert into ${intersectCountTable} values(3,"110001", to_bitmap(2)); """ - sql """ insert into ${intersectCountTable} values(3,"110001", to_bitmap(3)); """ - sql """ insert into ${intersectCountTable} values(3,"110001", to_bitmap(4)); """ - sql """ insert into ${intersectCountTable} values(3,"110001", to_bitmap(5)); """ - sql """ insert into ${intersectCountTable} values(4,"110001", to_bitmap(1)); """ - sql """ insert into ${intersectCountTable} values(4,"110001", to_bitmap(2)); """ - sql """ insert into ${intersectCountTable} values(4,"110001", to_bitmap(3)); """ - - qt_sql """ select dt,bitmap_to_string(user_id) from ${intersectCountTable} where dt in (3,4) order by dt desc; """ - qt_sql """ select intersect_count(user_id,dt,3,4) from ${intersectCountTable}; """ - - // ARTHOGONAL_BITMAP_**** - def arthogonalBitmapTable = "test_arthogonal_bitmap" - sql """ DROP TABLE IF EXISTS ${arthogonalBitmapTable} """ - sql """ CREATE TABLE IF NOT EXISTS ${arthogonalBitmapTable} ( tag_group bigint(20) NULL COMMENT "标签组", tag_value_id varchar(64) NULL COMMENT "标签值", tag_range int(11) NOT NULL DEFAULT "0" COMMENT "", partition_sign varchar(32) NOT NULL COMMENT "分区标识", bucket int(11) NOT NULL COMMENT "分桶字段", confidence tinyint(4) NULL DEFAULT "100" COMMENT "置信度", members bitmap BITMAP_UNION NULL COMMENT "人群") ENGINE=OLAP AGGREGATE KEY(tag_group, tag_value_id, tag_range, partition_sign, bucket, confidence) COMMENT "dmp_tag_map" PARTITION BY LIST(partition_sign) (PARTITION p202203231 VALUES IN ("2022-03-23-1"), PARTITION p202203251 VALUES IN ("2022-03-25-1"), PARTITION p202203261 VALUES IN ("2022-03-26-1"), PARTITION p202203271 VALUES IN ("2022-03-27-1"), PARTITION p202203281 VALUES IN ("2022-03-28-1"), PARTITION p202203291 VALUES IN ("2022-03-29-1"), PARTITION p202203301 VALUES IN ("2022-03-30-1"), PARTITION p202203311 VALUES IN ("2022-03-31-1"), PARTITION p202204011 VALUES IN ("2022-04-01-1"), PARTITION crowd VALUES IN ("crowd"), PARTITION crowd_tmp VALUES IN ("crowd_tmp"), PARTITION extend_crowd VALUES IN ("extend_crowd"), PARTITION partition_sign VALUES IN ("online_crowd")) DISTRIBUTED BY HASH(bucket) BUCKETS 64 PROPERTIES ("replication_allocation" = "tag.location.default: 1", "in_memory" = "false", "storage_format" = "V2");""" - - qt_sql """ select orthogonal_bitmap_intersect(members, tag_group, 1150000, 1150001, 390006) from ${arthogonalBitmapTable} where tag_group in ( 1150000, 1150001, 390006); """ - qt_sql """ select orthogonal_bitmap_intersect_count(members, tag_group, 1150000, 1150001, 390006) from ${arthogonalBitmapTable} where tag_group in ( 1150000, 1150001, 390006); """ - qt_sql """ select orthogonal_bitmap_union_count(members) from ${arthogonalBitmapTable} where tag_group in ( 1150000, 1150001, 390006); """ - - // qt_sql """ select bitmap_to_array(user_id) from ${intersectCountTable} order by dt desc; """ - // qt_sql """ select bitmap_to_array(bitmap_empty()); """ - // qt_sql """ select bitmap_to_array(bitmap_from_string('100,200,3,4')); """ - - // qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1,2,3,4,5'), 0, 3)) value; """ - // qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1'), 0, 3)) value; """ - // qt_sql """ select bitmap_to_string(bitmap_subset_limit(bitmap_from_string('100'), 0, 3)) value; """ - // qt_sql """ select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('20221103'), 0, 20221104)) date_list_bitmap; """ -} diff --git a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy index b958871c94..f025ef1643 100644 --- a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy @@ -56,18 +56,18 @@ suite("test_bitmap_function") { // BITMAP_OR qt_sql_bitmap_or1 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(2))) cnt """ - qt_sql_bitmap_or2 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt """ - qt_sql_bitmap_or3 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ - qt_sql_bitmap_or4 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) """ - qt_sql_bitmap_or5 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) """ - qt_sql_bitmap_or6 """ select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ - qt_sql_bitmap_or7 """ select bitmap_count(bitmap_or(to_bitmap(1), null)) cnt """ + qt_sql_bitmap_or2 """ select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt """ + qt_sql_bitmap_or3 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) """ + qt_sql_bitmap_or4 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) """ + qt_sql_bitmap_or5 """ select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) """ + qt_sql_bitmap_or6 """ select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) """ + qt_sql_bitmap_or7 """ select bitmap_count(bitmap_or(to_bitmap(1), null)) cnt """ // bitmap_or of all nullable column - sql """ DROP TABLE IF EXISTS test_bitmap_or1 """ - sql """ DROP TABLE IF EXISTS test_bitmap_or2 """ + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ DROP TABLE IF EXISTS test_bitmap2 """ sql """ - CREATE TABLE test_bitmap_or1 ( + CREATE TABLE test_bitmap1 ( dt INT(11) NULL, id bitmap BITMAP_UNION NULL ) ENGINE=OLAP @@ -79,7 +79,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or1 + test_bitmap1 values (1, to_bitmap(11)), (2, to_bitmap(22)), @@ -87,7 +87,7 @@ suite("test_bitmap_function") { (4, to_bitmap(44)); """ sql """ - CREATE TABLE test_bitmap_or2 ( + CREATE TABLE test_bitmap2 ( dt INT(11) NULL, id bitmap BITMAP_UNION NULL ) ENGINE=OLAP @@ -99,7 +99,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or2 + test_bitmap2 values (1, to_bitmap(111)), (2, to_bitmap(222)), @@ -110,7 +110,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -119,7 +119,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -128,7 +128,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -138,7 +138,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -148,7 +148,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt """ @@ -157,16 +157,16 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt """ // bitmap_or of NOT NULLABLE column and nullable column - sql """ DROP TABLE IF EXISTS test_bitmap_or1 """ + sql """ DROP TABLE IF EXISTS test_bitmap1 """ sql """ - CREATE TABLE test_bitmap_or1 ( + CREATE TABLE test_bitmap1 ( dt INT(11) NULL, id bitmap BITMAP_UNION NOT NULL ) ENGINE=OLAP @@ -178,7 +178,7 @@ suite("test_bitmap_function") { """ sql """ insert into - test_bitmap_or1 + test_bitmap1 values (1, to_bitmap(11)), (2, to_bitmap(22)), @@ -190,7 +190,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -199,7 +199,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt, count """ @@ -208,7 +208,7 @@ suite("test_bitmap_function") { l.dt, bitmap_count(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -218,7 +218,7 @@ suite("test_bitmap_function") { l.dt, bitmap_or_count(l.id, r.id) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt, count @@ -228,7 +228,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt order by l.dt """ @@ -237,7 +237,7 @@ suite("test_bitmap_function") { l.dt, bitmap_to_string(bitmap_or(l.id, r.id)) count from - test_bitmap_or1 l left join test_bitmap_or2 r + test_bitmap1 l left join test_bitmap2 r on l.dt = r.dt where r.id is not null order by l.dt @@ -263,8 +263,8 @@ suite("test_bitmap_function") { r.dt rdt, r.id rid from - test_bitmap_or1 l - left join test_bitmap_or2 r on l.dt = r.dt + test_bitmap1 l + left join test_bitmap2 r on l.dt = r.dt where r.id is null); """ sql """ @@ -275,8 +275,8 @@ suite("test_bitmap_function") { r.dt rdt, r.id rid from - test_bitmap_or1 l - right join test_bitmap_or2 r on l.dt = r.dt + test_bitmap1 l + right join test_bitmap2 r on l.dt = r.dt where l.id is null); """ @@ -288,12 +288,12 @@ suite("test_bitmap_function") { qt_sql_bitmap_or23 """ select v1.ldt, v1.rdt, v2.ldt, v2.rdt, bitmap_to_string(bitmap_or(v1.rid, v2.lid)) from v1, v2 order by v1.ldt, v2.rdt; """ // bitmap_and_count - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()) """ - qt_sql """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL) """ + qt_sql_bitmap_and_count1 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ + qt_sql_bitmap_and_count2 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ + qt_sql_bitmap_and_count3 """ select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ + qt_sql_bitmap_and_count4 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')) """ + qt_sql_bitmap_and_count5 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()) """ + qt_sql_bitmap_and_count6 """ select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL) """ // bitmap_or_count qt_sql_bitmap_or_count1 """ select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty()) """ @@ -310,12 +310,208 @@ suite("test_bitmap_function") { qt_sql """ select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ // BITMAP_XOR_COUNT - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ - qt_sql """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ - qt_sql """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ + qt_sql_bitmap_xor_count1 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) """ + qt_sql_bitmap_xor_count2 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')) """ + qt_sql_bitmap_xor_count3 """ select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')) """ + qt_sql_bitmap_xor_count4 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))) """ + qt_sql_bitmap_xor_count5 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())) """ + qt_sql_bitmap_xor_count6 """ select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)) """ + + // bitmap_and_count, bitmap_xor_count, bitmap_and_not_count of all nullable column + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ DROP TABLE IF EXISTS test_bitmap2 """ + sql """ + CREATE TABLE test_bitmap1 ( + dt INT(11) NULL, + id bitmap BITMAP_UNION NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap1 + values + (1, bitmap_from_string("11,111")), + (2, bitmap_from_string("22,222")), + (3, bitmap_from_string("33,333")), + (4, bitmap_from_string("44,444")); + """ + sql """ + CREATE TABLE test_bitmap2 ( + dt INT(11) NULL, + id bitmap BITMAP_UNION NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap2 + values + (1, bitmap_from_string("11,1111")), + (2, bitmap_from_string("22,2222")), + (5, bitmap_from_string("55,5555")); + """ + qt_sql_bitmap_and_count7 """ + select + l.dt, + bitmap_and_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_xor_count7 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_not_count3 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_count8 """ + select + l.dt, + bitmap_and_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_xor_count8 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_not_count4 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) + 1 count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + order by l.dt, count + """ + qt_sql_bitmap_and_count9 """ + select + l.dt, + bitmap_and_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + qt_sql_bitmap_xor_count9 """ + select + l.dt, + bitmap_xor_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + qt_sql_bitmap_and_not_count5 """ + select + l.dt, + bitmap_and_not_count(l.id, r.id) count + from + test_bitmap1 l left join test_bitmap2 r + on l.dt = r.dt + where r.id is not null + order by l.dt, count + """ + // bitmap_and_count, bitmap_xor_count, bitmap_and_not_count of all not nullable column + sql """ DROP TABLE IF EXISTS test_bitmap1 """ + sql """ + CREATE TABLE test_bitmap1 ( + dt INT(11) NOT NULL, + id1 bitmap BITMAP_UNION NOT NULL, + id2 bitmap BITMAP_UNION NOT NULL + ) ENGINE=OLAP + AGGREGATE KEY(dt) + DISTRIBUTED BY HASH(dt) BUCKETS 2 + properties ( + "replication_num" = "1" + ); + """ + sql """ + insert into + test_bitmap1 + values + (1, bitmap_from_string("11,1111"), bitmap_from_string("11,111")), + (2, bitmap_from_string("22,222,2222,22222"), bitmap_from_string("22,222,2222")) + """ + qt_sql_bitmap_and_count10 """ + select + dt, + bitmap_and_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_xor_count10 """ + select + dt, + bitmap_xor_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_not_count6 """ + select + dt, + bitmap_and_not_count(id1, id2) count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_count11 """ + select + dt, + bitmap_and_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_xor_count11 """ + select + dt, + bitmap_xor_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ + qt_sql_bitmap_and_not_count7 """ + select + dt, + bitmap_and_not_count(id1, id2) + 1 count + from + test_bitmap1 + order by dt, count + """ // BITMAP_NOT qt_sql """ select bitmap_count(bitmap_not(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt """ @@ -325,7 +521,8 @@ suite("test_bitmap_function") { qt_sql """ select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt """ // BITMAP_AND_NOT_COUNT - qt_sql """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt """ + qt_sql_bitmap_and_not_count1 """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt """ + qt_sql_bitmap_and_not_count2 """ select bitmap_and_not_count(bitmap_from_string('1,2,3'),null) cnt """ // BITMAP_SUBSET_IN_RANGE qt_sql """ select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 0, 9)) value """