Coverage Report

Created: 2026-09-09 14:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/common/agg_utils.h
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
18
#pragma once
19
20
#include <utility>
21
#include <variant>
22
#include <vector>
23
24
#include "core/arena.h"
25
#include "exec/common/hash_table/hash_map_context.h"
26
#include "exec/common/hash_table/hash_map_util.h"
27
#include "exec/common/hash_table/ph_hash_map.h"
28
#include "exec/common/hash_table/string_hash_map.h"
29
30
namespace doris {
31
32
template <typename PostCreate, typename Rollback>
33
void commit_aggregate_state(AggregateDataPtr& mapped, AggregateDataPtr new_state,
34
1
                            PostCreate&& post_create, Rollback&& rollback) {
35
1
    try {
36
1
        std::forward<PostCreate>(post_create)();
37
1
    } catch (...) {
38
0
        std::forward<Rollback>(rollback)(new_state);
39
0
        throw;
40
0
    }
41
1
    mapped = new_state;
42
1
}
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhS2_9HashCRC32IhEEEEEEEEEEbOT_ENKUlRSU_E_clIS2_EEDaSW_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_IST_EEbSV_ENKSY_IS2_EEDaSW_EUlPSU_E_EEvRS2_S2_SV_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItS2_9HashCRC32ItEEEEEEEEEEbOT_ENKUlRSU_E_clIS2_EEDaSW_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_IST_EEbSV_ENKSY_IS2_EEDaSW_EUlPSU_E_EEvRS2_S2_SV_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjS2_9HashCRC32IjEEEEEEEEEEbOT_ENKUlRSU_E_clIS2_EEDaSW_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_IST_EEbSV_ENKSY_IS2_EEDaSW_EUlPSU_E_EEvRS2_S2_SV_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImS2_9HashCRC32ImEEEEEEEEEEbOT_ENKUlRSU_E_clIS2_EEDaSW_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_IST_EEbSV_ENKSY_IS2_EEDaSW_EUlPSU_E_EEvRS2_S2_SV_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjS2_14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEbOT_ENKUlRSW_E_clIS2_EEDaSY_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_ISV_EEbSX_ENKS10_IS2_EEDaSY_EUlPSW_E_EEvRS2_S2_SX_OT0_
unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImS2_14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEbOT_ENKUlRSW_E_clIS2_EEDaSY_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_ISV_EEbSX_ENKS10_IS2_EEDaSY_EUlPSW_E_EEvRS2_S2_SX_OT0_
Line
Count
Source
34
1
                            PostCreate&& post_create, Rollback&& rollback) {
35
1
    try {
36
1
        std::forward<PostCreate>(post_create)();
37
1
    } catch (...) {
38
0
        std::forward<Rollback>(rollback)(new_state);
39
0
        throw;
40
0
    }
41
1
    mapped = new_state;
42
1
}
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapISN_S2_9HashCRC32ISN_EEEEEEEEEEbOT_ENKUlRSX_E_clIS2_EEDaSZ_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_ISW_EEbSY_ENKS11_IS2_EEDaSZ_EUlPSX_E_EEvRS2_S2_SY_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapISN_S2_9HashCRC32ISN_EEEEEEEEEEbOT_ENKUlRSX_E_clIS2_EEDaSZ_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_ISW_EEbSY_ENKS11_IS2_EEDaSZ_EUlPSX_E_EEvRS2_S2_SY_OT0_
Unexecuted instantiation: unity_1_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_17AggSinkLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERKSt6vectorIiSaIiEERS6_IPKNS_7IColumnESaISD_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIS2_NS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEbOT_ENKUlRSV_E_clIS2_EEDaSX_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SA_SG_jENKSI_ISU_EEbSW_ENKSZ_IS2_EEDaSX_EUlPSV_E_EEvRS2_S2_SW_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhS2_9HashCRC32IhEEEEEEEEEEbOT_ENKUlRSQ_E_clIS2_EEDaSS_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISP_EEbSR_ENKSU_IS2_EEDaSS_EUlPSQ_E_EEvRS2_S2_SR_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItS2_9HashCRC32ItEEEEEEEEEEbOT_ENKUlRSQ_E_clIS2_EEDaSS_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISP_EEbSR_ENKSU_IS2_EEDaSS_EUlPSQ_E_EEvRS2_S2_SR_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjS2_9HashCRC32IjEEEEEEEEEEbOT_ENKUlRSQ_E_clIS2_EEDaSS_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISP_EEbSR_ENKSU_IS2_EEDaSS_EUlPSQ_E_EEvRS2_S2_SR_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImS2_9HashCRC32ImEEEEEEEEEEbOT_ENKUlRSQ_E_clIS2_EEDaSS_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISP_EEbSR_ENKSU_IS2_EEDaSS_EUlPSQ_E_EEvRS2_S2_SR_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjS2_14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEbOT_ENKUlRSS_E_clIS2_EEDaSU_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISR_EEbST_ENKSW_IS2_EEDaSU_EUlPSS_E_EEvRS2_S2_ST_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImS2_14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEbOT_ENKUlRSS_E_clIS2_EEDaSU_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISR_EEbST_ENKSW_IS2_EEDaSU_EUlPSS_E_EEvRS2_S2_ST_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapISJ_S2_9HashCRC32ISJ_EEEEEEEEEEbOT_ENKUlRST_E_clIS2_EEDaSV_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISS_EEbSU_ENKSX_IS2_EEDaSV_EUlPST_E_EEvRS2_S2_SU_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapISJ_S2_9HashCRC32ISJ_EEEEEEEEEEbOT_ENKUlRST_E_clIS2_EEDaSV_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISS_EEbSU_ENKSX_IS2_EEDaSV_EUlPST_E_EEvRS2_S2_SU_OT0_
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris22commit_aggregate_stateIZZZNS_22StreamingAggLocalState30_emplace_into_hash_table_limitEPPcPNS_5BlockERSt6vectorIPKNS_7IColumnESaIS9_EEjENK3$_1clIRNS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIS2_NS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEbOT_ENKUlRSR_E_clIS2_EEDaST_EUlvE_ZZZNS1_30_emplace_into_hash_table_limitES3_S5_SC_jENKSE_ISQ_EEbSS_ENKSV_IS2_EEDaST_EUlPSR_E_EEvRS2_S2_SS_OT0_
43
44
template <typename T>
45
using AggData = PHHashMap<T, AggregateDataPtr, HashCRC32<T>>;
46
template <typename T>
47
using AggDataNullable = DataWithNullKey<AggData<T>>;
48
49
using AggregatedDataWithoutKey = AggregateDataPtr;
50
using AggregatedDataWithStringKey = PHHashMap<StringRef, AggregateDataPtr>;
51
using AggregatedDataWithShortStringKey = StringHashMap<AggregateDataPtr>;
52
53
using AggregatedDataWithUInt32KeyPhase2 =
54
        PHHashMap<UInt32, AggregateDataPtr, HashMixWrapper<UInt32>>;
