github-actions[bot] commented on code in PR #62668: URL: https://github.com/apache/doris/pull/62668#discussion_r3115920841
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/RetentionV2.java: ########## @@ -0,0 +1,110 @@ +// 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. + +package org.apache.doris.nereids.trees.expressions.functions.agg; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.BooleanType; +import org.apache.doris.nereids.util.ExpressionUtils; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * AggregateFunction 'retention_v2'. + * Optimized version of retention using a uint32_t bitmask state on the BE side. + * The serialization format is incompatible with retention (v1), so this function + * should only be used when all BE nodes have been upgraded. + */ +public class RetentionV2 extends NullableAggregateFunction + implements ExplicitlyCastableSignature { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).varArgs(BooleanType.INSTANCE) + ); + + /** + * constructor with 1 or more arguments. + */ + public RetentionV2(Expression arg, Expression... varArgs) { + this(false, arg, varArgs); + } + + /** + * constructor with 1 or more arguments. + */ + public RetentionV2(boolean distinct, Expression arg, Expression... varArgs) { + this(distinct, false, arg, varArgs); + } + + public RetentionV2(boolean distinct, boolean alwaysNullable, Expression arg, + Expression... varArgs) { + super("retention_v2", distinct, alwaysNullable, ExpressionUtils.mergeArguments(arg, varArgs)); + } + + /** constructor for withChildren and reuse signature */ + private RetentionV2(NullableAggregateFunctionParams functionParams) { + super(functionParams); Review Comment: `retention_v2` still needs an explicit upper-bound check for the number of event arguments. `RetentionStateV2` only has 32 bits, but this legality check currently accepts any number of boolean params. A query like `retention_v2(e1, ..., e33)` will make BE execute `1u << 32` in `RetentionStateV2::set()` and later `events >> i` for `i >= 32` in `insert_result_into()`, which is undefined behavior. Please reject `children.size() > 32` here and add a BE-side creator check as well (similar to `window_funnel_v2` / `sequence_match`) so malformed or legacy callers cannot bypass FE validation. A negative FE/regression test for the 33-arg case should go with that fix. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
