github-actions[bot] commented on code in PR #69286: URL: https://github.com/apache/doris/pull/69286#discussion_r4320711849
########## be/src/exprs/aggregate/aggregate_function_count_at_min_max.cpp: ########## @@ -0,0 +1,170 @@ +// 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. + +#include "exprs/aggregate/aggregate_function_count_at_min_max.h" + +#include "common/exception.h" +#include "core/data_type/data_type_nullable.h" +#include "core/data_type/define_primitive_type.h" +#include "core/data_type/primitive_type.h" +#include "exprs/aggregate/aggregate_function_simple_factory.h" +#include "exprs/aggregate/factory_helpers.h" +#include "exprs/aggregate/helpers.h" + +namespace doris { + +namespace { + +template <template <typename> class ExtremeData> +AggregateFunctionPtr create_aggregate_function_count_at_extreme(const String& name, + const DataTypes& argument_types, + const DataTypePtr& result_type, + const bool result_is_nullable, + const AggregateFunctionAttr& attr) { + assert_arity_range(name, argument_types, 1, 1); + switch (argument_types[0]->get_primitive_type()) { + case PrimitiveType::TYPE_STRING: + case PrimitiveType::TYPE_CHAR: + case PrimitiveType::TYPE_VARCHAR: + case PrimitiveType::TYPE_JSONB: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataString>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_DATE: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_DATE>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_DATETIME: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_DATETIME>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_DATEV2: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_DATEV2>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_DATETIMEV2: + return creator_without_type::create_unary_arguments<AggregateFunctionsCountAtExtreme< + ExtremeData<SingleValueDataFixed<TYPE_DATETIMEV2>>>>(argument_types, + result_is_nullable, attr); + case PrimitiveType::TYPE_TIMESTAMP_NS: + return creator_without_type::create_unary_arguments<AggregateFunctionsCountAtExtreme< + ExtremeData<SingleValueDataFixed<TYPE_TIMESTAMP_NS>>>>(argument_types, + result_is_nullable, attr); + case PrimitiveType::TYPE_TIMESTAMPTZ: + return creator_without_type::create_unary_arguments<AggregateFunctionsCountAtExtreme< + ExtremeData<SingleValueDataFixed<TYPE_TIMESTAMPTZ>>>>(argument_types, + result_is_nullable, attr); + case PrimitiveType::TYPE_TIMEV2: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_TIMEV2>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_IPV4: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_IPV4>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_IPV6: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_IPV6>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_UUID: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_UUID>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_BOOLEAN: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_BOOLEAN>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_TINYINT: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_TINYINT>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_SMALLINT: + return creator_without_type::create_unary_arguments< + AggregateFunctionsCountAtExtreme<ExtremeData<SingleValueDataFixed<TYPE_SMALLINT>>>>( + argument_types, result_is_nullable, attr); + case PrimitiveType::TYPE_INT: + return creator_without_type::create_unary_arguments< Review Comment: [P2] Preserve zero results in the foreach variants For an `ARRAY<INT>` column `a` containing `[1,NULL]` and `[2,NULL]`, both `count_at_min_foreach(a)` and `count_at_max_foreach(a)` produce `[1,NULL]` instead of `[1,0]`. The FE exposes these combinators automatically, and `foreachv2` requests `result_is_nullable=true` for its nested function. Forwarding that flag through `create_unary_arguments` installs a nullable-result adapter for the nullable array elements; an all-NULL position then emits NULL without calling the count state's zero-result insertion. Both old and V2 nullable adapters take this path. Use the nonnullable-result unary creator in all type branches (or otherwise preserve the nested aggregate's nonnullable semantics), and add an all-NULL-element regression for both variants. -- 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]