55
using AggregatedDataWithUInt64KeyPhase2 =
56
        PHHashMap<UInt64, AggregateDataPtr, HashMixWrapper<UInt64>>;
57
58
using AggregatedDataWithNullableUInt32KeyPhase2 =
59
        DataWithNullKey<AggregatedDataWithUInt32KeyPhase2>;
60
using AggregatedDataWithNullableUInt64KeyPhase2 =
61
        DataWithNullKey<AggregatedDataWithUInt64KeyPhase2>;
62
using AggregatedDataWithNullableShortStringKey = DataWithNullKey<AggregatedDataWithShortStringKey>;
63
using AggregatedDataWithNullableStringKey = DataWithNullKey<AggregatedDataWithStringKey>;
64
65
/// Parameterized method variant for aggregation hash tables.
66
/// StringData / NullableStringData control which hash map is used for string keys:
67
///   - AggregatedDataVariants uses StringHashMap (AggregatedDataWithShortStringKey)
68
///   - BucketedAggDataVariants uses PHHashMap<StringRef> (AggregatedDataWithStringKey)
69
///     to avoid StringHashMap's sub-table complexity and unify the emplace interface.
70
template <typename StringData, typename NullableStringData>
71
using AggMethodVariantsBase = std::variant<
72
        std::monostate, MethodSerialized<AggregatedDataWithStringKey>,
73
        MethodOneNumber<UInt8, AggData<UInt8>>, MethodOneNumber<UInt16, AggData<UInt16>>,
74
        MethodOneNumber<UInt32, AggData<UInt32>>, MethodOneNumber<UInt64, AggData<UInt64>>,
75
        MethodStringNoCache<StringData>, MethodOneNumber<UInt128, AggData<UInt128>>,
76
        MethodOneNumber<UInt256, AggData<UInt256>>,
77
        MethodOneNumber<UInt32, AggregatedDataWithUInt32KeyPhase2>,
78
        MethodOneNumber<UInt64, AggregatedDataWithUInt64KeyPhase2>,
79
        MethodSingleNullableColumn<MethodOneNumber<UInt8, AggDataNullable<UInt8>>>,
80
        MethodSingleNullableColumn<MethodOneNumber<UInt16, AggDataNullable<UInt16>>>,
81
        MethodSingleNullableColumn<MethodOneNumber<UInt32, AggDataNullable<UInt32>>>,
82
        MethodSingleNullableColumn<MethodOneNumber<UInt64, AggDataNullable<UInt64>>>,
83
        MethodSingleNullableColumn<
84
                MethodOneNumber<UInt32, AggregatedDataWithNullableUInt32KeyPhase2>>,
85
        MethodSingleNullableColumn<
86
                MethodOneNumber<UInt64, AggregatedDataWithNullableUInt64KeyPhase2>>,
87
        MethodSingleNullableColumn<MethodOneNumber<UInt128, AggDataNullable<UInt128>>>,
88
        MethodSingleNullableColumn<MethodOneNumber<UInt256, AggDataNullable<UInt256>>>,
89
        MethodSingleNullableColumn<MethodStringNoCache<NullableStringData>>,
90
        MethodKeysFixed<AggData<UInt64>>, MethodKeysFixed<AggData<UInt72>>,
91
        MethodKeysFixed<AggData<UInt96>>, MethodKeysFixed<AggData<UInt104>>,
92
        MethodKeysFixed<AggData<UInt128>>, MethodKeysFixed<AggData<UInt136>>,
93
        MethodKeysFixed<AggData<UInt256>>>;
94
95
using AggregatedMethodVariants = AggMethodVariantsBase<AggregatedDataWithShortStringKey,
96
                                                       AggregatedDataWithNullableShortStringKey>;
