This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 9d6428e56f90ddde7ec34be0a3acc1042eec8bb5 Author: TengJianPing <18241664+jackte...@users.noreply.github.com> AuthorDate: Wed Mar 15 09:34:44 2023 +0800 [fix](coalesce) support coalesce function for bitmap (#17798) --- be/src/vec/functions/function_coalesce.cpp | 40 +++++++- .../datatype_p0/bitmap/test_bitmap_coalesce.out | 8 ++ .../datatype_p0/bitmap/test_bitmap_coalesce.groovy | 102 +++++++++++++++++++++ 3 files changed, 145 insertions(+), 5 deletions(-) diff --git a/be/src/vec/functions/function_coalesce.cpp b/be/src/vec/functions/function_coalesce.cpp index 1d1ae5d593..c7edcd74ce 100644 --- a/be/src/vec/functions/function_coalesce.cpp +++ b/be/src/vec/functions/function_coalesce.cpp @@ -166,8 +166,9 @@ public: //if not string type, could check one column firstly, //and then fill the not null value in result column, //this method may result in higher CPU cache - filled_result_column(result_type, result_column, argument_columns[i], null_map_data, - filled_flags.data(), input_rows_count); + RETURN_IF_ERROR(filled_result_column(result_type, result_column, + argument_columns[i], null_map_data, + filled_flags.data(), input_rows_count)); } } @@ -212,9 +213,32 @@ public: return Status::OK(); } - Status filled_result_column(const DataTypePtr& data_type, MutableColumnPtr& result_column, - ColumnPtr& argument_column, UInt8* __restrict null_map_data, - UInt8* __restrict filled_flag, const size_t input_rows_count) { + Status insert_result_data_bitmap(MutableColumnPtr& result_column, ColumnPtr& argument_column, + const UInt8* __restrict null_map_data, + UInt8* __restrict filled_flag, const size_t input_rows_count) { + auto* __restrict result_raw_data = + reinterpret_cast<ColumnBitmap*>(result_column.get())->get_data().data(); + auto* __restrict column_raw_data = + reinterpret_cast<const ColumnBitmap*>(argument_column.get())->get_data().data(); + + // Here it's SIMD thought the compiler automatically also + // true: null_map_data[row]==0 && filled_idx[row]==0 + // if true, could filled current row data into result column + for (size_t row = 0; row < input_rows_count; ++row) { + if (!(null_map_data[row] | filled_flag[row])) { + result_raw_data[row] = column_raw_data[row]; + } + filled_flag[row] += (!(null_map_data[row] | filled_flag[row])); + } + return Status::OK(); + } + + [[nodiscard]] Status filled_result_column(const DataTypePtr& data_type, + MutableColumnPtr& result_column, + ColumnPtr& argument_column, + UInt8* __restrict null_map_data, + UInt8* __restrict filled_flag, + const size_t input_rows_count) { WhichDataType which(data_type->is_nullable() ? reinterpret_cast<const DataTypeNullable*>(data_type.get()) ->get_nested_type() @@ -227,6 +251,12 @@ public: DECIMAL_TYPE_TO_COLUMN_TYPE(DISPATCH) TIME_TYPE_TO_COLUMN_TYPE(DISPATCH) #undef DISPATCH + + if (which.idx == TypeIndex::BitMap) { + return insert_result_data_bitmap(result_column, argument_column, null_map_data, + filled_flag, input_rows_count); + } + return Status::NotSupported("argument_type {} not supported", data_type->get_name()); } }; diff --git a/regression-test/data/datatype_p0/bitmap/test_bitmap_coalesce.out b/regression-test/data/datatype_p0/bitmap/test_bitmap_coalesce.out new file mode 100644 index 0000000000..3b02873531 --- /dev/null +++ b/regression-test/data/datatype_p0/bitmap/test_bitmap_coalesce.out @@ -0,0 +1,8 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql_bitmap_coalesce -- +70018 A1 A A1 A1 1 1 +70019 A A1 A1 A1 1 1 +70020 A1,2 A1 A1,2 A1,2 2 2 +70021 A2 \N A2 A2 1 1 +70022 \N A2 A2 A2 1 1 + diff --git a/regression-test/suites/datatype_p0/bitmap/test_bitmap_coalesce.groovy b/regression-test/suites/datatype_p0/bitmap/test_bitmap_coalesce.groovy new file mode 100644 index 0000000000..594ccb53d9 --- /dev/null +++ b/regression-test/suites/datatype_p0/bitmap/test_bitmap_coalesce.groovy @@ -0,0 +1,102 @@ +// 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_coalesce") { + sql """DROP TABLE IF EXISTS `test_bitmap_t0`""" + sql """ + CREATE TABLE `test_bitmap_t0` ( + `org_sid` int(11) NOT NULL DEFAULT "0", + `ct_sid` int(11) NOT NULL DEFAULT "0", + `userid_bitmap` bitmap BITMAP_UNION NOT NULL + ) ENGINE=OLAP + AGGREGATE KEY(`org_sid`, `ct_sid`) + DISTRIBUTED BY HASH(`org_sid`) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """DROP TABLE IF EXISTS `test_bitmap_t1`""" + sql """ + CREATE TABLE `test_bitmap_t1` ( + `org_sid` int(11) NOT NULL DEFAULT "0", + `ct_sid` int(11) NOT NULL DEFAULT "0", + `userid_bitmap` bitmap BITMAP_UNION NOT NULL + ) ENGINE=OLAP + AGGREGATE KEY(`org_sid`, `ct_sid`) + DISTRIBUTED BY HASH(`org_sid`) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO test_bitmap_t0 + (org_sid,ct_sid,userid_bitmap) + VALUES + (70018,70018,bitmap_from_string('1')), + (70019,70019,bitmap_from_string('')), + (70020,70020,bitmap_from_string('1,2')), + (70021,70021,bitmap_from_string('2')); + """ + + + sql """ + INSERT INTO test_bitmap_t1 + (org_sid,ct_sid,userid_bitmap) + VALUES + (70018,70018,bitmap_from_string('')), + (70019,70019,bitmap_from_string('1')), + (70020,70020,bitmap_from_string('1')), + (70022,70022,bitmap_from_string('2')); + """ + + qt_sql_bitmap_coalesce """ + with tmp as( + select + COALESCE (t0.org_sid ,t1.org_sid), + COALESCE (t0.ct_sid,t1.ct_sid) ct_sid, + t0.userid_bitmap userid_bitmap0, + t1.userid_bitmap userid_bitmap1, + bitmap_or( COALESCE(t0.userid_bitmap,bitmap_empty()) ,COALESCE(t1.userid_bitmap,bitmap_empty()) ) bitmap_or1 , + bitmap_or( t0.userid_bitmap ,t1.userid_bitmap ) bitmap_or2 + from + (select + org_sid ,ct_sid , userid_bitmap + from test_bitmap_t0 + ) t0 + full join + (select + org_sid, ct_sid, + bitmap_union( userid_bitmap) userid_bitmap + from test_bitmap_t1 + group by 1,2 + ) t1 on + t0.org_sid = t1.org_sid + and t0.ct_sid = t1.ct_sid + ) + select ct_sid, + concat("A", bitmap_to_string(userid_bitmap0)) bitmap0_str, + concat("A", bitmap_to_string(userid_bitmap1)) bitmap1_str, + concat("A", bitmap_to_string(bitmap_or1)) bitmap_or1_str, + concat("A", bitmap_to_string(bitmap_or2)) bitmap_or2_str, + bitmap_count(bitmap_or1) bitmap_or1_count, + bitmap_count(bitmap_or2) bitmap_or2_count + from tmp + order by ct_sid; + """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org