Coverage Report

Created: 2026-07-29 19:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_uniq.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/AggregateFunctionUniq.cpp
19
// and modified by Doris
20
21
#include "exprs/aggregate/aggregate_function_uniq.h"
22
23
#include <string>
24
25
#include "common/exception.h"
26
#include "core/data_type/data_type.h"
27
#include "core/data_type/data_type_variant_v2.h"
28
#include "core/data_type/define_primitive_type.h"
29
#include "exec/common/hash_table/hash.h" // IWYU pragma: keep
30
#include "exprs/aggregate/aggregate_function_simple_factory.h"
31
#include "exprs/aggregate/helpers.h"
32
33
namespace doris {
34
35
template <template <PrimitiveType> class Data>
36
AggregateFunctionPtr create_aggregate_function_uniq(const std::string& name,
37
                                                    const DataTypes& argument_types,
38
                                                    const DataTypePtr& result_type,
39
                                                    const bool result_is_nullable,
40
1.41k
                                                    const AggregateFunctionAttr& attr) {
41
1.41k
    if (argument_types.size() == 1) {
42
1.41k
        const DataTypePtr argument_type = remove_nullable(argument_types[0]);
43
1.41k
        if (argument_type->get_primitive_type() == TYPE_VARIANT) {
44
2
            if (dynamic_cast<const DataTypeVariantV2*>(argument_type.get()) == nullptr) {
45
1
                throw Exception(
46
1
                        ErrorCode::INVALID_ARGUMENT,
47
1
                        "Aggregate function {} does not support legacy Variant; Variant V2 is "
48
1
                        "required",
49
1
                        name);
50
1
            }
51
1
            return creator_without_type::create<AggregateFunctionUniqVariant>(
52
1
                    argument_types, result_is_nullable, attr);
53
2
        }
54
1.41k
    }
55
1.41k
    return creator_with_type_list<
56
1.41k
            TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, TYPE_LARGEINT,
57
1.41k
            TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMAL256, TYPE_VARCHAR,
58
1.41k
            TYPE_ARRAY, TYPE_FLOAT, TYPE_DOUBLE, TYPE_DATEV2, TYPE_DATETIMEV2, TYPE_TIMESTAMPTZ,
59
1.41k
            TYPE_VARBINARY>::create<AggregateFunctionUniq, Data>(argument_types, result_is_nullable,
60
1.41k
                                                                 attr);
61
1.41k
}
62
63
5
void register_aggregate_function_uniq(AggregateFunctionSimpleFactory& factory) {
64
5
    AggregateFunctionCreator creator =
65
5
            create_aggregate_function_uniq<AggregateFunctionUniqExactData>;
66
5
    factory.register_function_both("multi_distinct_count", creator);
67
5
}
68
69
} // namespace doris