97
98
/// Bucketed agg uses PHHashMap<StringRef> for string keys instead of StringHashMap.
99
/// This avoids StringHashMap's sub-table complexity and unifies the emplace interface
100
/// (3-arg PHHashMap::emplace), while still using HashMethodString for correct
101
/// single-column string key extraction.
102
using BucketedAggMethodVariants =
103
        AggMethodVariantsBase<AggregatedDataWithStringKey, AggregatedDataWithNullableStringKey>;
104
105
/// Intermediate base that adds the shared init logic for aggregation data
106
/// variants.  Only the string_key case differs between AggregatedDataVariants
107
/// and BucketedAggDataVariants; all other key types are identical.  The
108
/// StringData/NullableStringData template parameters control which hash map
109
/// type is emplaced for string_key.
110
template <typename MethodVariants, typename StringData, typename NullableStringData>
111
struct AggDataVariantsBase : public DataVariants<MethodVariants, MethodSingleNullableColumn,
112
                                                 MethodOneNumber, DataWithNullKey> {
113
20.4M
    void init_agg_data(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
114
20.5M
        bool nullable = data_types.size() == 1 && data_types[0]->is_nullable();
115
116
20.4M
        switch (type) {
117
1
        case HashKeyType::without_key:
118
1
            break;
119
15.7k
        case HashKeyType::serialized:
120
15.7k
            this->method_variant.template emplace<MethodSerialized<AggregatedDataWithStringKey>>();
121
15.7k
            break;
122
3.13k
        case HashKeyType::int8_key:
123
3.13k
            this->template emplace_single<UInt8, AggData<UInt8>>(nullable);
124
3.13k
            break;
125
4.79k
        case HashKeyType::int16_key:
126
4.79k
            this->template emplace_single<UInt16, AggData<UInt16>>(nullable);
127
4.79k
            break;
128
25.1k
        case HashKeyType::int32_key:
129
25.1k
            this->template emplace_single<UInt32, AggData<UInt32>>(nullable);
130
25.1k
            break;
131
14.2k
        case HashKeyType::int32_key_phase2:
132
14.2k
            this->template emplace_single<UInt32, AggregatedDataWithUInt32KeyPhase2>(nullable);
133
14.2k
            break;
134
20.2M
        case HashKeyType::int64_key:
135
20.2M
            this->template emplace_single<UInt64, AggData<UInt64>>(nullable);
136
20.2M
            break;
137
3.06k
        case HashKeyType::int64_key_phase2:
138
3.06k
            this->template emplace_single<UInt64, AggregatedDataWithUInt64KeyPhase2>(nullable);
139
3.06k
            break;
140
1.01k
        case HashKeyType::int128_key:
141
1.01k
            this->template emplace_single<UInt128, AggData<UInt128>>(nullable);
142
1.01k
            break;
143
5
        case HashKeyType::int256_key:
144
5
            this->template emplace_single<UInt256, AggData<UInt256>>(nullable);
145
5
            break;
146
31.0k
        case HashKeyType::string_key:
147
31.0k
            if (nullable) {
148
13.5k
                this->method_variant.template emplace<
149
13.5k
                        MethodSingleNullableColumn<MethodStringNoCache<NullableStringData>>>();
150
17.5k
            } else {
151
17.5k
                this->method_variant.template emplace<MethodStringNoCache<StringData>>();
152
17.5k
            }
153
31.0k
            break;
154
2.57k
        case HashKeyType::fixed64:
155
2.57k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt64>>>(
156
2.57k
                    get_key_sizes(data_types));
157
2.57k
            break;
158
1.58k
        case HashKeyType::fixed72:
159
1.58k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt72>>>(
160
1.58k
                    get_key_sizes(data_types));
161
1.58k
            break;
162
866
        case HashKeyType::fixed96:
163
866
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt96>>>(
164
866
                    get_key_sizes(data_types));
165
866
            break;
166
2.31k
        case HashKeyType::fixed104:
167
2.31k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt104>>>(
168
2.31k
                    get_key_sizes(data_types));
169
2.31k
            break;
170
112
        case HashKeyType::fixed128:
171
112
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt128>>>(
172
112
                    get_key_sizes(data_types));
173
112
            break;
174
4.15k
        case HashKeyType::fixed136:
175
4.15k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt136>>>(
176
4.15k
                    get_key_sizes(data_types));
177
4.15k
            break;
178
6.56k
        case HashKeyType::fixed256:
179
6.56k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt256>>>(
180
6.56k
                    get_key_sizes(data_types));
181
6.56k
            break;
182
1
        default:
183
1
            throw Exception(ErrorCode::INTERNAL_ERROR, "meet invalid agg key type, type={}", type);
184
20.4M
        }
185
20.4M
    }
_ZN5doris19AggDataVariantsBaseISt7variantIJSt9monostateNS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS5_vEEEENS_15MethodOneNumberIhS4_IhS6_9HashCRC32IhEEEENSB_ItS4_ItS6_SC_ItEEEENSB_IjS4_IjS6_SC_IjEEEENSB_ImS4_ImS6_SC_ImEEEENS_19MethodStringNoCacheINS_13StringHashMapIS6_NS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEENSB_IN4wide7integerILm128EjEES4_ISY_S6_SC_ISY_EEEENSB_INSX_ILm256EjEES4_IS12_S6_SC_IS12_EEEENSB_IjS4_IjS6_14HashMixWrapperIjSJ_EEEENSB_ImS4_ImS6_S16_ImSM_EEEENS_26MethodSingleNullableColumnINSB_IhNS_15DataWithNullKeyISE_EEEEEENS1D_INSB_ItNS1E_ISH_EEEEEENS1D_INSB_IjNS1E_ISK_EEEEEENS1D_INSB_ImNS1E_ISN_EEEEEENS1D_INSB_IjNS1E_IS18_EEEEEENS1D_INSB_ImNS1E_IS1B_EEEEEENS1D_INSB_ISY_NS1E_IS10_EEEEEENS1D_INSB_IS12_NS1E_IS14_EEEEEENS1D_INSP_INS1E_ISU_EEEEEENS_15MethodKeysFixedISN_EENS26_IS4_INS_6UInt72ES6_SC_IS28_EEEENS26_IS4_INS_6UInt96ES6_SC_IS2C_EEEENS26_IS4_INS_7UInt104ES6_SC_IS2G_EEEENS26_IS10_EENS26_IS4_INS_7UInt136ES6_SC_IS2L_EEEENS26_IS14_EEEESU_S23_E13init_agg_dataERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS2W_EENS_11HashKeyTypeE
Line
Count
Source
113
45.9k
    void init_agg_data(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
114
45.9k
        bool nullable = data_types.size() == 1 && data_types[0]->is_nullable();
115
116
45.9k
        switch (type) {
117
1
        case HashKeyType::without_key:
118
1
            break;
119
8.34k
        case HashKeyType::serialized:
120
8.34k
            this->method_variant.template emplace<MethodSerialized<AggregatedDataWithStringKey>>();
121
8.34k
            break;
122
2.36k
        case HashKeyType::int8_key:
123
2.36k
            this->template emplace_single<UInt8, AggData<UInt8>>(nullable);
124
2.36k
            break;
125
445
        case HashKeyType::int16_key:
126
445
            this->template emplace_single<UInt16, AggData<UInt16>>(nullable);
127
445
            break;
128
3.12k
        case HashKeyType::int32_key:
129
3.12k
            this->template emplace_single<UInt32, AggData<UInt32>>(nullable);
130
3.12k
            break;
131
14.2k
        case HashKeyType::int32_key_phase2:
132
14.2k
            this->template emplace_single<UInt32, AggregatedDataWithUInt32KeyPhase2>(nullable);
133
14.2k
            break;
134
992
        case HashKeyType::int64_key:
135
992
            this->template emplace_single<UInt64, AggData<UInt64>>(nullable);
136
992
            break;
137
3.06k
        case HashKeyType::int64_key_phase2:
138
3.06k
            this->template emplace_single<UInt64, AggregatedDataWithUInt64KeyPhase2>(nullable);
139
3.06k
            break;
140
504
        case HashKeyType::int128_key:
141
504
            this->template emplace_single<UInt128, AggData<UInt128>>(nullable);
142
504
            break;
143
5
        case HashKeyType::int256_key:
144
5
            this->template emplace_single<UInt256, AggData<UInt256>>(nullable);
145
5
            break;
146
4.12k
        case HashKeyType::string_key:
147
4.12k
            if (nullable) {
148
3.30k
                this->method_variant.template emplace<
149
3.30k
                        MethodSingleNullableColumn<MethodStringNoCache<NullableStringData>>>();
150
3.30k
            } else {
151
822
                this->method_variant.template emplace<MethodStringNoCache<StringData>>();
152
822
            }
153
4.12k
            break;
154
786
        case HashKeyType::fixed64:
155
786
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt64>>>(
156
786
                    get_key_sizes(data_types));
157
786
            break;
158
1.32k
        case HashKeyType::fixed72:
159
1.32k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt72>>>(
160
1.32k
                    get_key_sizes(data_types));
161
1.32k
            break;
162
610
        case HashKeyType::fixed96:
163
610
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt96>>>(
164
610
                    get_key_sizes(data_types));
165
610
            break;
166
519
        case HashKeyType::fixed104:
167
519
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt104>>>(
168
519
                    get_key_sizes(data_types));
169
519
            break;
170
112
        case HashKeyType::fixed128:
171
112
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt128>>>(
172
112
                    get_key_sizes(data_types));
173
112
            break;
174
2.36k
        case HashKeyType::fixed136:
175
2.36k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt136>>>(
176
2.36k
                    get_key_sizes(data_types));
177
2.36k
            break;
178
3.06k
        case HashKeyType::fixed256:
179
3.06k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt256>>>(
180
3.06k
                    get_key_sizes(data_types));
181
3.06k
            break;
182
1
        default:
183
1
            throw Exception(ErrorCode::INTERNAL_ERROR, "meet invalid agg key type, type={}", type);
184
45.9k
        }
185
45.9k
    }
_ZN5doris19AggDataVariantsBaseISt7variantIJSt9monostateNS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS5_vEEEENS_15MethodOneNumberIhS4_IhS6_9HashCRC32IhEEEENSB_ItS4_ItS6_SC_ItEEEENSB_IjS4_IjS6_SC_IjEEEENSB_ImS4_ImS6_SC_ImEEEENS_19MethodStringNoCacheIS9_EENSB_IN4wide7integerILm128EjEES4_IST_S6_SC_IST_EEEENSB_INSS_ILm256EjEES4_ISX_S6_SC_ISX_EEEENSB_IjS4_IjS6_14HashMixWrapperIjSJ_EEEENSB_ImS4_ImS6_S11_ImSM_EEEENS_26MethodSingleNullableColumnINSB_IhNS_15DataWithNullKeyISE_EEEEEENS18_INSB_ItNS19_ISH_EEEEEENS18_INSB_IjNS19_ISK_EEEEEENS18_INSB_ImNS19_ISN_EEEEEENS18_INSB_IjNS19_IS13_EEEEEENS18_INSB_ImNS19_IS16_EEEEEENS18_INSB_IST_NS19_ISV_EEEEEENS18_INSB_ISX_NS19_ISZ_EEEEEENS18_INSP_INS19_IS9_EEEEEENS_15MethodKeysFixedISN_EENS21_IS4_INS_6UInt72ES6_SC_IS23_EEEENS21_IS4_INS_6UInt96ES6_SC_IS27_EEEENS21_IS4_INS_7UInt104ES6_SC_IS2B_EEEENS21_ISV_EENS21_IS4_INS_7UInt136ES6_SC_IS2G_EEEENS21_ISZ_EEEES9_S1Y_E13init_agg_dataERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS2R_EENS_11HashKeyTypeE
Line
Count
Source
113
20.3M
    void init_agg_data(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
114
20.5M
        bool nullable = data_types.size() == 1 && data_types[0]->is_nullable();
115
116
20.3M
        switch (type) {
117
0
        case HashKeyType::without_key:
118
0
            break;
119
7.42k
        case HashKeyType::serialized:
120
7.42k
            this->method_variant.template emplace<MethodSerialized<AggregatedDataWithStringKey>>();
121
7.42k
            break;
122
768
        case HashKeyType::int8_key:
123
768
            this->template emplace_single<UInt8, AggData<UInt8>>(nullable);
124
768
            break;
125
4.35k
        case HashKeyType::int16_key:
126
4.35k
            this->template emplace_single<UInt16, AggData<UInt16>>(nullable);
127
4.35k
            break;
128
22.0k
        case HashKeyType::int32_key:
129
22.0k
            this->template emplace_single<UInt32, AggData<UInt32>>(nullable);
130
22.0k
            break;
131
0
        case HashKeyType::int32_key_phase2:
132
0
            this->template emplace_single<UInt32, AggregatedDataWithUInt32KeyPhase2>(nullable);
133
0
            break;
134
20.2M
        case HashKeyType::int64_key:
135
20.2M
            this->template emplace_single<UInt64, AggData<UInt64>>(nullable);
136
20.2M
            break;
137
0
        case HashKeyType::int64_key_phase2:
138
0
            this->template emplace_single<UInt64, AggregatedDataWithUInt64KeyPhase2>(nullable);
139
0
            break;
140
512
        case HashKeyType::int128_key:
141
512
            this->template emplace_single<UInt128, AggData<UInt128>>(nullable);
142
512
            break;
143
0
        case HashKeyType::int256_key:
144
0
            this->template emplace_single<UInt256, AggData<UInt256>>(nullable);
145
0
            break;
146
26.8k
        case HashKeyType::string_key:
147
26.8k
            if (nullable) {
148
10.1k
                this->method_variant.template emplace<
149
10.1k
                        MethodSingleNullableColumn<MethodStringNoCache<NullableStringData>>>();
150
16.6k
            } else {
151
16.6k
                this->method_variant.template emplace<MethodStringNoCache<StringData>>();
152
16.6k
            }
153
26.8k
            break;
154
1.79k
        case HashKeyType::fixed64:
155
1.79k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt64>>>(
156
1.79k
                    get_key_sizes(data_types));
157
1.79k
            break;
158
256
        case HashKeyType::fixed72:
159
256
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt72>>>(
160
256
                    get_key_sizes(data_types));
161
256
            break;
162
256
        case HashKeyType::fixed96:
163
256
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt96>>>(
164
256
                    get_key_sizes(data_types));
165
256
            break;
166
1.79k
        case HashKeyType::fixed104:
167
1.79k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt104>>>(
168
1.79k
                    get_key_sizes(data_types));
169
1.79k
            break;
170
0
        case HashKeyType::fixed128:
171
0
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt128>>>(
172
0
                    get_key_sizes(data_types));
173
0
            break;
174
1.79k
        case HashKeyType::fixed136:
175
1.79k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt136>>>(
176
1.79k
                    get_key_sizes(data_types));
177
1.79k
            break;
178
3.50k
        case HashKeyType::fixed256:
179
3.50k
            this->method_variant.template emplace<MethodKeysFixed<AggData<UInt256>>>(
180
3.50k
                    get_key_sizes(data_types));
181
3.50k
            break;
182
0
        default:
183
0
            throw Exception(ErrorCode::INTERNAL_ERROR, "meet invalid agg key type, type={}", type);
184
20.3M
        }
185
20.3M
    }
186
};
187
188
struct AggregatedDataVariants
189
        : public AggDataVariantsBase<AggregatedMethodVariants, AggregatedDataWithShortStringKey,
