dataroaring commented on code in PR #13056: URL: https://github.com/apache/doris/pull/13056#discussion_r989830599
########## be/src/exprs/aggregate_functions.cpp: ########## @@ -2534,6 +2535,97 @@ IntVal AggregateFunctions::window_funnel_finalize(FunctionContext* ctx, const St return doris_udf::IntVal(val); } +// Refer to AggregateFunctionRetention.h in https://github.com/ClickHouse/ClickHouse.git +struct RetentionState { + static constexpr size_t max_events = 32; + std::bitset<max_events> events; + + RetentionState() {} + + void add(int event) { events.set(event); } + + void merge(RetentionState* other) { events |= other->events; } + + BooleanVal* getRetentionData() { + static BooleanVal data_to[max_events]; + int current_offset = 0; + + const bool first_flag = events.test(0); + data_to[current_offset] = first_flag; + ++current_offset; + + for (size_t i = 1; i < events.size(); ++i) { + data_to[current_offset] = (first_flag && events.test(i)); + ++current_offset; + } + return data_to; + } + + int64_t serizlized_size() { return sizeof(events); } + + void serialize(uint8_t* buf) { + memcpy(buf, &events, sizeof(events)); Review Comment: bitset is a container, memcpy should not be used for serialized. ########## be/src/exprs/aggregate_functions.cpp: ########## @@ -2534,6 +2535,97 @@ IntVal AggregateFunctions::window_funnel_finalize(FunctionContext* ctx, const St return doris_udf::IntVal(val); } +// Refer to AggregateFunctionRetention.h in https://github.com/ClickHouse/ClickHouse.git +struct RetentionState { + static constexpr size_t max_events = 32; + std::bitset<max_events> events; + + RetentionState() {} + + void add(int event) { events.set(event); } + + void merge(RetentionState* other) { events |= other->events; } + + BooleanVal* getRetentionData() { + static BooleanVal data_to[max_events]; + int current_offset = 0; + + const bool first_flag = events.test(0); Review Comment: We should check if there are at least one element in events. ########## be/src/vec/aggregate_functions/aggregate_function_retention.h: ########## @@ -0,0 +1,116 @@ +// 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. + +// This file is copied from +// https://github.com/ClickHouse/ClickHouse/blob/master/AggregateFunctionRetention.h +// and modified by Doris + +#pragma once + +#include <bitset> + +#include "common/logging.h" +#include "vec/aggregate_functions/aggregate_function.h" +#include "vec/columns/column_array.h" +#include "vec/columns/columns_number.h" +#include "vec/data_types/data_type_array.h" +#include "vec/data_types/data_type_decimal.h" +#include "vec/io/var_int.h" + +namespace doris::vectorized { +struct RetentionState { + static constexpr size_t max_events = 32; + std::bitset<max_events> events; Review Comment: We can just use uint8_t events[max_events]; uint8 array can be vectorized. You can refer to https://llvm.org/docs/Vectorizers.html to look into vectorization report of clang. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org