Coverage Report

Created: 2026-09-15 07:17

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.59k
                                                    const AggregateFunctionAttr& attr) {
41
1.59k
    if (argument_types.size() == 1) {
42
1.59k
        const DataTypePtr argument_type = remove_nullable(argument_types[0]);
43
1.59k
        if (argument_type->get_primitive_type() == TYPE_VARIANT) {
44
2
            DORIS_CHECK(dynamic_cast<const DataTypeVariantV2*>(argument_type.get()) != nullptr);
45
2
            return creator_without_type::create<AggregateFunctionUniqVariant>(
46
2
                    argument_types, result_is_nullable, attr);
47
2
        }
48
1.59k
    }
49
1.59k
    return creator_with_type_list<
50
1.59k
            TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, TYPE_LARGEINT,
51
1.59k
            TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMAL256, TYPE_VARCHAR,
52
1.59k
            TYPE_ARRAY, TYPE_FLOAT, TYPE_DOUBLE, TYPE_DATEV2, TYPE_DATETIMEV2, TYPE_TIMESTAMP_NS,
53
1.59k
            TYPE_TIMESTAMPTZ, TYPE_VARBINARY,
54
1.59k
            TYPE_UUID>::create<AggregateFunctionUniq, Data>(argument_types, result_is_nullable,
55
1.59k
                                                            attr);
56
1.59k
}
57
58
7
void register_aggregate_function_uniq(AggregateFunctionSimpleFactory& factory) {
59
7
    AggregateFunctionCreator creator =
60
7
            create_aggregate_function_uniq<AggregateFunctionUniqExactData>;
61
7
    factory.register_function_both("multi_distinct_count", creator);
62
7
}
63
64
} // namespace doris