190
                                     AggregatedDataWithNullableShortStringKey> {
191
    AggregatedDataWithoutKey without_key = nullptr;
192
193
    bool is_fixed_key = true;
194
195
46.0k
    void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
196
46.0k
        is_fixed_key = !(type == HashKeyType::without_key || type == HashKeyType::EMPTY ||
197
46.0k
                         type == HashKeyType::serialized || type == HashKeyType::string_key);
198
46.0k
        this->init_agg_data(data_types, type);
199
46.0k
    }
200
};
201
202
using AggregatedDataVariantsUPtr = std::unique_ptr<AggregatedDataVariants>;
203
using ArenaUPtr = std::unique_ptr<Arena>;
204
205
/// Data variants for bucketed hash aggregation.
206
/// Uses BucketedAggMethodVariants (PHHashMap for string keys).
207
struct BucketedAggDataVariants
208
        : public AggDataVariantsBase<BucketedAggMethodVariants, AggregatedDataWithStringKey,
209
                                     AggregatedDataWithNullableStringKey> {
210
21.9M
    void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
211
21.9M
        this->init_agg_data(data_types, type);
212
21.9M
    }
213
};
214
215
using BucketedAggDataVariantsUPtr = std::unique_ptr<BucketedAggDataVariants>;
216
217
struct AggregateDataContainer {
218
public:
219
    AggregateDataContainer(size_t size_of_key, size_t size_of_aggregate_states)
220
45.0k
            : _size_of_key(size_of_key), _size_of_aggregate_states(size_of_aggregate_states) {}
221
222
42.4k
    int64_t memory_usage() const { return _arena_pool.size(); }
223
224
    template <typename KeyType>
225
3.15M
    AggregateDataPtr append_data(const KeyType& key) {
226
3.15M
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
3.15M
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
20.6k
            _expand();
230
20.6k
        }
231
232
3.15M
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
3.15M
        auto* aggregate_data = _current_agg_data;
234
3.15M
        ++_total_count;
235
3.15M
        ++_index_in_sub_container;
236
3.15M
        _current_agg_data += _size_of_aggregate_states;
237
3.15M
        _current_keys += _size_of_key;
238
3.15M
        return aggregate_data;
239
3.15M
    }
