Coverage Report

Created: 2025-12-30 14:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/tablet_schema.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
18
#include "olap/tablet_schema.h"
19
20
#include <gen_cpp/Descriptors_types.h>
21
#include <gen_cpp/olap_file.pb.h>
22
#include <glog/logging.h>
23
#include <google/protobuf/io/coded_stream.h>
24
#include <google/protobuf/io/zero_copy_stream.h>
25
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
26
27
#include <algorithm>
28
#include <cctype>
29
// IWYU pragma: no_include <bits/std_abs.h>
30
#include <cmath> // IWYU pragma: keep
31
#include <memory>
32
#include <ostream>
33
#include <vector>
34
35
#include "common/compiler_util.h" // IWYU pragma: keep
36
#include "common/consts.h"
37
#include "common/status.h"
38
#include "exec/tablet_info.h"
39
#include "olap/inverted_index_parser.h"
40
#include "olap/olap_common.h"
41
#include "olap/olap_define.h"
42
#include "olap/tablet_column_object_pool.h"
43
#include "olap/types.h"
44
#include "olap/utils.h"
45
#include "tablet_meta.h"
46
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
47
#include "vec/aggregate_functions/aggregate_function_state_union.h"
48
#include "vec/columns/column_nothing.h"
49
#include "vec/common/hex.h"
50
#include "vec/common/string_ref.h"
51
#include "vec/core/block.h"
52
#include "vec/data_types/data_type.h"
53
#include "vec/data_types/data_type_factory.hpp"
54
#include "vec/json/path_in_data.h"
55
56
namespace doris {
57
#include "common/compile_check_begin.h"
58
68.6k
FieldType TabletColumn::get_field_type_by_type(PrimitiveType primitiveType) {
59
68.6k
    switch (primitiveType) {
60
0
    case PrimitiveType::INVALID_TYPE:
61
0
        return FieldType::OLAP_FIELD_TYPE_UNKNOWN;
62
0
    case PrimitiveType::TYPE_NULL:
63
0
        return FieldType::OLAP_FIELD_TYPE_NONE;
64
0
    case PrimitiveType::TYPE_BOOLEAN:
65
0
        return FieldType::OLAP_FIELD_TYPE_BOOL;
66
68.5k
    case PrimitiveType::TYPE_TINYINT:
67
68.5k
        return FieldType::OLAP_FIELD_TYPE_TINYINT;
68
69
    case PrimitiveType::TYPE_SMALLINT:
69
69
        return FieldType::OLAP_FIELD_TYPE_SMALLINT;
70
7
    case PrimitiveType::TYPE_INT:
71
7
        return FieldType::OLAP_FIELD_TYPE_INT;
72
6
    case PrimitiveType::TYPE_BIGINT:
73
6
        return FieldType::OLAP_FIELD_TYPE_BIGINT;
74
0
    case PrimitiveType::TYPE_LARGEINT:
75
0
        return FieldType::OLAP_FIELD_TYPE_LARGEINT;
76
0
    case PrimitiveType::TYPE_FLOAT:
77
0
        return FieldType::OLAP_FIELD_TYPE_FLOAT;
78
12
    case PrimitiveType::TYPE_DOUBLE:
79
12
        return FieldType::OLAP_FIELD_TYPE_DOUBLE;
80
0
    case PrimitiveType::TYPE_VARCHAR:
81
0
        return FieldType::OLAP_FIELD_TYPE_VARCHAR;
82
0
    case PrimitiveType::TYPE_DATE:
83
0
        return FieldType::OLAP_FIELD_TYPE_DATE;
84
0
    case PrimitiveType::TYPE_DATETIME:
85
0
        return FieldType::OLAP_FIELD_TYPE_DATETIME;
86
0
    case PrimitiveType::TYPE_BINARY:
87
0
        return FieldType::OLAP_FIELD_TYPE_UNKNOWN; // Not implemented
88
0
    case PrimitiveType::TYPE_CHAR:
89
0
        return FieldType::OLAP_FIELD_TYPE_CHAR;
90
0
    case PrimitiveType::TYPE_STRUCT:
91
0
        return FieldType::OLAP_FIELD_TYPE_STRUCT;
92
0
    case PrimitiveType::TYPE_ARRAY:
93
0
        return FieldType::OLAP_FIELD_TYPE_ARRAY;
94
0
    case PrimitiveType::TYPE_MAP:
95
0
        return FieldType::OLAP_FIELD_TYPE_MAP;
96
0
    case PrimitiveType::TYPE_HLL:
97
0
        return FieldType::OLAP_FIELD_TYPE_HLL;
98
0
    case PrimitiveType::TYPE_DECIMALV2:
99
0
        return FieldType::OLAP_FIELD_TYPE_UNKNOWN; // Not implemented
100
0
    case PrimitiveType::TYPE_BITMAP:
101
0
        return FieldType::OLAP_FIELD_TYPE_BITMAP;
102
0
    case PrimitiveType::TYPE_STRING:
103
0
        return FieldType::OLAP_FIELD_TYPE_STRING;
104
0
    case PrimitiveType::TYPE_QUANTILE_STATE:
105
0
        return FieldType::OLAP_FIELD_TYPE_QUANTILE_STATE;
106
0
    case PrimitiveType::TYPE_DATEV2:
107
0
        return FieldType::OLAP_FIELD_TYPE_DATEV2;
108
0
    case PrimitiveType::TYPE_DATETIMEV2:
109
0
        return FieldType::OLAP_FIELD_TYPE_DATETIMEV2;
110
0
    case PrimitiveType::TYPE_TIMESTAMPTZ:
111
0
        return FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ;
112
0
    case PrimitiveType::TYPE_TIMEV2:
113
0
        return FieldType::OLAP_FIELD_TYPE_TIMEV2;
114
0
    case PrimitiveType::TYPE_DECIMAL32:
115
0
        return FieldType::OLAP_FIELD_TYPE_DECIMAL32;
116
0
    case PrimitiveType::TYPE_DECIMAL64:
117
0
        return FieldType::OLAP_FIELD_TYPE_DECIMAL64;
118
0
    case PrimitiveType::TYPE_DECIMAL128I:
119
0
        return FieldType::OLAP_FIELD_TYPE_DECIMAL128I;
120
0
    case PrimitiveType::TYPE_DECIMAL256:
121
0
        return FieldType::OLAP_FIELD_TYPE_DECIMAL256;
122
0
    case PrimitiveType::TYPE_JSONB:
123
0
        return FieldType::OLAP_FIELD_TYPE_JSONB;
124
0
    case PrimitiveType::TYPE_VARIANT:
125
0
        return FieldType::OLAP_FIELD_TYPE_VARIANT;
126
0
    case PrimitiveType::TYPE_IPV4:
127
0
        return FieldType::OLAP_FIELD_TYPE_IPV4;
128
0
    case PrimitiveType::TYPE_IPV6:
129
0
        return FieldType::OLAP_FIELD_TYPE_IPV6;
130
0
    case PrimitiveType::TYPE_LAMBDA_FUNCTION:
131
0
        return FieldType::OLAP_FIELD_TYPE_UNKNOWN; // Not implemented
132
0
    case PrimitiveType::TYPE_AGG_STATE:
133
0
        return FieldType::OLAP_FIELD_TYPE_AGG_STATE;
134
0
    default:
135
0
        return FieldType::OLAP_FIELD_TYPE_UNKNOWN;
136
68.6k
    }
137
68.6k
}
138
139
25.0k
PrimitiveType TabletColumn::get_primitive_type_by_field_type(FieldType type) {
140
25.0k
    static const PrimitiveType mapping[] = {
141
25.0k
            /*  0 */ PrimitiveType::INVALID_TYPE,
142
25.0k
            /*  1 OLAP_FIELD_TYPE_TINYINT           */ PrimitiveType::TYPE_TINYINT,
143
25.0k
            /*  2 OLAP_FIELD_TYPE_UNSIGNED_TINYINT  */ PrimitiveType::INVALID_TYPE,
144
25.0k
            /*  3 OLAP_FIELD_TYPE_SMALLINT          */ PrimitiveType::TYPE_SMALLINT,
145
25.0k
            /*  4 OLAP_FIELD_TYPE_UNSIGNED_SMALLINT */ PrimitiveType::INVALID_TYPE,
146
25.0k
            /*  5 OLAP_FIELD_TYPE_INT               */ PrimitiveType::TYPE_INT,
147
25.0k
            /*  6 OLAP_FIELD_TYPE_UNSIGNED_INT      */ PrimitiveType::INVALID_TYPE,
148
25.0k
            /*  7 OLAP_FIELD_TYPE_BIGINT            */ PrimitiveType::TYPE_BIGINT,
149
25.0k
            /*  8 OLAP_FIELD_TYPE_UNSIGNED_BIGINT   */ PrimitiveType::INVALID_TYPE,
150
25.0k
            /*  9 OLAP_FIELD_TYPE_LARGEINT          */ PrimitiveType::TYPE_LARGEINT,
151
25.0k
            /* 10 OLAP_FIELD_TYPE_FLOAT             */ PrimitiveType::TYPE_FLOAT,
152
25.0k
            /* 11 OLAP_FIELD_TYPE_DOUBLE            */ PrimitiveType::TYPE_DOUBLE,
153
25.0k
            /* 12 OLAP_FIELD_TYPE_DISCRETE_DOUBLE   */ PrimitiveType::INVALID_TYPE,
154
25.0k
            /* 13 OLAP_FIELD_TYPE_CHAR              */ PrimitiveType::TYPE_CHAR,
155
25.0k
            /* 14 OLAP_FIELD_TYPE_DATE              */ PrimitiveType::TYPE_DATE,
156
25.0k
            /* 15 OLAP_FIELD_TYPE_DATETIME          */ PrimitiveType::TYPE_DATETIME,
157
25.0k
            /* 16 OLAP_FIELD_TYPE_DECIMAL           */ PrimitiveType::INVALID_TYPE,
158
25.0k
            /* 17 OLAP_FIELD_TYPE_VARCHAR           */ PrimitiveType::TYPE_VARCHAR,
159
25.0k
            /* 18 OLAP_FIELD_TYPE_STRUCT            */ PrimitiveType::TYPE_STRUCT,
160
25.0k
            /* 19 OLAP_FIELD_TYPE_ARRAY             */ PrimitiveType::TYPE_ARRAY,
161
25.0k
            /* 20 OLAP_FIELD_TYPE_MAP               */ PrimitiveType::TYPE_MAP,
162
25.0k
            /* 21 OLAP_FIELD_TYPE_UNKNOWN           */ PrimitiveType::INVALID_TYPE,
163
25.0k
            /* 22 OLAP_FIELD_TYPE_NONE              */ PrimitiveType::TYPE_NULL,
164
25.0k
            /* 23 OLAP_FIELD_TYPE_HLL               */ PrimitiveType::TYPE_HLL,
165
25.0k
            /* 24 OLAP_FIELD_TYPE_BOOL              */ PrimitiveType::TYPE_BOOLEAN,
166
25.0k
            /* 25 OLAP_FIELD_TYPE_BITMAP            */ PrimitiveType::TYPE_BITMAP,
167
25.0k
            /* 26 OLAP_FIELD_TYPE_STRING            */ PrimitiveType::TYPE_STRING,
168
25.0k
            /* 27 OLAP_FIELD_TYPE_QUANTILE_STATE    */ PrimitiveType::TYPE_QUANTILE_STATE,
169
25.0k
            /* 28 OLAP_FIELD_TYPE_DATEV2            */ PrimitiveType::TYPE_DATEV2,
170
25.0k
            /* 29 OLAP_FIELD_TYPE_DATETIMEV2        */ PrimitiveType::TYPE_DATETIMEV2,
171
25.0k
            /* 30 OLAP_FIELD_TYPE_TIMEV2            */ PrimitiveType::TYPE_TIMEV2,
172
25.0k
            /* 31 OLAP_FIELD_TYPE_DECIMAL32         */ PrimitiveType::TYPE_DECIMAL32,
173
25.0k
            /* 32 OLAP_FIELD_TYPE_DECIMAL64         */ PrimitiveType::TYPE_DECIMAL64,
174
25.0k
            /* 33 OLAP_FIELD_TYPE_DECIMAL128I       */ PrimitiveType::TYPE_DECIMAL128I,
175
25.0k
            /* 34 OLAP_FIELD_TYPE_JSONB             */ PrimitiveType::TYPE_JSONB,
176
25.0k
            /* 35 OLAP_FIELD_TYPE_VARIANT           */ PrimitiveType::TYPE_VARIANT,
177
25.0k
            /* 36 OLAP_FIELD_TYPE_AGG_STATE         */ PrimitiveType::TYPE_AGG_STATE,
178
25.0k
            /* 37 OLAP_FIELD_TYPE_DECIMAL256        */ PrimitiveType::TYPE_DECIMAL256,
179
25.0k
            /* 38 OLAP_FIELD_TYPE_IPV4              */ PrimitiveType::TYPE_IPV4,
180
25.0k
            /* 39 OLAP_FIELD_TYPE_IPV6              */ PrimitiveType::TYPE_IPV6,
181
25.0k
            /* 40 OLAP_FIELD_TYPE_TIMESTAMPTZ       */ PrimitiveType::TYPE_TIMESTAMPTZ,
182
25.0k
    };
183
184
25.0k
    int idx = static_cast<int>(type);
185
25.0k
    return mapping[idx];
186
25.0k
}
187
188
12.4k
FieldType TabletColumn::get_field_type_by_string(const std::string& type_str) {
189
12.4k
    std::string upper_type_str = type_str;
190
12.4k
    std::transform(type_str.begin(), type_str.end(), upper_type_str.begin(),
191
69.9k
                   [](auto c) { return std::toupper(c); });
192
12.4k
    FieldType type;
193
194
12.4k
    if (0 == upper_type_str.compare("TINYINT")) {
195
435
        type = FieldType::OLAP_FIELD_TYPE_TINYINT;
196
12.0k
    } else if (0 == upper_type_str.compare("SMALLINT")) {
197
885
        type = FieldType::OLAP_FIELD_TYPE_SMALLINT;
198
11.1k
    } else if (0 == upper_type_str.compare("INT")) {
199
2.58k
        type = FieldType::OLAP_FIELD_TYPE_INT;
200
8.57k
    } else if (0 == upper_type_str.compare("BIGINT")) {
201
188
        type = FieldType::OLAP_FIELD_TYPE_BIGINT;
202
8.38k
    } else if (0 == upper_type_str.compare("LARGEINT")) {
203
140
        type = FieldType::OLAP_FIELD_TYPE_LARGEINT;
204
8.24k
    } else if (0 == upper_type_str.compare("UNSIGNED_TINYINT")) {
205
0
        type = FieldType::OLAP_FIELD_TYPE_UNSIGNED_TINYINT;
206
8.24k
    } else if (0 == upper_type_str.compare("UNSIGNED_SMALLINT")) {
207
0
        type = FieldType::OLAP_FIELD_TYPE_UNSIGNED_SMALLINT;
208
8.24k
    } else if (0 == upper_type_str.compare("UNSIGNED_INT")) {
209
0
        type = FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT;
210
8.24k
    } else if (0 == upper_type_str.compare("UNSIGNED_BIGINT")) {
211
0
        type = FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT;
212
8.24k
    } else if (0 == upper_type_str.compare("IPV4")) {
213
17
        type = FieldType::OLAP_FIELD_TYPE_IPV4;
214
8.22k
    } else if (0 == upper_type_str.compare("IPV6")) {
215
17
        type = FieldType::OLAP_FIELD_TYPE_IPV6;
216
8.20k
    } else if (0 == upper_type_str.compare("FLOAT")) {
217
4
        type = FieldType::OLAP_FIELD_TYPE_FLOAT;
218
8.20k
    } else if (0 == upper_type_str.compare("DISCRETE_DOUBLE")) {
219
0
        type = FieldType::OLAP_FIELD_TYPE_DISCRETE_DOUBLE;
220
8.20k
    } else if (0 == upper_type_str.compare("DOUBLE")) {
221
0
        type = FieldType::OLAP_FIELD_TYPE_DOUBLE;
222
8.20k
    } else if (0 == upper_type_str.compare("CHAR")) {
223
141
        type = FieldType::OLAP_FIELD_TYPE_CHAR;
224
8.06k
    } else if (0 == upper_type_str.compare("DATE")) {
225
143
        type = FieldType::OLAP_FIELD_TYPE_DATE;
226
7.92k
    } else if (0 == upper_type_str.compare("DATEV2")) {
227
133
        type = FieldType::OLAP_FIELD_TYPE_DATEV2;
228
7.78k
    } else if (0 == upper_type_str.compare("DATETIMEV2")) {
229
0
        type = FieldType::OLAP_FIELD_TYPE_DATETIMEV2;
230
7.78k
    } else if (0 == upper_type_str.compare("DATETIME")) {
231
172
        type = FieldType::OLAP_FIELD_TYPE_DATETIME;
232
7.61k
    } else if (0 == upper_type_str.compare("TIMESTAMPTZ")) {
233
16
        type = FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ;
234
7.60k
    } else if (0 == upper_type_str.compare("DECIMAL32")) {
235
0
        type = FieldType::OLAP_FIELD_TYPE_DECIMAL32;
236
7.60k
    } else if (0 == upper_type_str.compare("DECIMAL64")) {
237
0
        type = FieldType::OLAP_FIELD_TYPE_DECIMAL64;
238
7.60k
    } else if (0 == upper_type_str.compare("DECIMAL128I")) {
239
0
        type = FieldType::OLAP_FIELD_TYPE_DECIMAL128I;
240
7.60k
    } else if (0 == upper_type_str.compare("DECIMAL256")) {
241
0
        type = FieldType::OLAP_FIELD_TYPE_DECIMAL256;
242
7.60k
    } else if (0 == upper_type_str.compare(0, 7, "DECIMAL")) {
243
144
        type = FieldType::OLAP_FIELD_TYPE_DECIMAL;
244
7.45k
    } else if (0 == upper_type_str.compare(0, 7, "VARCHAR")) {
245
219
        type = FieldType::OLAP_FIELD_TYPE_VARCHAR;
246
7.23k
    } else if (0 == upper_type_str.compare("STRING")) {
247
7.17k
        type = FieldType::OLAP_FIELD_TYPE_STRING;
248
7.17k
    } else if (0 == upper_type_str.compare("JSONB")) {
249
0
        type = FieldType::OLAP_FIELD_TYPE_JSONB;
250
67
    } else if (0 == upper_type_str.compare("VARIANT")) {
251
54
        type = FieldType::OLAP_FIELD_TYPE_VARIANT;
252
54
    } else if (0 == upper_type_str.compare("BOOLEAN")) {
253
0
        type = FieldType::OLAP_FIELD_TYPE_BOOL;
254
13
    } else if (0 == upper_type_str.compare(0, 3, "HLL")) {
255
7
        type = FieldType::OLAP_FIELD_TYPE_HLL;
256
7
    } else if (0 == upper_type_str.compare("STRUCT")) {
257
0
        type = FieldType::OLAP_FIELD_TYPE_STRUCT;
258
6
    } else if (0 == upper_type_str.compare("LIST")) {
259
0
        type = FieldType::OLAP_FIELD_TYPE_ARRAY;
260
6
    } else if (0 == upper_type_str.compare("MAP")) {
261
0
        type = FieldType::OLAP_FIELD_TYPE_MAP;
262
6
    } else if (0 == upper_type_str.compare("OBJECT")) {
263
0
        type = FieldType::OLAP_FIELD_TYPE_BITMAP;
264
6
    } else if (0 == upper_type_str.compare("BITMAP")) {
265
0
        type = FieldType::OLAP_FIELD_TYPE_BITMAP;
266
6
    } else if (0 == upper_type_str.compare("ARRAY")) {
267
6
        type = FieldType::OLAP_FIELD_TYPE_ARRAY;
268
6
    } else if (0 == upper_type_str.compare("QUANTILE_STATE")) {
269
0
        type = FieldType::OLAP_FIELD_TYPE_QUANTILE_STATE;
270
0
    } else if (0 == upper_type_str.compare("AGG_STATE")) {
271
0
        type = FieldType::OLAP_FIELD_TYPE_AGG_STATE;
272
0
    } else {
273
0
        LOG(WARNING) << "invalid type string. [type='" << type_str << "']";
274
0
        type = FieldType::OLAP_FIELD_TYPE_UNKNOWN;
275
0
    }
276
277
12.4k
    return type;
278
12.4k
}
279
280
4.11k
FieldAggregationMethod TabletColumn::get_aggregation_type_by_string(const std::string& str) {
281
4.11k
    std::string upper_str = str;
282
4.11k
    std::transform(str.begin(), str.end(), upper_str.begin(),
283
21.1k
                   [](auto c) { return std::toupper(c); });
284
4.11k
    FieldAggregationMethod aggregation_type;
285
286
4.11k
    if (0 == upper_str.compare("NONE")) {
287
1.77k
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE;
288
2.34k
    } else if (0 == upper_str.compare("SUM")) {
289
594
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_SUM;
290
1.75k
    } else if (0 == upper_str.compare("MIN")) {
291
4
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MIN;
292
1.75k
    } else if (0 == upper_str.compare("MAX")) {
293
4
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MAX;
294
1.74k
    } else if (0 == upper_str.compare("REPLACE")) {
295
1.73k
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE;
296
1.73k
    } else if (0 == upper_str.compare("REPLACE_IF_NOT_NULL")) {
297
0
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE_IF_NOT_NULL;
298
7
    } else if (0 == upper_str.compare("HLL_UNION")) {
299
7
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_HLL_UNION;
300
7
    } else if (0 == upper_str.compare("BITMAP_UNION")) {
301
0
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_BITMAP_UNION;
302
0
    } else if (0 == upper_str.compare("QUANTILE_UNION")) {
303
0
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_QUANTILE_UNION;
304
0
    } else if (!upper_str.empty()) {
305
0
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_GENERIC;
306
0
    } else {
307
0
        aggregation_type = FieldAggregationMethod::OLAP_FIELD_AGGREGATION_UNKNOWN;
308
0
    }
309
310
4.11k
    return aggregation_type;
311
4.11k
}
312
313
32.3k
std::string TabletColumn::get_string_by_field_type(FieldType type) {
314
32.3k
    switch (type) {
315
1.68k
    case FieldType::OLAP_FIELD_TYPE_TINYINT:
316
1.68k
        return "TINYINT";
317
318
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_TINYINT:
319
0
        return "UNSIGNED_TINYINT";
320
321
3.69k
    case FieldType::OLAP_FIELD_TYPE_SMALLINT:
322
3.69k
        return "SMALLINT";
323
324
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_SMALLINT:
325
0
        return "UNSIGNED_SMALLINT";
326
327
9.02k
    case FieldType::OLAP_FIELD_TYPE_INT:
328
9.02k
        return "INT";
329
330
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT:
331
0
        return "UNSIGNED_INT";
332
333
904
    case FieldType::OLAP_FIELD_TYPE_BIGINT:
334
904
        return "BIGINT";
335
336
751
    case FieldType::OLAP_FIELD_TYPE_LARGEINT:
337
751
        return "LARGEINT";
338
339
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT:
340
0
        return "UNSIGNED_BIGINT";
341
342
147
    case FieldType::OLAP_FIELD_TYPE_IPV4:
343
147
        return "IPV4";
344
345
147
    case FieldType::OLAP_FIELD_TYPE_IPV6:
346
147
        return "IPV6";
347
348
10
    case FieldType::OLAP_FIELD_TYPE_FLOAT:
349
10
        return "FLOAT";
350
351
0
    case FieldType::OLAP_FIELD_TYPE_DOUBLE:
352
0
        return "DOUBLE";
353
354
0
    case FieldType::OLAP_FIELD_TYPE_DISCRETE_DOUBLE:
355
0
        return "DISCRETE_DOUBLE";
356
357
751
    case FieldType::OLAP_FIELD_TYPE_CHAR:
358
751
        return "CHAR";
359
360
755
    case FieldType::OLAP_FIELD_TYPE_DATE:
361
755
        return "DATE";
362
363
670
    case FieldType::OLAP_FIELD_TYPE_DATEV2:
364
670
        return "DATEV2";
365
366
948
    case FieldType::OLAP_FIELD_TYPE_DATETIME:
367
948
        return "DATETIME";
368
369
0
    case FieldType::OLAP_FIELD_TYPE_DATETIMEV2:
370
0
        return "DATETIMEV2";
371
372
142
    case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ:
373
142
        return "TIMESTAMPTZ";
374
375
751
    case FieldType::OLAP_FIELD_TYPE_DECIMAL:
376
751
        return "DECIMAL";
377
378
0
    case FieldType::OLAP_FIELD_TYPE_DECIMAL32:
379
0
        return "DECIMAL32";
380
381
0
    case FieldType::OLAP_FIELD_TYPE_DECIMAL64:
382
0
        return "DECIMAL64";
383
384
0
    case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
385
0
        return "DECIMAL128I";
386
387
0
    case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
388
0
        return "DECIMAL256";
389
390
1.01k
    case FieldType::OLAP_FIELD_TYPE_VARCHAR:
391
1.01k
        return "VARCHAR";
392
393
0
    case FieldType::OLAP_FIELD_TYPE_JSONB:
394
0
        return "JSONB";
395
396
129
    case FieldType::OLAP_FIELD_TYPE_VARIANT:
397
129
        return "VARIANT";
398
399
10.8k
    case FieldType::OLAP_FIELD_TYPE_STRING:
400
10.8k
        return "STRING";
401
402
0
    case FieldType::OLAP_FIELD_TYPE_BOOL:
403
0
        return "BOOLEAN";
404
405
6
    case FieldType::OLAP_FIELD_TYPE_HLL:
406
6
        return "HLL";
407
408
0
    case FieldType::OLAP_FIELD_TYPE_STRUCT:
409
0
        return "STRUCT";
410
411
14
    case FieldType::OLAP_FIELD_TYPE_ARRAY:
412
14
        return "ARRAY";
413
414
2
    case FieldType::OLAP_FIELD_TYPE_MAP:
415
2
        return "MAP";
416
417
0
    case FieldType::OLAP_FIELD_TYPE_BITMAP:
418
0
        return "OBJECT";
419
0
    case FieldType::OLAP_FIELD_TYPE_QUANTILE_STATE:
420
0
        return "QUANTILE_STATE";
421
0
    case FieldType::OLAP_FIELD_TYPE_AGG_STATE:
422
0
        return "AGG_STATE";
423
0
    default:
424
0
        return "UNKNOWN";
425
32.3k
    }
426
32.3k
}
427
428
1.72k
std::string TabletColumn::get_string_by_aggregation_type(FieldAggregationMethod type) {
429
1.72k
    switch (type) {
430
1.70k
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE:
431
1.70k
        return "NONE";
432
433
9
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_SUM:
434
9
        return "SUM";
435
436
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MIN:
437
0
        return "MIN";
438
439
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MAX:
440
0
        return "MAX";
441
442
15
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE:
443
15
        return "REPLACE";
444
445
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE_IF_NOT_NULL:
446
0
        return "REPLACE_IF_NOT_NULL";
447
448
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_HLL_UNION:
449
0
        return "HLL_UNION";
450
451
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_BITMAP_UNION:
452
0
        return "BITMAP_UNION";
453
454
0
    case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_QUANTILE_UNION:
455
0
        return "QUANTILE_UNION";
456
457
2
    default:
458
2
        return "UNKNOWN";
459
1.72k
    }
460
1.72k
}
461
462
2.22k
uint32_t TabletColumn::get_field_length_by_type(TPrimitiveType::type type, uint32_t string_length) {
463
2.22k
    switch (type) {
464
113
    case TPrimitiveType::TINYINT:
465
113
    case TPrimitiveType::BOOLEAN:
466
113
        return 1;
467
363
    case TPrimitiveType::SMALLINT:
468
363
        return 2;
469
847
    case TPrimitiveType::INT:
470
847
        return 4;
471
120
    case TPrimitiveType::BIGINT:
472
120
        return 8;
473
104
    case TPrimitiveType::LARGEINT:
474
104
        return 16;
475
16
    case TPrimitiveType::IPV4:
476
16
        return 4;
477
16
    case TPrimitiveType::IPV6:
478
16
        return 16;
479
104
    case TPrimitiveType::DATE:
480
104
        return 3;
481
92
    case TPrimitiveType::DATEV2:
482
92
        return 4;
483
112
    case TPrimitiveType::DATETIME:
484
112
        return 8;
485
0
    case TPrimitiveType::DATETIMEV2:
486
15
    case TPrimitiveType::TIMESTAMPTZ:
487
15
        return 8;
488
0
    case TPrimitiveType::FLOAT:
489
0
        return 4;
490
0
    case TPrimitiveType::DOUBLE:
491
0
        return 8;
492
0
    case TPrimitiveType::QUANTILE_STATE:
493
0
    case TPrimitiveType::BITMAP:
494
0
        return 16;
495
104
    case TPrimitiveType::CHAR:
496
104
        return string_length;
497
104
    case TPrimitiveType::VARCHAR:
498
104
    case TPrimitiveType::HLL:
499
104
    case TPrimitiveType::AGG_STATE:
500
104
        return string_length + sizeof(OLAP_VARCHAR_MAX_LENGTH);
501
4
    case TPrimitiveType::STRING:
502
4
    case TPrimitiveType::VARIANT:
503
4
        return string_length + sizeof(OLAP_STRING_MAX_LENGTH);
504
0
    case TPrimitiveType::JSONB:
505
0
        return string_length + sizeof(OLAP_JSONB_MAX_LENGTH);
506
0
    case TPrimitiveType::STRUCT:
507
        // Note that(xy): this is the length of struct type itself,
508
        // the length of its subtypes are not included.
509
0
        return OLAP_STRUCT_MAX_LENGTH;
510
7
    case TPrimitiveType::ARRAY:
511
7
        return OLAP_ARRAY_MAX_LENGTH;
512
0
    case TPrimitiveType::MAP:
513
0
        return OLAP_MAP_MAX_LENGTH;
514
0
    case TPrimitiveType::DECIMAL32:
515
0
        return 4;
516
0
    case TPrimitiveType::DECIMAL64:
517
0
        return 8;
518
0
    case TPrimitiveType::DECIMAL128I:
519
0
        return 16;
520
0
    case TPrimitiveType::DECIMAL256:
521
0
        return 32;
522
104
    case TPrimitiveType::DECIMALV2:
523
104
        return 12; // use 12 bytes in olap engine.
524
0
    default:
525
0
        LOG(WARNING) << "unknown field type. [type=" << type << "]";
526
0
        return 0;
527
2.22k
    }
528
2.22k
}
529
530
9
bool TabletColumn::has_char_type() const {
531
9
    switch (_type) {
532
3
    case FieldType::OLAP_FIELD_TYPE_CHAR: {
533
3
        return true;
534
0
    }
535
4
    case FieldType::OLAP_FIELD_TYPE_ARRAY:
536
4
    case FieldType::OLAP_FIELD_TYPE_MAP:
537
4
    case FieldType::OLAP_FIELD_TYPE_STRUCT: {
538
4
        return std::any_of(_sub_columns.begin(), _sub_columns.end(),
539
4
                           [&](const auto& sub) -> bool { return sub->has_char_type(); });
540
4
    }
541
2
    default:
542
2
        return false;
543
9
    }
544
9
}
545
546
18.3k
TabletColumn::TabletColumn() : _aggregation(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE) {}
547
548
37.6k
TabletColumn::TabletColumn(FieldAggregationMethod agg, FieldType type) {
549
37.6k
    _aggregation = agg;
550
37.6k
    _type = type;
551
37.6k
}
552
553
17
TabletColumn::TabletColumn(FieldAggregationMethod agg, FieldType filed_type, bool is_nullable) {
554
17
    _aggregation = agg;
555
17
    _type = filed_type;
556
17
    _length = cast_set<int32_t>(get_scalar_type_info(filed_type)->size());
557
17
    _is_nullable = is_nullable;
558
17
}
559
560
TabletColumn::TabletColumn(FieldAggregationMethod agg, FieldType filed_type, bool is_nullable,
561
346
                           int32_t unique_id, size_t length) {
562
346
    _aggregation = agg;
563
346
    _type = filed_type;
564
346
    _is_nullable = is_nullable;
565
346
    _unique_id = unique_id;
566
346
    _length = cast_set<int32_t>(length);
567
346
}
568
569
0
TabletColumn::TabletColumn(const ColumnPB& column) {
570
0
    init_from_pb(column);
571
0
}
572
573
4
TabletColumn::TabletColumn(const TColumn& column) {
574
4
    init_from_thrift(column);
575
4
}
576
577
5
void TabletColumn::init_from_thrift(const TColumn& tcolumn) {
578
5
    ColumnPB column_pb;
579
5
    TabletMeta::init_column_from_tcolumn(tcolumn.col_unique_id, tcolumn, &column_pb);
580
5
    init_from_pb(column_pb);
581
5
}
582
583
12.3k
void TabletColumn::init_from_pb(const ColumnPB& column) {
584
12.3k
    _unique_id = column.unique_id();
585
12.3k
    _col_name = column.name();
586
12.3k
    _col_name_lower_case = to_lower(_col_name);
587
12.3k
    _type = TabletColumn::get_field_type_by_string(column.type());
588
12.3k
    _is_key = column.is_key();
589
12.3k
    _is_nullable = column.is_nullable();
590
12.3k
    _is_auto_increment = column.is_auto_increment();
591
12.3k
    if (column.has_is_on_update_current_timestamp()) {
592
11.4k
        _is_on_update_current_timestamp = column.is_on_update_current_timestamp();
593
11.4k
    }
594
595
12.3k
    _has_default_value = column.has_default_value();
596
12.3k
    if (_has_default_value) {
597
30
        _default_value = column.default_value();
598
30
    }
599
600
12.3k
    if (column.has_precision()) {
601
4.06k
        _is_decimal = true;
602
4.06k
        _precision = column.precision();
603
8.33k
    } else {
604
8.33k
        _is_decimal = false;
605
8.33k
    }
606
12.3k
    if (column.has_frac()) {
607
4.06k
        _frac = column.frac();
608
4.06k
    }
609
12.3k
    _length = column.length();
610
12.3k
    _index_length = column.index_length();
611
12.3k
    if (column.has_is_bf_column()) {
612
419
        _is_bf_column = column.is_bf_column();
613
11.9k
    } else {
614
11.9k
        _is_bf_column = false;
615
11.9k
    }
616
12.3k
    if (column.has_aggregation()) {
617
4.11k
        _aggregation = get_aggregation_type_by_string(column.aggregation());
618
4.11k
        _aggregation_name = column.aggregation();
619
4.11k
    }
620
621
12.3k
    if (_type == FieldType::OLAP_FIELD_TYPE_AGG_STATE) {
622
0
        _result_is_nullable = column.result_is_nullable();
623
0
        _be_exec_version = column.be_exec_version();
624
0
    }
625
626
12.3k
    if (column.has_visible()) {
627
11.4k
        _visible = column.visible();
628
11.4k
    }
629
12.3k
    if (_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
630
6
        CHECK(column.children_columns_size() == 1)
631
0
                << "ARRAY type should has 1 children types, but got "
632
0
                << column.children_columns_size();
633
6
    }
634
12.3k
    if (_type == FieldType::OLAP_FIELD_TYPE_MAP) {
635
0
        DCHECK(column.children_columns_size() == 2)
636
0
                << "MAP type should has 2 children types, but got "
637
0
                << column.children_columns_size();
638
0
        if (UNLIKELY(column.children_columns_size() != 2)) {
639
0
            LOG(WARNING) << "MAP type should has 2 children types, but got "
640
0
                         << column.children_columns_size();
641
0
        }
642
0
    }
643
12.4k
    for (int i = 0; i < column.children_columns_size(); i++) {
644
10
        TabletColumn child_column;
645
10
        child_column.init_from_pb(column.children_columns(i));
646
10
        add_sub_column(child_column);
647
10
    }
648
12.3k
    if (column.has_column_path_info()) {
649
12
        _column_path = std::make_shared<vectorized::PathInData>();
650
12
        _column_path->from_protobuf(column.column_path_info());
651
12
        _parent_col_unique_id = column.column_path_info().parrent_column_unique_id();
652
12
    }
653
12.3k
    if (is_variant_type() && !column.has_column_path_info()) {
654
        // set path info for variant root column, to prevent from missing
655
42
        _column_path = std::make_shared<vectorized::PathInData>(_col_name_lower_case);
656
        // _parent_col_unique_id = _unique_id;
657
42
    }
658
12.3k
    if (column.has_variant_max_subcolumns_count()) {
659
11.4k
        _variant_max_subcolumns_count = column.variant_max_subcolumns_count();
660
11.4k
    }
661
12.3k
    if (column.has_variant_enable_typed_paths_to_sparse()) {
662
11.4k
        _variant_enable_typed_paths_to_sparse = column.variant_enable_typed_paths_to_sparse();
663
11.4k
    }
664
12.3k
    if (column.has_variant_max_sparse_column_statistics_size()) {
665
11.4k
        _variant_max_sparse_column_statistics_size =
666
11.4k
                column.variant_max_sparse_column_statistics_size();
667
11.4k
    }
668
12.3k
    if (column.has_variant_sparse_hash_shard_count()) {
669
9.20k
        _variant_sparse_hash_shard_count = column.variant_sparse_hash_shard_count();
670
9.20k
    }
671
12.3k
    if (column.has_pattern_type()) {
672
9.19k
        _pattern_type = column.pattern_type();
673
9.19k
    }
674
12.3k
}
675
676
TabletColumn TabletColumn::create_materialized_variant_column(const std::string& root,
677
                                                              const std::vector<std::string>& paths,
678
                                                              int32_t parent_unique_id,
679
0
                                                              int32_t max_subcolumns_count) {
680
0
    TabletColumn subcol;
681
0
    subcol.set_type(FieldType::OLAP_FIELD_TYPE_VARIANT);
682
0
    subcol.set_is_nullable(true);
683
0
    subcol.set_unique_id(-1);
684
0
    subcol.set_parent_unique_id(parent_unique_id);
685
0
    vectorized::PathInData path(root, paths);
686
0
    subcol.set_path_info(path);
687
0
    subcol.set_name(path.get_path());
688
0
    subcol.set_variant_max_subcolumns_count(max_subcolumns_count);
689
0
    return subcol;
690
0
}
691
692
32.3k
void TabletColumn::to_schema_pb(ColumnPB* column) const {
693
32.3k
    column->set_unique_id(_unique_id);
694
32.3k
    column->set_name(_col_name);
695
32.3k
    column->set_type(get_string_by_field_type(_type));
696
32.3k
    column->set_is_key(_is_key);
697
32.3k
    column->set_is_nullable(_is_nullable);
698
32.3k
    column->set_is_auto_increment(_is_auto_increment);
699
32.3k
    column->set_is_on_update_current_timestamp(_is_on_update_current_timestamp);
700
32.3k
    if (_has_default_value) {
701
156
        column->set_default_value(_default_value);
702
156
    }
703
32.3k
    if (_is_decimal) {
704
17.5k
        column->set_precision(_precision);
705
17.5k
        column->set_frac(_frac);
706
17.5k
    }
707
32.3k
    column->set_length(_length);
708
32.3k
    column->set_index_length(_index_length);
709
32.3k
    if (_is_bf_column) {
710
8
        column->set_is_bf_column(_is_bf_column);
711
8
    }
712
32.3k
    if (!_aggregation_name.empty()) {
713
17.7k
        column->set_aggregation(_aggregation_name);
714
17.7k
    }
715
32.3k
    column->set_result_is_nullable(_result_is_nullable);
716
32.3k
    column->set_be_exec_version(_be_exec_version);
717
32.3k
    column->set_visible(_visible);
718
719
32.3k
    if (_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
720
14
        CHECK(_sub_columns.size() == 1)
721
0
                << "ARRAY type should has 1 children types, but got " << _sub_columns.size();
722
14
    }
723
32.3k
    if (_type == FieldType::OLAP_FIELD_TYPE_MAP) {
724
0
        DCHECK(_sub_columns.size() == 2)
725
0
                << "MAP type should has 2 children types, but got " << _sub_columns.size();
726
0
        if (UNLIKELY(_sub_columns.size() != 2)) {
727
0
            LOG(WARNING) << "MAP type should has 2 children types, but got " << _sub_columns.size();
728
0
        }
729
0
    }
730
731
32.3k
    for (size_t i = 0; i < _sub_columns.size(); i++) {
732
18
        ColumnPB* child = column->add_children_columns();
733
18
        _sub_columns[i]->to_schema_pb(child);
734
18
    }
735
736
    // set parts info
737
32.3k
    if (has_path_info()) {
738
        // CHECK_GT(_parent_col_unique_id, 0);
739
124
        _column_path->to_protobuf(column->mutable_column_path_info(), _parent_col_unique_id);
740
        // Update unstable information for variant columns. Some of the fields in the tablet schema
741
        // are irrelevant for variant sub-columns, but retaining them may lead to an excessive growth
742
        // in the number of tablet schema cache entries.
743
124
        if (_type == FieldType::OLAP_FIELD_TYPE_STRING) {
744
0
            column->set_length(INT_MAX);
745
0
        }
746
124
        column->set_index_length(0);
747
124
    }
748
32.3k
    column->set_variant_max_subcolumns_count(_variant_max_subcolumns_count);
749
32.3k
    column->set_pattern_type(_pattern_type);
750
32.3k
    column->set_variant_enable_typed_paths_to_sparse(_variant_enable_typed_paths_to_sparse);
751
32.3k
    column->set_variant_max_sparse_column_statistics_size(
752
32.3k
            _variant_max_sparse_column_statistics_size);
753
32.3k
    column->set_variant_sparse_hash_shard_count(_variant_sparse_hash_shard_count);
754
32.3k
}
755
756
1.36k
void TabletColumn::add_sub_column(TabletColumn& sub_column) {
757
1.36k
    _sub_columns.push_back(std::make_shared<TabletColumn>(sub_column));
758
1.36k
    sub_column._parent_col_unique_id = this->_unique_id;
759
1.36k
    _sub_column_count += 1;
760
1.36k
}
761
762
25.2k
bool TabletColumn::is_row_store_column() const {
763
25.2k
    return _col_name == BeConsts::ROW_STORE_COL;
764
25.2k
}
765
766
vectorized::AggregateFunctionPtr TabletColumn::get_aggregate_function_union(
767
0
        vectorized::DataTypePtr type, int current_be_exec_version) const {
768
0
    const auto* state_type = assert_cast<const vectorized::DataTypeAggState*>(type.get());
769
0
    BeExecVersionManager::check_function_compatibility(
770
0
            current_be_exec_version, _be_exec_version,
771
0
            state_type->get_nested_function()->get_name());
772
0
    return vectorized::AggregateStateUnion::create(state_type->get_nested_function(), {type}, type);
773
0
}
774
775
vectorized::AggregateFunctionPtr TabletColumn::get_aggregate_function(
776
24
        std::string suffix, int current_be_exec_version) const {
777
24
    vectorized::AggregateFunctionPtr function = nullptr;
778
779
24
    auto type = vectorized::DataTypeFactory::instance().create_data_type(*this);
780
24
    if (type && type->get_primitive_type() == PrimitiveType::TYPE_AGG_STATE) {
781
0
        function = get_aggregate_function_union(type, current_be_exec_version);
782
24
    } else {
783
24
        std::string origin_name = TabletColumn::get_string_by_aggregation_type(_aggregation);
784
24
        std::string agg_name = origin_name + suffix;
785
24
        std::transform(agg_name.begin(), agg_name.end(), agg_name.begin(),
786
258
                       [](unsigned char c) { return std::tolower(c); });
787
24
        function = vectorized::AggregateFunctionSimpleFactory::instance().get(
788
24
                agg_name, {type}, type, type->is_nullable(),
789
24
                BeExecVersionManager::get_newest_version());
790
24
        if (!function) {
791
0
            LOG(WARNING) << "get column aggregate function failed, aggregation_name=" << origin_name
792
0
                         << ", column_type=" << type->get_name();
793
0
        }
794
24
    }
795
24
    if (function) {
796
24
        function->set_version(_be_exec_version);
797
24
        return function;
798
24
    }
799
0
    return nullptr;
800
24
}
801
802
1.77k
void TabletColumn::set_path_info(const vectorized::PathInData& path) {
803
1.77k
    _column_path = std::make_shared<vectorized::PathInData>(path);
804
1.77k
}
805
806
0
vectorized::DataTypePtr TabletColumn::get_vec_type() const {
807
0
    return vectorized::DataTypeFactory::instance().create_data_type(*this);
808
0
}
809
810
// escape '.' and '_'
811
61.3k
std::string escape_for_path_name(const std::string& s) {
812
61.3k
    std::string res;
813
61.3k
    const char* pos = s.data();
814
61.3k
    const char* end = pos + s.size();
815
61.9k
    while (pos != end) {
816
609
        unsigned char c = *pos;
817
609
        if (c == '.' || c == '_') {
818
55
            res += '%';
819
55
            res += vectorized::hex_digit_uppercase(c / 16);
820
55
            res += vectorized::hex_digit_uppercase(c % 16);
821
554
        } else {
822
554
            res += c;
823
554
        }
824
609
        ++pos;
825
609
    }
826
61.3k
    return res;
827
61.3k
}
828
829
26
void TabletIndex::set_escaped_escaped_index_suffix_path(const std::string& path_name) {
830
26
    std::string escaped_path = escape_for_path_name(path_name);
831
26
    _escaped_index_suffix_path = escaped_path;
832
26
}
833
834
void TabletIndex::init_from_thrift(const TOlapTableIndex& index,
835
18
                                   const TabletSchema& tablet_schema) {
836
18
    _index_id = index.index_id;
837
18
    _index_name = index.index_name;
838
    // init col_unique_id in index at be side, since col_unique_id may be -1 at fe side
839
    // get column unique id by name
840
18
    std::vector<int32_t> col_unique_ids(index.columns.size());
841
36
    for (size_t i = 0; i < index.columns.size(); i++) {
842
18
        auto column_idx = tablet_schema.field_index(index.columns[i]);
843
18
        if (column_idx >= 0) {
844
14
            col_unique_ids[i] = tablet_schema.column(column_idx).unique_id();
845
14
        } else {
846
            // if column unique id not found by column name, find by column unique id
847
            // column unique id can not found means this column is a new column added by light schema change
848
4
            if (index.__isset.column_unique_ids && !index.column_unique_ids.empty() &&
849
4
                tablet_schema.has_column_unique_id(index.column_unique_ids[i])) {
850
1
                col_unique_ids[i] = index.column_unique_ids[i];
851
3
            } else {
852
3
                col_unique_ids[i] = -1;
853
3
            }
854
4
        }
855
18
    }
856
18
    _col_unique_ids = std::move(col_unique_ids);
857
858
18
    switch (index.index_type) {
859
0
    case TIndexType::BITMAP:
860
0
        _index_type = IndexType::BITMAP;
861
0
        break;
862
17
    case TIndexType::INVERTED:
863
17
        _index_type = IndexType::INVERTED;
864
17
        break;
865
1
    case TIndexType::ANN:
866
1
        _index_type = IndexType::ANN;
867
1
        break;
868
0
    case TIndexType::BLOOMFILTER:
869
0
        _index_type = IndexType::BLOOMFILTER;
870
0
        break;
871
0
    case TIndexType::NGRAM_BF:
872
0
        _index_type = IndexType::NGRAM_BF;
873
0
        break;
874
18
    }
875
18
    if (index.__isset.properties) {
876
4
        for (auto kv : index.properties) {
877
4
            _properties[kv.first] = kv.second;
878
4
        }
879
1
    }
880
18
}
881
882
void TabletIndex::init_from_thrift(const TOlapTableIndex& index,
883
1
                                   const std::vector<int32_t>& column_uids) {
884
1
    _index_id = index.index_id;
885
1
    _index_name = index.index_name;
886
1
    _col_unique_ids = column_uids;
887
888
1
    switch (index.index_type) {
889
0
    case TIndexType::BITMAP:
890
0
        _index_type = IndexType::BITMAP;
891
0
        break;
892
1
    case TIndexType::INVERTED:
893
1
        _index_type = IndexType::INVERTED;
894
1
        break;
895
0
    case TIndexType::ANN:
896
0
        _index_type = IndexType::ANN;
897
0
        break;
898
0
    case TIndexType::BLOOMFILTER:
899
0
        _index_type = IndexType::BLOOMFILTER;
900
0
        break;
901
0
    case TIndexType::NGRAM_BF:
902
0
        _index_type = IndexType::NGRAM_BF;
903
0
        break;
904
1
    }
905
1
    if (index.__isset.properties) {
906
3
        for (auto kv : index.properties) {
907
3
            _properties[kv.first] = kv.second;
908
3
        }
909
1
    }
910
1
}
911
912
7.49k
void TabletIndex::init_from_pb(const TabletIndexPB& index) {
913
7.49k
    _index_id = index.index_id();
914
7.49k
    _index_name = index.index_name();
915
7.49k
    _col_unique_ids.clear();
916
7.49k
    for (auto col_unique_id : index.col_unique_id()) {
917
7.46k
        _col_unique_ids.push_back(col_unique_id);
918
7.46k
    }
919
7.49k
    _index_type = index.index_type();
920
41.0k
    for (const auto& kv : index.properties()) {
921
41.0k
        _properties[kv.first] = kv.second;
922
41.0k
    }
923
7.49k
    _escaped_index_suffix_path = index.index_suffix_name();
924
7.49k
}
925
926
11.0k
void TabletIndex::to_schema_pb(TabletIndexPB* index) const {
927
11.0k
    index->set_index_id(_index_id);
928
11.0k
    index->set_index_name(_index_name);
929
11.0k
    index->clear_col_unique_id();
930
11.0k
    for (auto col_unique_id : _col_unique_ids) {
931
11.0k
        index->add_col_unique_id(col_unique_id);
932
11.0k
    }
933
11.0k
    index->set_index_type(_index_type);
934
60.8k
    for (const auto& kv : _properties) {
935
60.8k
        DBUG_EXECUTE_IF("tablet_schema.to_schema_pb", {
936
60.8k
            if (kv.first == INVERTED_INDEX_PARSER_LOWERCASE_KEY) {
937
60.8k
                continue;
938
60.8k
            }
939
60.8k
        })
940
60.8k
        (*index->mutable_properties())[kv.first] = kv.second;
941
60.8k
    }
942
11.0k
    index->set_index_suffix_name(_escaped_index_suffix_path);
943
944
11.0k
    DBUG_EXECUTE_IF("tablet_schema.to_schema_pb", { return; })
945
946
    // lowercase by default
947
11.0k
    if (!_properties.empty()) {
948
9.76k
        if (!_properties.contains(INVERTED_INDEX_PARSER_LOWERCASE_KEY)) {
949
179
            (*index->mutable_properties())[INVERTED_INDEX_PARSER_LOWERCASE_KEY] =
950
179
                    INVERTED_INDEX_PARSER_TRUE;
951
179
        }
952
9.76k
    }
953
11.0k
}
954
955
3.21k
TabletSchema::TabletSchema() = default;
956
957
3.14k
TabletSchema::~TabletSchema() {}
958
959
1.93k
int64_t TabletSchema::get_metadata_size() const {
960
1.93k
    return sizeof(TabletSchema);
961
1.93k
}
962
963
3.34k
void TabletSchema::append_column(TabletColumn column, ColumnType col_type) {
964
3.34k
    if (column.is_key()) {
965
119
        _num_key_columns++;
966
119
    }
967
3.34k
    if (column.is_nullable()) {
968
3.10k
        _num_null_columns++;
969
3.10k
    }
970
3.34k
    if (column.is_variant_type()) {
971
55
        ++_num_variant_columns;
972
55
        if (!column.has_path_info()) {
973
23
            const std::string& col_name = column.name_lower_case();
974
23
            vectorized::PathInData path(col_name);
975
23
            column.set_path_info(path);
976
23
        }
977
55
    }
978
3.34k
    if (UNLIKELY(column.name() == DELETE_SIGN)) {
979
21
        _delete_sign_idx = _num_columns;
980
3.32k
    } else if (UNLIKELY(column.name() == SEQUENCE_COL)) {
981
4
        _sequence_col_idx = _num_columns;
982
3.31k
    } else if (UNLIKELY(column.name() == VERSION_COL)) {
983
0
        _version_col_idx = _num_columns;
984
3.31k
    } else if (UNLIKELY(column.name() == SKIP_BITMAP_COL)) {
985
0
        _skip_bitmap_col_idx = _num_columns;
986
3.31k
    } else if (UNLIKELY(column.name().starts_with(BeConsts::VIRTUAL_COLUMN_PREFIX))) {
987
0
        _vir_col_idx_to_unique_id[_num_columns] = column.unique_id();
988
0
    }
989
3.34k
    _field_uniqueid_to_index[column.unique_id()] = _num_columns;
990
3.34k
    _cols.push_back(std::make_shared<TabletColumn>(std::move(column)));
991
    // The dropped column may have same name with exsiting column, so that
992
    // not add to name to index map, only for uid to index map
993
3.34k
    if (col_type == ColumnType::VARIANT || _cols.back()->is_variant_type() ||
994
3.34k
        _cols.back()->is_extracted_column()) {
995
110
        _field_name_to_index.emplace(StringRef(_cols.back()->name()), _num_columns);
996
110
        _field_path_to_index[_cols.back()->path_info_ptr().get()] = _num_columns;
997
3.23k
    } else if (col_type == ColumnType::NORMAL) {
998
3.23k
        _field_name_to_index.emplace(StringRef(_cols.back()->name()), _num_columns);
999
3.23k
    }
1000
3.34k
    _num_columns++;
1001
3.34k
    _num_virtual_columns = _vir_col_idx_to_unique_id.size();
1002
3.34k
}
1003
1004
73
void TabletSchema::append_index(TabletIndex&& index) {
1005
73
    size_t index_pos = _indexes.size();
1006
73
    _indexes.push_back(std::make_shared<TabletIndex>(index));
1007
76
    for (int32_t id : _indexes.back()->col_unique_ids()) {
1008
76
        if (auto field_pattern = _indexes.back()->field_pattern(); !field_pattern.empty()) {
1009
6
            auto& pattern_to_index_map = _index_by_unique_id_with_pattern[id];
1010
6
            pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
1011
70
        } else {
1012
70
            IndexKey key = std::make_tuple(_indexes.back()->index_type(), id,
1013
70
                                           _indexes.back()->get_index_suffix());
1014
70
            _col_id_suffix_to_index[key].push_back(index_pos);
1015
70
        }
1016
76
    }
1017
73
}
1018
1019
0
void TabletSchema::replace_column(size_t pos, TabletColumn new_col) {
1020
0
    CHECK_LT(pos, num_columns()) << " outof range";
1021
0
    _cols[pos] = std::make_shared<TabletColumn>(std::move(new_col));
1022
0
}
1023
1024
3
void TabletSchema::clear_index() {
1025
3
    _indexes.clear();
1026
3
    _col_id_suffix_to_index.clear();
1027
3
    _index_by_unique_id_with_pattern.clear();
1028
3
}
1029
1030
7
void TabletSchema::remove_index(int64_t index_id) {
1031
7
    std::vector<TabletIndexPtr> new_indexes;
1032
11
    for (auto& index : _indexes) {
1033
11
        if (index->index_id() != index_id) {
1034
4
            new_indexes.emplace_back(std::move(index));
1035
4
        }
1036
11
    }
1037
7
    _indexes = std::move(new_indexes);
1038
7
    _col_id_suffix_to_index.clear();
1039
7
    _index_by_unique_id_with_pattern.clear();
1040
11
    for (size_t new_pos = 0; new_pos < _indexes.size(); ++new_pos) {
1041
4
        const auto& index = _indexes[new_pos];
1042
4
        for (int32_t col_uid : index->col_unique_ids()) {
1043
4
            if (auto field_pattern = index->field_pattern(); !field_pattern.empty()) {
1044
0
                auto& pattern_to_index_map = _index_by_unique_id_with_pattern[col_uid];
1045
0
                pattern_to_index_map[field_pattern].emplace_back(index);
1046
4
            } else {
1047
4
                IndexKey key = std::make_tuple(_indexes.back()->index_type(), col_uid,
1048
4
                                               _indexes.back()->get_index_suffix());
1049
4
                _col_id_suffix_to_index[key].push_back(new_pos);
1050
4
            }
1051
4
        }
1052
4
    }
1053
7
}
1054
1055
1
void TabletSchema::clear_columns() {
1056
1
    _field_path_to_index.clear();
1057
1
    _field_name_to_index.clear();
1058
1
    _field_uniqueid_to_index.clear();
1059
1
    _num_columns = 0;
1060
1
    _num_variant_columns = 0;
1061
1
    _num_null_columns = 0;
1062
1
    _num_key_columns = 0;
1063
1
    _cols.clear();
1064
1
}
1065
1066
void TabletSchema::init_from_pb(const TabletSchemaPB& schema, bool ignore_extracted_columns,
1067
1.86k
                                bool reuse_cache_column) {
1068
1.86k
    _keys_type = schema.keys_type();
1069
1.86k
    _num_columns = 0;
1070
1.86k
    _num_variant_columns = 0;
1071
1.86k
    _num_key_columns = 0;
1072
1.86k
    _num_null_columns = 0;
1073
1.86k
    _cols.clear();
1074
1.86k
    _indexes.clear();
1075
1.86k
    _index_by_unique_id_with_pattern.clear();
1076
1.86k
    _col_id_suffix_to_index.clear();
1077
1.86k
    _field_name_to_index.clear();
1078
1.86k
    _field_uniqueid_to_index.clear();
1079
1.86k
    _cluster_key_uids.clear();
1080
1.86k
    for (const auto& i : schema.cluster_key_uids()) {
1081
6
        _cluster_key_uids.push_back(i);
1082
6
    }
1083
12.5k
    for (auto& column_pb : schema.column()) {
1084
12.5k
        TabletColumnPtr column;
1085
12.5k
        if (reuse_cache_column) {
1086
345
            auto pair = TabletColumnObjectPool::instance()->insert(
1087
345
                    deterministic_string_serialize(column_pb));
1088
345
            column = pair.second;
1089
            // Release the handle quickly, because we use shared ptr to manage column.
1090
            // It often core during tablet schema copy to another schema because handle's
1091
            // reference count should be managed mannually.
1092
345
            TabletColumnObjectPool::instance()->release(pair.first);
1093
12.2k
        } else {
1094
12.2k
            column = std::make_shared<TabletColumn>();
1095
12.2k
            column->init_from_pb(column_pb);
1096
12.2k
        }
1097
12.5k
        if (ignore_extracted_columns && column->is_extracted_column()) {
1098
0
            continue;
1099
0
        }
1100
12.5k
        if (column->is_key()) {
1101
2.42k
            _num_key_columns++;
1102
2.42k
        }
1103
12.5k
        if (column->is_nullable()) {
1104
7.47k
            _num_null_columns++;
1105
7.47k
        }
1106
12.5k
        if (column->is_variant_type()) {
1107
59
            ++_num_variant_columns;
1108
59
        }
1109
1110
12.5k
        _cols.emplace_back(std::move(column));
1111
12.5k
        if (!_cols.back()->is_extracted_column()) {
1112
12.5k
            _field_name_to_index.emplace(StringRef(_cols.back()->name()), _num_columns);
1113
12.5k
            _field_uniqueid_to_index[_cols.back()->unique_id()] = _num_columns;
1114
12.5k
        }
1115
12.5k
        _num_columns++;
1116
12.5k
    }
1117
7.40k
    for (const auto& index_pb : schema.index()) {
1118
7.40k
        TabletIndexPtr index;
1119
7.40k
        if (reuse_cache_column) {
1120
163
            auto pair = TabletColumnObjectPool::instance()->insert_index(
1121
163
                    deterministic_string_serialize(index_pb));
1122
163
            index = pair.second;
1123
            //  Only need the value to be cached by the pool, release it quickly because the handle need
1124
            // record reference count mannually, or it will core during tablet schema copy method.
1125
163
            TabletColumnObjectPool::instance()->release(pair.first);
1126
7.24k
        } else {
1127
7.24k
            index = std::make_shared<TabletIndex>();
1128
7.24k
            index->init_from_pb(index_pb);
1129
7.24k
        }
1130
7.40k
        size_t index_pos = _indexes.size();
1131
7.40k
        _indexes.emplace_back(std::move(index));
1132
7.40k
        for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
1133
7.40k
            if (auto field_pattern = _indexes.back()->field_pattern(); !field_pattern.empty()) {
1134
0
                auto& pattern_to_index_map = _index_by_unique_id_with_pattern[col_uid];
1135
0
                pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
1136
7.40k
            } else {
1137
7.40k
                IndexKey key = std::make_tuple(_indexes.back()->index_type(), col_uid,
1138
7.40k
                                               _indexes.back()->get_index_suffix());
1139
7.40k
                _col_id_suffix_to_index[key].push_back(index_pos);
1140
7.40k
            }
1141
7.40k
        }
1142
7.40k
    }
1143
1.86k
    _num_short_key_columns = schema.num_short_key_columns();
1144
1.86k
    _num_rows_per_row_block = schema.num_rows_per_row_block();
1145
1.86k
    _compress_kind = schema.compress_kind();
1146
1.86k
    _next_column_unique_id = schema.next_column_unique_id();
1147
1.86k
    if (schema.has_bf_fpp()) {
1148
3
        _has_bf_fpp = true;
1149
3
        _bf_fpp = schema.bf_fpp();
1150
1.85k
    } else {
1151
1.85k
        _has_bf_fpp = false;
1152
1.85k
        _bf_fpp = BLOOM_FILTER_DEFAULT_FPP;
1153
1.85k
    }
1154
1.86k
    _is_in_memory = schema.is_in_memory();
1155
1.86k
    _disable_auto_compaction = schema.disable_auto_compaction();
1156
1.86k
    _enable_single_replica_compaction = schema.enable_single_replica_compaction();
1157
1.86k
    _store_row_column = schema.store_row_column();
1158
1.86k
    _skip_write_index_on_load = schema.skip_write_index_on_load();
1159
1.86k
    _delete_sign_idx = schema.delete_sign_idx();
1160
1.86k
    _sequence_col_idx = schema.sequence_col_idx();
1161
1.86k
    _version_col_idx = schema.version_col_idx();
1162
1.86k
    _skip_bitmap_col_idx = schema.skip_bitmap_col_idx();
1163
1.86k
    _sort_type = schema.sort_type();
1164
1.86k
    _sort_col_num = schema.sort_col_num();
1165
1.86k
    _compression_type = schema.compression_type();
1166
1.86k
    _row_store_page_size = schema.row_store_page_size();
1167
1.86k
    _storage_page_size = schema.storage_page_size();
1168
1.86k
    _storage_dict_page_size = schema.storage_dict_page_size();
1169
1.86k
    _schema_version = schema.schema_version();
1170
    // Default to V1 inverted index storage format for backward compatibility if not specified in schema.
1171
1.86k
    if (!schema.has_inverted_index_storage_format()) {
1172
276
        _inverted_index_storage_format = InvertedIndexStorageFormatPB::V1;
1173
1.58k
    } else {
1174
1.58k
        _inverted_index_storage_format = schema.inverted_index_storage_format();
1175
1.58k
    }
1176
1177
1.86k
    _row_store_column_unique_ids.assign(schema.row_store_column_unique_ids().begin(),
1178
1.86k
                                        schema.row_store_column_unique_ids().end());
1179
1.86k
    _enable_variant_flatten_nested = schema.enable_variant_flatten_nested();
1180
1.86k
    if (schema.has_is_external_segment_column_meta_used()) {
1181
941
        _is_external_segment_column_meta_used = schema.is_external_segment_column_meta_used();
1182
941
    } else {
1183
921
        _is_external_segment_column_meta_used = false;
1184
921
    }
1185
1.86k
    if (schema.has_integer_type_default_use_plain_encoding()) {
1186
941
        _integer_type_default_use_plain_encoding = schema.integer_type_default_use_plain_encoding();
1187
941
    }
1188
1.86k
    if (schema.has_binary_plain_encoding_default_impl()) {
1189
941
        _binary_plain_encoding_default_impl = schema.binary_plain_encoding_default_impl();
1190
941
    }
1191
1.86k
    update_metadata_size();
1192
1.86k
}
1193
1194
390
void TabletSchema::copy_from(const TabletSchema& tablet_schema) {
1195
390
    TabletSchemaPB tablet_schema_pb;
1196
390
    tablet_schema.to_schema_pb(&tablet_schema_pb);
1197
390
    init_from_pb(tablet_schema_pb);
1198
390
    _table_id = tablet_schema.table_id();
1199
390
    _path_set_info_map = tablet_schema._path_set_info_map;
1200
390
}
1201
1202
42
void TabletSchema::shawdow_copy_without_columns(const TabletSchema& tablet_schema) {
1203
42
    *this = tablet_schema;
1204
42
    _field_path_to_index.clear();
1205
42
    _field_name_to_index.clear();
1206
42
    _field_uniqueid_to_index.clear();
1207
42
    _num_columns = 0;
1208
42
    _num_variant_columns = 0;
1209
42
    _num_null_columns = 0;
1210
42
    _num_key_columns = 0;
1211
42
    _cols.clear();
1212
42
    _delete_sign_idx = -1;
1213
42
    _sequence_col_idx = -1;
1214
42
    _version_col_idx = -1;
1215
42
}
1216
1217
0
void TabletSchema::update_index_info_from(const TabletSchema& tablet_schema) {
1218
0
    for (auto& col : _cols) {
1219
0
        if (col->unique_id() < 0) {
1220
0
            continue;
1221
0
        }
1222
0
        const auto iter = tablet_schema._field_uniqueid_to_index.find(col->unique_id());
1223
0
        if (iter == tablet_schema._field_uniqueid_to_index.end()) {
1224
0
            continue;
1225
0
        }
1226
0
        auto col_idx = iter->second;
1227
0
        if (col_idx < 0 || col_idx >= tablet_schema._cols.size()) {
1228
0
            continue;
1229
0
        }
1230
0
        col->set_is_bf_column(tablet_schema._cols[col_idx]->is_bf_column());
1231
0
    }
1232
0
}
1233
1234
6.36k
std::string TabletSchema::to_key() const {
1235
6.36k
    TabletSchemaPB pb;
1236
6.36k
    to_schema_pb(&pb);
1237
6.36k
    return TabletSchema::deterministic_string_serialize(pb);
1238
6.36k
}
1239
1240
void TabletSchema::build_current_tablet_schema(int64_t index_id, int32_t version,
1241
                                               const OlapTableIndexSchema* index,
1242
0
                                               const TabletSchema& ori_tablet_schema) {
1243
    // copy from ori_tablet_schema
1244
0
    _keys_type = ori_tablet_schema.keys_type();
1245
0
    _num_short_key_columns = ori_tablet_schema.num_short_key_columns();
1246
0
    _num_rows_per_row_block = ori_tablet_schema.num_rows_per_row_block();
1247
0
    _compress_kind = ori_tablet_schema.compress_kind();
1248
1249
    // todo(yixiu): unique_id
1250
0
    _next_column_unique_id = ori_tablet_schema.next_column_unique_id();
1251
0
    _is_in_memory = ori_tablet_schema.is_in_memory();
1252
0
    _disable_auto_compaction = ori_tablet_schema.disable_auto_compaction();
1253
0
    _enable_single_replica_compaction = ori_tablet_schema.enable_single_replica_compaction();
1254
0
    _skip_write_index_on_load = ori_tablet_schema.skip_write_index_on_load();
1255
0
    _sort_type = ori_tablet_schema.sort_type();
1256
0
    _sort_col_num = ori_tablet_schema.sort_col_num();
1257
0
    _row_store_page_size = ori_tablet_schema.row_store_page_size();
1258
0
    _storage_page_size = ori_tablet_schema.storage_page_size();
1259
0
    _storage_dict_page_size = ori_tablet_schema.storage_dict_page_size();
1260
0
    _enable_variant_flatten_nested = ori_tablet_schema.variant_flatten_nested();
1261
1262
    // copy from table_schema_param
1263
0
    _schema_version = version;
1264
0
    _num_columns = 0;
1265
0
    _num_variant_columns = 0;
1266
0
    _num_key_columns = 0;
1267
0
    _num_null_columns = 0;
1268
0
    bool has_bf_columns = false;
1269
0
    _cols.clear();
1270
0
    _indexes.clear();
1271
0
    _col_id_suffix_to_index.clear();
1272
0
    _index_by_unique_id_with_pattern.clear();
1273
0
    _field_name_to_index.clear();
1274
0
    _field_uniqueid_to_index.clear();
1275
0
    _delete_sign_idx = -1;
1276
0
    _sequence_col_idx = -1;
1277
0
    _version_col_idx = -1;
1278
0
    _skip_bitmap_col_idx = -1;
1279
0
    _cluster_key_uids.clear();
1280
0
    for (const auto& i : ori_tablet_schema._cluster_key_uids) {
1281
0
        _cluster_key_uids.push_back(i);
1282
0
    }
1283
0
    for (auto& column : index->columns) {
1284
0
        if (column->is_key()) {
1285
0
            _num_key_columns++;
1286
0
        }
1287
0
        if (column->is_nullable()) {
1288
0
            _num_null_columns++;
1289
0
        }
1290
0
        if (column->is_bf_column()) {
1291
0
            has_bf_columns = true;
1292
0
        }
1293
0
        if (column->is_variant_type()) {
1294
0
            ++_num_variant_columns;
1295
0
        }
1296
0
        if (UNLIKELY(column->name() == DELETE_SIGN)) {
1297
0
            _delete_sign_idx = _num_columns;
1298
0
        } else if (UNLIKELY(column->name() == SEQUENCE_COL)) {
1299
0
            _sequence_col_idx = _num_columns;
1300
0
        } else if (UNLIKELY(column->name() == VERSION_COL)) {
1301
0
            _version_col_idx = _num_columns;
1302
0
        } else if (UNLIKELY(column->name() == SKIP_BITMAP_COL)) {
1303
0
            _skip_bitmap_col_idx = _num_columns;
1304
0
        }
1305
0
        _cols.emplace_back(std::make_shared<TabletColumn>(*column));
1306
0
        _field_name_to_index.emplace(StringRef(_cols.back()->name()), _num_columns);
1307
0
        _field_uniqueid_to_index[_cols.back()->unique_id()] = _num_columns;
1308
0
        _num_columns++;
1309
0
    }
1310
1311
0
    for (const auto& i : index->indexes) {
1312
0
        size_t index_pos = _indexes.size();
1313
0
        _indexes.emplace_back(std::make_shared<TabletIndex>(*i));
1314
0
        for (int32_t col_uid : _indexes.back()->col_unique_ids()) {
1315
0
            if (auto field_pattern = _indexes.back()->field_pattern(); !field_pattern.empty()) {
1316
0
                auto& pattern_to_index_map = _index_by_unique_id_with_pattern[col_uid];
1317
0
                pattern_to_index_map[field_pattern].emplace_back(_indexes.back());
1318
0
            } else {
1319
0
                IndexKey key = std::make_tuple(_indexes.back()->index_type(), col_uid,
1320
0
                                               _indexes.back()->get_index_suffix());
1321
0
                _col_id_suffix_to_index[key].push_back(index_pos);
1322
0
            }
1323
0
        }
1324
0
    }
1325
1326
0
    if (has_bf_columns) {
1327
0
        _has_bf_fpp = true;
1328
0
        _bf_fpp = ori_tablet_schema.bloom_filter_fpp();
1329
0
    } else {
1330
0
        _has_bf_fpp = false;
1331
0
        _bf_fpp = BLOOM_FILTER_DEFAULT_FPP;
1332
0
    }
1333
0
}
1334
1335
149
void TabletSchema::merge_dropped_columns(const TabletSchema& src_schema) {
1336
    // If they are the same tablet schema object, then just return
1337
149
    if (this == &src_schema) {
1338
0
        return;
1339
0
    }
1340
2.90k
    for (const auto& src_col : src_schema.columns()) {
1341
2.90k
        if (_field_uniqueid_to_index.find(src_col->unique_id()) == _field_uniqueid_to_index.end()) {
1342
0
            CHECK(!src_col->is_key())
1343
0
                    << src_col->name() << " is key column, should not be dropped.";
1344
0
            ColumnPB src_col_pb;
1345
            // There are some pointer in tablet column, not sure the reference relation, so
1346
            // that deep copy it.
1347
0
            src_col->to_schema_pb(&src_col_pb);
1348
0
            TabletColumn new_col(src_col_pb);
1349
0
            append_column(new_col, TabletSchema::ColumnType::DROPPED);
1350
0
        }
1351
2.90k
    }
1352
149
}
1353
1354
0
TabletSchemaSPtr TabletSchema::copy_without_variant_extracted_columns() {
1355
0
    TabletSchemaSPtr copy = std::make_shared<TabletSchema>();
1356
0
    copy->shawdow_copy_without_columns(*this);
1357
0
    for (auto& col : this->columns()) {
1358
0
        if (col->is_extracted_column()) {
1359
0
            continue;
1360
0
        }
1361
0
        copy->append_column(*col);
1362
0
    }
1363
0
    return copy;
1364
0
}
1365
1366
// Dropped column is in _field_uniqueid_to_index but not in _field_name_to_index
1367
// Could refer to append_column method
1368
6.34k
bool TabletSchema::is_dropped_column(const TabletColumn& col) const {
1369
6.34k
    CHECK(_field_uniqueid_to_index.find(col.unique_id()) != _field_uniqueid_to_index.end())
1370
0
            << "could not find col with unique id = " << col.unique_id()
1371
0
            << " and name = " << col.name() << " table_id=" << _table_id;
1372
6.34k
    auto it = _field_name_to_index.find(StringRef {col.name()});
1373
6.34k
    return it == _field_name_to_index.end() || _cols[it->second]->unique_id() != col.unique_id();
1374
6.34k
}
1375
1376
0
void TabletSchema::copy_extracted_columns(const TabletSchema& src_schema) {
1377
0
    std::unordered_set<int32_t> variant_columns;
1378
0
    for (const auto& col : columns()) {
1379
0
        if (col->is_variant_type()) {
1380
0
            variant_columns.insert(col->unique_id());
1381
0
        }
1382
0
    }
1383
0
    for (const TabletColumnPtr& col : src_schema.columns()) {
1384
0
        if (col->is_extracted_column() && variant_columns.contains(col->parent_unique_id())) {
1385
0
            ColumnPB col_pb;
1386
0
            col->to_schema_pb(&col_pb);
1387
0
            TabletColumn new_col(col_pb);
1388
0
            append_column(new_col, ColumnType::VARIANT);
1389
0
        }
1390
0
    }
1391
0
}
1392
1393
0
void TabletSchema::reserve_extracted_columns() {
1394
0
    for (auto it = _cols.begin(); it != _cols.end();) {
1395
0
        if (!(*it)->is_extracted_column()) {
1396
0
            it = _cols.erase(it);
1397
0
        } else {
1398
0
            ++it;
1399
0
        }
1400
0
    }
1401
0
}
1402
1403
8.60k
void TabletSchema::to_schema_pb(TabletSchemaPB* tablet_schema_pb) const {
1404
8.60k
    for (const auto& i : _cluster_key_uids) {
1405
30
        tablet_schema_pb->add_cluster_key_uids(i);
1406
30
    }
1407
8.60k
    tablet_schema_pb->set_keys_type(_keys_type);
1408
32.3k
    for (const auto& col : _cols) {
1409
32.3k
        ColumnPB* column = tablet_schema_pb->add_column();
1410
32.3k
        col->to_schema_pb(column);
1411
32.3k
    }
1412
11.0k
    for (const auto& index : _indexes) {
1413
11.0k
        auto* index_pb = tablet_schema_pb->add_index();
1414
11.0k
        index->to_schema_pb(index_pb);
1415
11.0k
    }
1416
8.60k
    tablet_schema_pb->set_num_short_key_columns(cast_set<int32_t>(_num_short_key_columns));
1417
8.60k
    tablet_schema_pb->set_num_rows_per_row_block(cast_set<int32_t>(_num_rows_per_row_block));
1418
8.60k
    tablet_schema_pb->set_compress_kind(_compress_kind);
1419
8.60k
    if (_has_bf_fpp) {
1420
4
        tablet_schema_pb->set_bf_fpp(_bf_fpp);
1421
4
    }
1422
8.60k
    tablet_schema_pb->set_next_column_unique_id(cast_set<uint32_t>(_next_column_unique_id));
1423
8.60k
    tablet_schema_pb->set_is_in_memory(_is_in_memory);
1424
8.60k
    tablet_schema_pb->set_disable_auto_compaction(_disable_auto_compaction);
1425
8.60k
    tablet_schema_pb->set_enable_single_replica_compaction(_enable_single_replica_compaction);
1426
8.60k
    tablet_schema_pb->set_store_row_column(_store_row_column);
1427
8.60k
    tablet_schema_pb->set_skip_write_index_on_load(_skip_write_index_on_load);
1428
8.60k
    tablet_schema_pb->set_delete_sign_idx(_delete_sign_idx);
1429
8.60k
    tablet_schema_pb->set_sequence_col_idx(_sequence_col_idx);
1430
8.60k
    tablet_schema_pb->set_sort_type(_sort_type);
1431
8.60k
    tablet_schema_pb->set_sort_col_num(cast_set<int32_t>(_sort_col_num));
1432
8.60k
    tablet_schema_pb->set_schema_version(_schema_version);
1433
8.60k
    tablet_schema_pb->set_compression_type(_compression_type);
1434
8.60k
    tablet_schema_pb->set_row_store_page_size(_row_store_page_size);
1435
8.60k
    tablet_schema_pb->set_storage_page_size(_storage_page_size);
1436
8.60k
    tablet_schema_pb->set_storage_dict_page_size(_storage_dict_page_size);
1437
8.60k
    tablet_schema_pb->set_version_col_idx(_version_col_idx);
1438
8.60k
    tablet_schema_pb->set_skip_bitmap_col_idx(_skip_bitmap_col_idx);
1439
8.60k
    tablet_schema_pb->set_inverted_index_storage_format(_inverted_index_storage_format);
1440
8.60k
    tablet_schema_pb->mutable_row_store_column_unique_ids()->Assign(
1441
8.60k
            _row_store_column_unique_ids.begin(), _row_store_column_unique_ids.end());
1442
8.60k
    tablet_schema_pb->set_enable_variant_flatten_nested(_enable_variant_flatten_nested);
1443
8.60k
    tablet_schema_pb->set_is_external_segment_column_meta_used(
1444
8.60k
            _is_external_segment_column_meta_used);
1445
8.60k
    tablet_schema_pb->set_integer_type_default_use_plain_encoding(
1446
8.60k
            _integer_type_default_use_plain_encoding);
1447
8.60k
    tablet_schema_pb->set_binary_plain_encoding_default_impl(_binary_plain_encoding_default_impl);
1448
8.60k
}
1449
1450
0
size_t TabletSchema::row_size() const {
1451
0
    size_t size = 0;
1452
0
    for (const auto& column : _cols) {
1453
0
        size += column->length();
1454
0
    }
1455
0
    size += (_num_columns + 7) / 8;
1456
1457
0
    return size;
1458
0
}
1459
1460
1.26k
int32_t TabletSchema::field_index(const std::string& field_name) const {
1461
1.26k
    const auto& found = _field_name_to_index.find(StringRef(field_name));
1462
1.26k
    return (found == _field_name_to_index.end()) ? -1 : found->second;
1463
1.26k
}
1464
1465
0
int32_t TabletSchema::field_index(const vectorized::PathInData& path) const {
1466
0
    const auto& found = _field_path_to_index.find(vectorized::PathInDataRef(&path));
1467
0
    return (found == _field_path_to_index.end()) ? -1 : found->second;
1468
0
}
1469
1470
195
int32_t TabletSchema::field_index(int32_t col_unique_id) const {
1471
195
    const auto& found = _field_uniqueid_to_index.find(col_unique_id);
1472
195
    return (found == _field_uniqueid_to_index.end()) ? -1 : found->second;
1473
195
}
1474
1475
27.4k
const std::vector<TabletColumnPtr>& TabletSchema::columns() const {
1476
27.4k
    return _cols;
1477
27.4k
}
1478
1479
104k
const TabletColumn& TabletSchema::column(size_t ordinal) const {
1480
104k
    DCHECK(ordinal < _num_columns) << "ordinal:" << ordinal << ", _num_columns:" << _num_columns;
1481
104k
    return *_cols[ordinal];
1482
104k
}
1483
1484
2.43k
const TabletColumn& TabletSchema::column_by_uid(int32_t col_unique_id) const {
1485
2.43k
    return *_cols.at(_field_uniqueid_to_index.at(col_unique_id));
1486
2.43k
}
1487
1488
1
TabletColumn& TabletSchema::mutable_column_by_uid(int32_t col_unique_id) {
1489
1
    return *_cols.at(_field_uniqueid_to_index.at(col_unique_id));
1490
1
}
1491
1492
18
TabletColumn& TabletSchema::mutable_column(size_t ordinal) {
1493
18
    return *_cols.at(ordinal);
1494
18
}
1495
1496
1
void TabletSchema::update_indexes_from_thrift(const std::vector<doris::TOlapTableIndex>& tindexes) {
1497
1
    std::vector<TabletIndexPtr> indexes;
1498
2
    for (const auto& tindex : tindexes) {
1499
2
        TabletIndex index;
1500
2
        index.init_from_thrift(tindex, *this);
1501
2
        indexes.emplace_back(std::make_shared<TabletIndex>(std::move(index)));
1502
2
    }
1503
1
    _indexes = std::move(indexes);
1504
1
    _col_id_suffix_to_index.clear();
1505
1
    _index_by_unique_id_with_pattern.clear();
1506
1
    size_t index_pos = 0;
1507
2
    for (auto& index : _indexes) {
1508
2
        for (int32_t col_uid : index->col_unique_ids()) {
1509
2
            if (auto field_pattern = index->field_pattern(); !field_pattern.empty()) {
1510
0
                auto& pattern_to_index_map = _index_by_unique_id_with_pattern[col_uid];
1511
0
                pattern_to_index_map[field_pattern].emplace_back(index);
1512
2
            } else {
1513
2
                IndexKey key =
1514
2
                        std::make_tuple(index->index_type(), col_uid, index->get_index_suffix());
1515
2
                _col_id_suffix_to_index[key].push_back(index_pos);
1516
2
            }
1517
2
        }
1518
2
        index_pos++;
1519
2
    }
1520
1
}
1521
1522
0
bool TabletSchema::exist_column(const std::string& field_name) const {
1523
0
    return _field_name_to_index.contains(StringRef {field_name});
1524
0
}
1525
1526
16.0k
bool TabletSchema::has_column_unique_id(int32_t col_unique_id) const {
1527
16.0k
    return _field_uniqueid_to_index.contains(col_unique_id);
1528
16.0k
}
1529
1530
4.04k
Status TabletSchema::have_column(const std::string& field_name) const {
1531
4.04k
    if (!_field_name_to_index.contains(StringRef(field_name))) {
1532
4.04k
        return Status::Error<ErrorCode::INTERNAL_ERROR>(
1533
4.04k
                "Not found field_name, field_name:{}, schema:{}", field_name,
1534
4.04k
                get_all_field_names());
1535
4.04k
    }
1536
0
    return Status::OK();
1537
4.04k
}
1538
1539
183
Result<const TabletColumn*> TabletSchema::column(const std::string& field_name) const {
1540
183
    auto it = _field_name_to_index.find(StringRef {field_name});
1541
183
    if (it == _field_name_to_index.end()) {
1542
0
        DCHECK(false) << "field_name=" << field_name << ", table_id=" << _table_id
1543
0
                      << ", field_name_to_index=" << get_all_field_names();
1544
0
        return ResultError(
1545
0
                Status::InternalError("column not found, name={}, table_id={}, schema_version={}",
1546
0
                                      field_name, _table_id, _schema_version));
1547
0
    }
1548
183
    return _cols[it->second].get();
1549
183
}
1550
1551
void TabletSchema::update_tablet_columns(const TabletSchema& tablet_schema,
1552
0
                                         const std::vector<TColumn>& t_columns) {
1553
0
    copy_from(tablet_schema);
1554
0
    if (!t_columns.empty() && t_columns[0].col_unique_id >= 0) {
1555
0
        clear_columns();
1556
0
        for (const auto& column : t_columns) {
1557
0
            append_column(TabletColumn(column));
1558
0
        }
1559
0
    }
1560
0
}
1561
1562
67
bool TabletSchema::has_inverted_index_with_index_id(int64_t index_id) const {
1563
86
    for (size_t i = 0; i < _indexes.size(); i++) {
1564
48
        if ((_indexes[i]->index_type() == IndexType::INVERTED ||
1565
48
             _indexes[i]->index_type() == IndexType::ANN) &&
1566
48
            _indexes[i]->index_id() == index_id) {
1567
29
            return true;
1568
29
        }
1569
48
    }
1570
38
    return false;
1571
67
}
1572
1573
std::vector<const TabletIndex*> TabletSchema::inverted_indexs(
1574
32.7k
        int32_t col_unique_id, const std::string& suffix_path) const {
1575
32.7k
    std::vector<const TabletIndex*> result;
1576
32.7k
    const std::string escaped_suffix = escape_for_path_name(suffix_path);
1577
32.7k
    auto it = _col_id_suffix_to_index.find(
1578
32.7k
            std::make_tuple(IndexType::INVERTED, col_unique_id, escaped_suffix));
1579
32.7k
    if (it != _col_id_suffix_to_index.end()) {
1580
7.85k
        for (size_t pos : it->second) {
1581
7.85k
            if (pos < _indexes.size()) {
1582
7.85k
                result.push_back(_indexes[pos].get());
1583
7.85k
            }
1584
7.85k
        }
1585
7.82k
    }
1586
32.7k
    return result;
1587
32.7k
}
1588
1589
std::vector<TabletIndexPtr> TabletSchema::inverted_index_by_field_pattern(
1590
36
        int32_t col_unique_id, const std::string& field_pattern) const {
1591
36
    auto id_to_pattern_map = _index_by_unique_id_with_pattern.find(col_unique_id);
1592
36
    if (id_to_pattern_map == _index_by_unique_id_with_pattern.end()) {
1593
27
        return {};
1594
27
    }
1595
9
    auto pattern_to_index_map = id_to_pattern_map->second.find(field_pattern);
1596
9
    if (pattern_to_index_map == id_to_pattern_map->second.end()) {
1597
4
        return {};
1598
4
    }
1599
5
    return pattern_to_index_map->second;
1600
9
}
1601
1602
29.0k
std::vector<const TabletIndex*> TabletSchema::inverted_indexs(const TabletColumn& col) const {
1603
    // Some columns(Float, Double, JSONB ...) from the variant do not support inverted index
1604
29.0k
    if (!segment_v2::IndexColumnWriter::check_support_inverted_index(col)) {
1605
394
        return {};
1606
394
    }
1607
1608
    // TODO use more efficient impl
1609
    // Use parent id if unique not assigned, this could happend when accessing subcolumns of variants
1610
28.6k
    int32_t col_unique_id = col.is_extracted_column() ? col.parent_unique_id() : col.unique_id();
1611
28.6k
    std::vector<const TabletIndex*> result;
1612
28.6k
    if (result = inverted_indexs(col_unique_id, escape_for_path_name(col.suffix_path()));
1613
28.6k
        !result.empty()) {
1614
5.20k
        return result;
1615
5.20k
    }
1616
    // variant's typed column has it's own index
1617
23.4k
    else if (col.is_extracted_column() && col.path_info_ptr()->get_is_typed()) {
1618
2
        std::string relative_path = col.path_info_ptr()->copy_pop_front().get_path();
1619
2
        if (_path_set_info_map.find(col_unique_id) == _path_set_info_map.end()) {
1620
0
            return result;
1621
0
        }
1622
2
        const auto& path_set_info = _path_set_info_map.at(col_unique_id);
1623
2
        if (path_set_info.typed_path_set.find(relative_path) ==
1624
2
            path_set_info.typed_path_set.end()) {
1625
0
            return result;
1626
0
        }
1627
2
        for (const auto& index : path_set_info.typed_path_set.at(relative_path).indexes) {
1628
2
            result.push_back(index.get());
1629
2
        }
1630
2
        return result;
1631
2
    }
1632
    // variant's subcolumns has it's own index
1633
23.4k
    else if (col.is_extracted_column()) {
1634
3
        std::string relative_path = col.path_info_ptr()->copy_pop_front().get_path();
1635
3
        if (_path_set_info_map.find(col_unique_id) == _path_set_info_map.end()) {
1636
1
            return result;
1637
1
        }
1638
2
        const auto& path_set_info = _path_set_info_map.at(col_unique_id);
1639
2
        if (path_set_info.subcolumn_indexes.find(relative_path) ==
1640
2
            path_set_info.subcolumn_indexes.end()) {
1641
1
            return result;
1642
1
        }
1643
1
        for (const auto& index : path_set_info.subcolumn_indexes.at(relative_path)) {
1644
1
            result.push_back(index.get());
1645
1
        }
1646
1
    }
1647
23.4k
    return result;
1648
28.6k
}
1649
1650
const TabletIndex* TabletSchema::ann_index(int32_t col_unique_id,
1651
8
                                           const std::string& suffix_path) const {
1652
8
    for (size_t i = 0; i < _indexes.size(); i++) {
1653
4
        if (_indexes[i]->index_type() == IndexType::ANN) {
1654
4
            for (int32_t id : _indexes[i]->col_unique_ids()) {
1655
4
                if (id == col_unique_id &&
1656
4
                    _indexes[i]->get_index_suffix() == escape_for_path_name(suffix_path)) {
1657
4
                    return _indexes[i].get();
1658
4
                }
1659
4
            }
1660
4
        }
1661
4
    }
1662
4
    return nullptr;
1663
8
}
1664
1665
26.1k
const TabletIndex* TabletSchema::ann_index(const TabletColumn& col) const {
1666
26.1k
    if (!segment_v2::IndexColumnWriter::check_support_ann_index(col)) {
1667
26.1k
        return nullptr;
1668
26.1k
    }
1669
    // TODO use more efficient impl
1670
    // Use parent id if unique not assigned, this could happend when accessing subcolumns of variants
1671
8
    int32_t col_unique_id = col.is_extracted_column() ? col.parent_unique_id() : col.unique_id();
1672
8
    return ann_index(col_unique_id, escape_for_path_name(col.suffix_path()));
1673
26.1k
}
1674
1675
0
bool TabletSchema::has_ngram_bf_index(int32_t col_unique_id) const {
1676
0
    IndexKey index_key(IndexType::NGRAM_BF, col_unique_id, "");
1677
0
    auto it = _col_id_suffix_to_index.find(index_key);
1678
0
    return it != _col_id_suffix_to_index.end();
1679
0
}
1680
1681
15.9k
const TabletIndex* TabletSchema::get_ngram_bf_index(int32_t col_unique_id) const {
1682
    // Get the ngram bf index for the given column unique id
1683
15.9k
    IndexKey index_key(IndexType::NGRAM_BF, col_unique_id, "");
1684
15.9k
    auto it = _col_id_suffix_to_index.find(index_key);
1685
15.9k
    if (it != _col_id_suffix_to_index.end()) {
1686
1
        if (!it->second.empty() && it->second[0] < _indexes.size()) {
1687
1
            return _indexes[it->second[0]].get();
1688
1
        }
1689
1
    }
1690
15.9k
    return nullptr;
1691
15.9k
}
1692
1693
const TabletIndex* TabletSchema::get_index(int32_t col_unique_id, IndexType index_type,
1694
14
                                           const std::string& suffix_path) const {
1695
14
    IndexKey index_key(index_type, col_unique_id, suffix_path);
1696
14
    auto it = _col_id_suffix_to_index.find(index_key);
1697
14
    if (it != _col_id_suffix_to_index.end()) {
1698
12
        if (!it->second.empty() && it->second[0] < _indexes.size()) {
1699
12
            return _indexes[it->second[0]].get();
1700
12
        }
1701
12
    }
1702
2
    return nullptr;
1703
14
}
1704
1705
vectorized::Block TabletSchema::create_block(
1706
        const std::vector<uint32_t>& return_columns,
1707
724
        const std::unordered_set<uint32_t>* tablet_columns_need_convert_null) const {
1708
724
    vectorized::Block block;
1709
2.86k
    for (int i = 0; i < return_columns.size(); ++i) {
1710
2.13k
        const ColumnId cid = return_columns[i];
1711
2.13k
        const auto& col = *_cols[cid];
1712
2.13k
        bool is_nullable = (tablet_columns_need_convert_null != nullptr &&
1713
2.13k
                            tablet_columns_need_convert_null->find(cid) !=
1714
0
                                    tablet_columns_need_convert_null->end());
1715
2.13k
        auto data_type = vectorized::DataTypeFactory::instance().create_data_type(col, is_nullable);
1716
2.13k
        if (col.type() == FieldType::OLAP_FIELD_TYPE_STRUCT ||
1717
2.13k
            col.type() == FieldType::OLAP_FIELD_TYPE_MAP ||
1718
2.13k
            col.type() == FieldType::OLAP_FIELD_TYPE_ARRAY) {
1719
2
            if (_pruned_columns_data_type.contains(col.unique_id())) {
1720
0
                data_type = _pruned_columns_data_type.at(col.unique_id());
1721
0
            }
1722
2
        }
1723
1724
2.13k
        if (_vir_col_idx_to_unique_id.contains(cid)) {
1725
0
            block.insert({vectorized::ColumnNothing::create(0), data_type, col.name()});
1726
0
            VLOG_DEBUG << fmt::format(
1727
0
                    "Create block from tablet schema, column cid {} is virtual column, col_name: "
1728
0
                    "{}, col_unique_id: {}, type {}",
1729
0
                    cid, col.name(), col.unique_id(), data_type->get_name());
1730
2.13k
        } else {
1731
2.13k
            block.insert({data_type->create_column(), data_type, col.name()});
1732
2.13k
        }
1733
2.13k
    }
1734
724
    return block;
1735
724
}
1736
1737
1.99k
vectorized::Block TabletSchema::create_block(bool ignore_dropped_col) const {
1738
1.99k
    vectorized::Block block;
1739
6.34k
    for (const auto& col : _cols) {
1740
6.34k
        if (ignore_dropped_col && is_dropped_column(*col)) {
1741
0
            continue;
1742
0
        }
1743
1744
6.34k
        auto data_type = vectorized::DataTypeFactory::instance().create_data_type(*col);
1745
6.34k
        if (col->type() == FieldType::OLAP_FIELD_TYPE_STRUCT) {
1746
0
            if (_pruned_columns_data_type.contains(col->unique_id())) {
1747
0
                data_type = _pruned_columns_data_type.at(col->unique_id());
1748
0
            }
1749
0
        }
1750
6.34k
        block.insert({data_type->create_column(), data_type, col->name()});
1751
6.34k
    }
1752
1.99k
    return block;
1753
1.99k
}
1754
1755
0
vectorized::Block TabletSchema::create_block_by_cids(const std::vector<uint32_t>& cids) const {
1756
0
    vectorized::Block block;
1757
0
    for (const auto& cid : cids) {
1758
0
        const auto& col = *_cols[cid];
1759
0
        auto data_type = vectorized::DataTypeFactory::instance().create_data_type(col);
1760
0
        if (col.type() == FieldType::OLAP_FIELD_TYPE_STRUCT) {
1761
0
            if (_pruned_columns_data_type.contains(col.unique_id())) {
1762
0
                data_type = _pruned_columns_data_type.at(col.unique_id());
1763
0
            }
1764
0
        }
1765
0
        block.insert({data_type->create_column(), data_type, col.name()});
1766
0
    }
1767
0
    return block;
1768
0
}
1769
1770
0
bool operator==(const TabletColumn& a, const TabletColumn& b) {
1771
0
    if (a._unique_id != b._unique_id) return false;
1772
0
    if (a._col_name != b._col_name) return false;
1773
0
    if (a._type != b._type) return false;
1774
0
    if (a._is_key != b._is_key) return false;
1775
0
    if (a._aggregation != b._aggregation) return false;
1776
0
    if (a._is_nullable != b._is_nullable) return false;
1777
0
    if (a._has_default_value != b._has_default_value) return false;
1778
0
    if (a._has_default_value) {
1779
0
        if (a._default_value != b._default_value) return false;
1780
0
    }
1781
0
    if (a._is_decimal != b._is_decimal) return false;
1782
0
    if (a._is_decimal) {
1783
0
        if (a._precision != b._precision) return false;
1784
0
        if (a._frac != b._frac) return false;
1785
0
    }
1786
0
    if (a._length != b._length) return false;
1787
0
    if (a._index_length != b._index_length) return false;
1788
0
    if (a._is_bf_column != b._is_bf_column) return false;
1789
0
    if (a._column_path == nullptr && a._column_path != nullptr) return false;
1790
0
    if (b._column_path == nullptr && a._column_path != nullptr) return false;
1791
0
    if (b._column_path != nullptr && a._column_path != nullptr &&
1792
0
        *a._column_path != *b._column_path)
1793
0
        return false;
1794
0
    return true;
1795
0
}
1796
1797
0
bool operator!=(const TabletColumn& a, const TabletColumn& b) {
1798
0
    return !(a == b);
1799
0
}
1800
1801
3
bool operator==(const TabletSchema& a, const TabletSchema& b) {
1802
3
    if (a._keys_type != b._keys_type) return false;
1803
3
    if (a._cols.size() != b._cols.size()) return false;
1804
3
    for (int i = 0; i < a._cols.size(); ++i) {
1805
0
        if (*a._cols[i] != *b._cols[i]) return false;
1806
0
    }
1807
3
    if (a._num_columns != b._num_columns) return false;
1808
3
    if (a._num_key_columns != b._num_key_columns) return false;
1809
3
    if (a._num_null_columns != b._num_null_columns) return false;
1810
3
    if (a._num_short_key_columns != b._num_short_key_columns) return false;
1811
3
    if (a._num_rows_per_row_block != b._num_rows_per_row_block) return false;
1812
3
    if (a._compress_kind != b._compress_kind) return false;
1813
3
    if (a._next_column_unique_id != b._next_column_unique_id) return false;
1814
3
    if (a._has_bf_fpp != b._has_bf_fpp) return false;
1815
3
    if (a._has_bf_fpp) {
1816
0
        if (std::abs(a._bf_fpp - b._bf_fpp) > 1e-6) return false;
1817
0
    }
1818
3
    if (a._is_in_memory != b._is_in_memory) return false;
1819
3
    if (a._delete_sign_idx != b._delete_sign_idx) return false;
1820
3
    if (a._disable_auto_compaction != b._disable_auto_compaction) return false;
1821
3
    if (a._enable_single_replica_compaction != b._enable_single_replica_compaction) return false;
1822
3
    if (a._store_row_column != b._store_row_column) return false;
1823
3
    if (a._row_store_page_size != b._row_store_page_size) return false;
1824
3
    if (a._storage_page_size != b._storage_page_size) return false;
1825
3
    if (a._storage_dict_page_size != b._storage_dict_page_size) return false;
1826
3
    if (a._skip_write_index_on_load != b._skip_write_index_on_load) return false;
1827
3
    if (a._enable_variant_flatten_nested != b._enable_variant_flatten_nested) return false;
1828
3
    if (a._is_external_segment_column_meta_used != b._is_external_segment_column_meta_used)
1829
0
        return false;
1830
3
    if (a._integer_type_default_use_plain_encoding != b._integer_type_default_use_plain_encoding)
1831
0
        return false;
1832
3
    if (a._binary_plain_encoding_default_impl != b._binary_plain_encoding_default_impl)
1833
0
        return false;
1834
3
    return true;
1835
3
}
1836
1837
3
bool operator!=(const TabletSchema& a, const TabletSchema& b) {
1838
3
    return !(a == b);
1839
3
}
1840
#include "common/compile_check_end.h"
1841
} // namespace doris