_ZN5doris22AggregateDataContainer11append_dataINS_9StringRefEEEPcRKT_
Line
Count
Source
225
93.8k
    AggregateDataPtr append_data(const KeyType& key) {
226
93.8k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
93.8k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
4.84k
            _expand();
230
4.84k
        }
231
232
93.8k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
93.8k
        auto* aggregate_data = _current_agg_data;
234
93.8k
        ++_total_count;
235
93.8k
        ++_index_in_sub_container;
236
93.8k
        _current_agg_data += _size_of_aggregate_states;
237
93.8k
        _current_keys += _size_of_key;
238
93.8k
        return aggregate_data;
239
93.8k
    }
_ZN5doris22AggregateDataContainer11append_dataIhEEPcRKT_
Line
Count
Source
225
3.06k
    AggregateDataPtr append_data(const KeyType& key) {
226
3.06k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
3.06k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
1.52k
            _expand();
230
1.52k
        }
231
232
3.06k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
3.06k
        auto* aggregate_data = _current_agg_data;
234
3.06k
        ++_total_count;
235
3.06k
        ++_index_in_sub_container;
236
3.06k
        _current_agg_data += _size_of_aggregate_states;
237
3.06k
        _current_keys += _size_of_key;
238
3.06k
        return aggregate_data;
239
3.06k
    }
_ZN5doris22AggregateDataContainer11append_dataItEEPcRKT_
Line
Count
Source
225
299
    AggregateDataPtr append_data(const KeyType& key) {
226
299
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
299
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
145
            _expand();
230
145
        }
231
232
299
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
299
        auto* aggregate_data = _current_agg_data;
234
299
        ++_total_count;
235
299
        ++_index_in_sub_container;
236
299
        _current_agg_data += _size_of_aggregate_states;
237
299
        _current_keys += _size_of_key;
238
299
        return aggregate_data;
239
299
    }
_ZN5doris22AggregateDataContainer11append_dataIjEEPcRKT_
Line
Count
Source
225
2.76M
    AggregateDataPtr append_data(const KeyType& key) {
226
2.76M
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
2.76M
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
9.49k
            _expand();
230
9.49k
        }
231
232
2.76M
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
2.76M
        auto* aggregate_data = _current_agg_data;
234
2.76M
        ++_total_count;
235
2.76M
        ++_index_in_sub_container;
236
2.76M
        _current_agg_data += _size_of_aggregate_states;
237
2.76M
        _current_keys += _size_of_key;
238
2.76M
        return aggregate_data;
239
2.76M
    }
_ZN5doris22AggregateDataContainer11append_dataImEEPcRKT_
Line
Count
Source
225
259k
    AggregateDataPtr append_data(const KeyType& key) {
226
259k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
259k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
1.55k
            _expand();
230
1.55k
        }
231
232
259k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
259k
        auto* aggregate_data = _current_agg_data;
234
259k
        ++_total_count;
235
259k
        ++_index_in_sub_container;
236
259k
        _current_agg_data += _size_of_aggregate_states;
237
259k
        _current_keys += _size_of_key;
238
259k
        return aggregate_data;
239
259k
    }
_ZN5doris22AggregateDataContainer11append_dataIN4wide7integerILm128EjEEEEPcRKT_
Line
Count
Source
225
16.6k
    AggregateDataPtr append_data(const KeyType& key) {
226
16.6k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
16.6k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
180
            _expand();
230
180
        }
231
232
16.6k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
16.6k
        auto* aggregate_data = _current_agg_data;
234
16.6k
        ++_total_count;
235
16.6k
        ++_index_in_sub_container;
236
16.6k
        _current_agg_data += _size_of_aggregate_states;
237
16.6k
        _current_keys += _size_of_key;
238
16.6k
        return aggregate_data;
239
16.6k
    }
_ZN5doris22AggregateDataContainer11append_dataIN4wide7integerILm256EjEEEEPcRKT_
Line
Count
Source
225
6.36k
    AggregateDataPtr append_data(const KeyType& key) {
226
6.36k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
6.36k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
659
            _expand();
230
659
        }
231
232
6.36k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
6.36k
        auto* aggregate_data = _current_agg_data;
234
6.36k
        ++_total_count;
235
6.36k
        ++_index_in_sub_container;
236
6.36k
        _current_agg_data += _size_of_aggregate_states;
237
6.36k
        _current_keys += _size_of_key;
238
6.36k
        return aggregate_data;
239
6.36k
    }
_ZN5doris22AggregateDataContainer11append_dataINS_6UInt72EEEPcRKT_
Line
Count
Source
225
1.01k
    AggregateDataPtr append_data(const KeyType& key) {
226
1.01k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
1.01k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
470
            _expand();
230
470
        }
231
232
1.01k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
1.01k
        auto* aggregate_data = _current_agg_data;
234
1.01k
        ++_total_count;
235
1.01k
        ++_index_in_sub_container;
236
1.01k
        _current_agg_data += _size_of_aggregate_states;
237
1.01k
        _current_keys += _size_of_key;
238
1.01k
        return aggregate_data;
239
1.01k
    }
_ZN5doris22AggregateDataContainer11append_dataINS_6UInt96EEEPcRKT_
Line
Count
Source
225
7.69k
    AggregateDataPtr append_data(const KeyType& key) {
226
7.69k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
7.69k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
576
            _expand();
230
576
        }
231
232
7.69k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
7.69k
        auto* aggregate_data = _current_agg_data;
234
7.69k
        ++_total_count;
235
7.69k
        ++_index_in_sub_container;
236
7.69k
        _current_agg_data += _size_of_aggregate_states;
237
7.69k
        _current_keys += _size_of_key;
238
7.69k
        return aggregate_data;
239
7.69k
    }
_ZN5doris22AggregateDataContainer11append_dataINS_7UInt104EEEPcRKT_
Line
Count
Source
225
616
    AggregateDataPtr append_data(const KeyType& key) {
226
616
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
616
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
304
            _expand();
230
304
        }
231
232
616
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
616
        auto* aggregate_data = _current_agg_data;
234
616
        ++_total_count;
235
616
        ++_index_in_sub_container;
236
616
        _current_agg_data += _size_of_aggregate_states;
237
616
        _current_keys += _size_of_key;
238
616
        return aggregate_data;
239
616
    }
_ZN5doris22AggregateDataContainer11append_dataINS_7UInt136EEEPcRKT_
Line
Count
Source
225
2.45k
    AggregateDataPtr append_data(const KeyType& key) {
226
2.45k
        DCHECK_EQ(sizeof(KeyType), _size_of_key);
227
        // SUB_CONTAINER_CAPACITY should add a new sub container, and also expand when it is zero
228
2.45k
        if (UNLIKELY(_index_in_sub_container % SUB_CONTAINER_CAPACITY == 0)) {
229
909
            _expand();
230
909
        }
231
232
2.45k
        *reinterpret_cast<KeyType*>(_current_keys) = key;
233
2.45k
        auto* aggregate_data = _current_agg_data;
234
2.45k
        ++_total_count;
235
2.45k
        ++_index_in_sub_container;
236
2.45k
        _current_agg_data += _size_of_aggregate_states;
237
2.45k
        _current_keys += _size_of_key;
238
2.45k
        return aggregate_data;
239
2.45k
    }
240
241
    template <typename Derived, bool IsConst>
242
    class IteratorBase {
243
        using Container =
244
                std::conditional_t<IsConst, const AggregateDataContainer, AggregateDataContainer>;
245
246
        Container* container = nullptr;
247
        uint32_t index;
248
        uint32_t sub_container_index;
249
        uint32_t index_in_sub_container;
250
251
        friend class HashTable;
252
253
    public:
254
45.0k
        IteratorBase() = default;
255
        IteratorBase(Container* container_, uint32_t index_)
256
2.97M
                : container(container_), index(index_) {
257
2.97M
            sub_container_index = index / SUB_CONTAINER_CAPACITY;
258
2.97M
            index_in_sub_container = index - sub_container_index * SUB_CONTAINER_CAPACITY;
259
2.97M
        }
260
261
43.6k
        bool operator==(const IteratorBase& rhs) const { return index == rhs.index; }
262
2.88M
        bool operator!=(const IteratorBase& rhs) const { return index != rhs.index; }
263
264
2.85M
        Derived& operator++() {
265
2.85M
            index++;
266
2.85M
            index_in_sub_container++;
267
2.85M
            if (index_in_sub_container == SUB_CONTAINER_CAPACITY) {
268
267
                index_in_sub_container = 0;
269
267
                sub_container_index++;
270
267
            }
271
2.85M
            return static_cast<Derived&>(*this);
272
2.85M
        }
273
274
        template <typename KeyType>
275
2.82M
        KeyType get_key() {
276
2.82M
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
2.82M
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
2.82M
                    [index_in_sub_container];
279
2.82M
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyINS_9StringRefEEET_v
Line
Count
Source
275
94.6k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
94.6k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
94.6k
                    [index_in_sub_container];
279
94.6k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyIhEET_v
Line
Count
Source
275
3.07k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
3.07k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
3.07k
                    [index_in_sub_container];
279
3.07k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyItEET_v
Line
Count
Source
275
299
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
299
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
299
                    [index_in_sub_container];
279
299
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyIjEET_v
Line
Count
Source
275
2.45M
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
2.45M
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
2.45M
                    [index_in_sub_container];
279
2.45M
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyImEET_v
Line
Count
Source
275
228k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
228k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
228k
                    [index_in_sub_container];
279
228k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyIN4wide7integerILm128EjEEEET_v
Line
Count
Source
275
16.4k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
16.4k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
16.4k
                    [index_in_sub_container];
279
16.4k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyIN4wide7integerILm256EjEEEET_v
Line
Count
Source
275
9.90k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
9.90k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
9.90k
                    [index_in_sub_container];
279
9.90k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyINS_6UInt72EEET_v
Line
Count
Source
275
1.01k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
1.01k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
1.01k
                    [index_in_sub_container];
279
1.01k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyINS_6UInt96EEET_v
Line
Count
Source
275
7.73k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
7.73k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
7.73k
                    [index_in_sub_container];
279
7.73k
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyINS_7UInt104EEET_v
Line
Count
Source
275
613
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
613
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
613
                    [index_in_sub_container];
279
613
        }
_ZN5doris22AggregateDataContainer12IteratorBaseINS0_8IteratorELb0EE7get_keyINS_7UInt136EEET_v
Line
Count
Source
275
2.43k
        KeyType get_key() {
276
            DCHECK_EQ(sizeof(KeyType), container->_size_of_key);
277
2.43k
            return ((KeyType*)(container->_key_containers[sub_container_index]))
278
2.43k
                    [index_in_sub_container];
279
2.43k
        }
280
281
2.83M
        AggregateDataPtr get_aggregate_data() {
282
2.83M
            return &(container->_value_containers[sub_container_index]
283
2.83M
                                                 [container->_size_of_aggregate_states *
284
2.83M
                                                  index_in_sub_container]);
285
2.83M
        }
286
    };
287
288
    class Iterator : public IteratorBase<Iterator, false> {
289
    public:
290
        using IteratorBase<Iterator, false>::IteratorBase;
291
    };
292
293
    class ConstIterator : public IteratorBase<ConstIterator, true> {
294
    public:
295
        using IteratorBase<ConstIterator, true>::IteratorBase;
296
    };
297
298
    ConstIterator begin() const { return {this, 0}; }
299
300
    ConstIterator cbegin() const { return begin(); }
301
302
43.6k
    Iterator begin() { return {this, 0}; }
303
304
    ConstIterator end() const { return {this, _total_count}; }
305
    ConstIterator cend() const { return end(); }
306
2.93M
    Iterator end() { return {this, _total_count}; }
307
308
10
    [[nodiscard]] uint32_t total_count() const { return _total_count; }
309
310
19
    size_t estimate_memory(size_t rows) const {
311
19
        bool need_to_expand = false;
312
19
        if (_total_count == 0) {
313
1
            need_to_expand = true;
314
18
        } else if ((_index_in_sub_container + rows) > SUB_CONTAINER_CAPACITY) {
315
2
            need_to_expand = true;
316
2
            rows -= (SUB_CONTAINER_CAPACITY - _index_in_sub_container);
317
2
        }
318
319
19
        if (!need_to_expand) {
320
16
            return 0;
321
16
        }
322
323
3
        size_t count = (rows + SUB_CONTAINER_CAPACITY - 1) / SUB_CONTAINER_CAPACITY;
324
3
        size_t size = _size_of_key * SUB_CONTAINER_CAPACITY;
325
3
        size += _size_of_aggregate_states * SUB_CONTAINER_CAPACITY;
326
3
        size *= count;
327
3
        return size;
328
19
    }
329
330
43.7k
    void init_once() {
331
43.7k
        if (_inited) {
332
324
            return;
333
324
        }
334
43.4k
        _inited = true;
335
43.4k
        iterator = begin();
336
43.4k
    }
337
    Iterator iterator;
338
339
private:
340
20.6k
    void _expand() {
341
20.6k
        _index_in_sub_container = 0;
342
20.6k
        _current_keys = nullptr;
343
20.6k
        _current_agg_data = nullptr;
344
20.6k
        try {
345
20.6k
            _current_keys = _arena_pool.alloc(_size_of_key * SUB_CONTAINER_CAPACITY);
346
20.6k
            _key_containers.emplace_back(_current_keys);
347
348
20.6k
            _current_agg_data = (AggregateDataPtr)_arena_pool.alloc(_size_of_aggregate_states *
349
20.6k
                                                                    SUB_CONTAINER_CAPACITY);
350
20.6k
            _value_containers.emplace_back(_current_agg_data);
351
20.6k
        } catch (...) {
352
0
            if (_current_keys) {
353
0
                _key_containers.pop_back();
354
0
                _current_keys = nullptr;
355
0
            }
356
0
            if (_current_agg_data) {
357
0
                _value_containers.pop_back();
358
0
                _current_agg_data = nullptr;
359
0
            }
360
0
            throw;
361
0
        }
362
20.6k
    }
363
364
    static constexpr uint32_t SUB_CONTAINER_CAPACITY = 8192;
365
    Arena _arena_pool;
366
    std::vector<char*> _key_containers;
367
    std::vector<AggregateDataPtr> _value_containers;
368
    AggregateDataPtr _current_agg_data = nullptr;
369
    char* _current_keys = nullptr;
370
    size_t _size_of_key {};
371
    size_t _size_of_aggregate_states {};
372
    uint32_t _index_in_sub_container {};
373
    uint32_t _total_count {};
374
    bool _inited = false;
375
};
376
} // namespace doris