Coverage Report

Created: 2025-07-26 23:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/field.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 <cstddef>
21
#include <sstream>
22
#include <string>
23
24
#include "olap/key_coder.h"
25
#include "olap/olap_common.h"
26
#include "olap/olap_define.h"
27
#include "olap/row_cursor_cell.h"
28
#include "olap/tablet_schema.h"
29
#include "olap/types.h"
30
#include "olap/utils.h"
31
#include "runtime/collection_value.h"
32
#include "runtime/map_value.h"
33
#include "util/hash_util.hpp"
34
#include "util/slice.h"
35
#include "vec/common/arena.h"
36
#include "vec/json/path_in_data.h"
37
38
namespace doris {
39
#include "common/compile_check_begin.h"
40
// A Field is used to represent a column in memory format.
41
// User can use this class to access or deal with column data in memory.
42
class Field {
43
public:
44
    Field(const TabletColumn& column)
45
224M
            : _type_info(get_type_info(&column)),
46
224M
              _desc(column),
47
224M
              _length(column.length()),
48
224M
              _key_coder(get_key_coder(column.type())),
49
224M
              _name(column.name()),
50
224M
              _index_size(column.index_length()),
51
224M
              _is_nullable(column.is_nullable()),
52
224M
              _unique_id(column.unique_id()),
53
224M
              _parent_unique_id(column.parent_unique_id()),
54
224M
              _is_extracted_column(column.is_extracted_column()),
55
224M
              _path(column.path_info_ptr()) {}
56
57
225M
    virtual ~Field() = default;
58
59
295M
    size_t size() const { return _type_info->size(); }
60
0
    size_t length() const { return _length; }
61
0
    size_t field_size() const { return size() + 1; }
62
0
    size_t index_size() const { return _index_size; }
63
254M
    int32_t unique_id() const { return _unique_id; }
64
194M
    int32_t parent_unique_id() const { return _parent_unique_id; }
65
47.3M
    bool is_extracted_column() const { return _is_extracted_column; }
66
153M
    const std::string& name() const { return _name; }
67
193M
    const vectorized::PathInDataPtr& path() const { return _path; }
68
69
2.85M
    virtual void set_to_max(char* buf) const { return _type_info->set_to_max(buf); }
70
2.85M
    virtual void set_to_zone_map_max(char* buf) const { set_to_max(buf); }
71
72
3.41M
    virtual void set_to_min(char* buf) const { return _type_info->set_to_min(buf); }
73
3.41M
    virtual void set_to_zone_map_min(char* buf) const { set_to_min(buf); }
74
75
5.60M
    void set_long_text_buf(char** buf) { _long_text_buf = buf; }
76
77
    // This function allocate memory from arena, other than allocate_memory
78
    // reserve memory from continuous memory.
79
3.67M
    virtual char* allocate_value(vectorized::Arena& arena) const {
80
3.67M
        return arena.alloc(_type_info->size());
81
3.67M
    }
82
83
3.67M
    virtual char* allocate_zone_map_value(vectorized::Arena& arena) const {
84
3.67M
        return allocate_value(arena);
85
3.67M
    }
86
87
17.9M
    virtual size_t get_variable_len() const { return 0; }
88
89
1.92M
    virtual void modify_zone_map_index(char*) const {}
90
91
10.0M
    virtual Field* clone() const {
92
10.0M
        auto* local = new Field(_desc);
93
10.0M
        this->clone(local);
94
10.0M
        return local;
95
10.0M
    }
96
97
    // Only compare column content, without considering nullptr condition.
98
    // RETURNS:
99
    //      0 means equal,
100
    //      -1 means left less than right,
101
    //      1 means left bigger than right
102
3.51M
    int compare(const void* left, const void* right) const { return _type_info->cmp(left, right); }
103
104
    // Compare two types of cell.
105
    // This function differs compare in that this function compare cell which
106
    // will consider the condition which cell may be nullptr. While compare only
107
    // compare column content without considering nullptr condition.
108
    // Only compare column content, without considering nullptr condition.
109
    // RETURNS:
110
    //      0 means equal,
111
    //      -1 means left less than right,
112
    //      1 means left bigger than right
113
    template <typename LhsCellType, typename RhsCellType>
114
8.96M
    int compare_cell(const LhsCellType& lhs, const RhsCellType& rhs) const {
115
8.96M
        bool l_null = lhs.is_null();
116
8.96M
        bool r_null = rhs.is_null();
117
8.96M
        if (l_null != r_null) {
118
18.4E
            return l_null ? -1 : 1;
119
1.54M
        }
120
7.42M
        return l_null ? 0 : _type_info->cmp(lhs.cell_ptr(), rhs.cell_ptr());
121
8.96M
    }
Unexecuted instantiation: _ZNK5doris5Field12compare_cellINS_12WrapperFieldES2_EEiRKT_RKT0_
_ZNK5doris5Field12compare_cellINS_13RowCursorCellES2_EEiRKT_RKT0_
Line
Count
Source
114
8.96M
    int compare_cell(const LhsCellType& lhs, const RhsCellType& rhs) const {
115
8.96M
        bool l_null = lhs.is_null();
116
8.96M
        bool r_null = rhs.is_null();
117
8.96M
        if (l_null != r_null) {
118
18.4E
            return l_null ? -1 : 1;
119
1.54M
        }
120
7.42M
        return l_null ? 0 : _type_info->cmp(lhs.cell_ptr(), rhs.cell_ptr());
121
8.96M
    }
122
123
    // Copy source cell's content to destination cell directly.
124
    // For string type, this function assume that destination has
125
    // enough space and copy source content into destination without
126
    // memory allocation.
127
    template <typename DstCellType, typename SrcCellType>
128
0
    void direct_copy(DstCellType* dst, const SrcCellType& src) const {
129
0
        bool is_null = src.is_null();
130
0
        dst->set_is_null(is_null);
131
0
        if (is_null) {
132
0
            return;
133
0
        }
134
0
        if (type() == FieldType::OLAP_FIELD_TYPE_STRING) {
135
0
            auto dst_slice = reinterpret_cast<Slice*>(dst->mutable_cell_ptr());
136
0
            auto src_slice = reinterpret_cast<const Slice*>(src.cell_ptr());
137
0
            if (dst_slice->size < src_slice->size) {
138
0
                *_long_text_buf = static_cast<char*>(realloc(*_long_text_buf, src_slice->size));
139
0
                dst_slice->data = *_long_text_buf;
140
0
                dst_slice->size = src_slice->size;
141
0
            }
142
0
        }
143
0
        return _type_info->direct_copy(dst->mutable_cell_ptr(), src.cell_ptr());
144
0
    }
145
146
    // deep copy source cell' content to destination cell.
147
    // For string type, this will allocate data form arena,
148
    // and copy source's content.
149
    template <typename DstCellType, typename SrcCellType>
150
    void deep_copy(DstCellType* dst, const SrcCellType& src, vectorized::Arena& arena) const {
151
        bool is_null = src.is_null();
152
        dst->set_is_null(is_null);
153
        if (is_null) {
154
            return;
155
        }
156
        _type_info->deep_copy(dst->mutable_cell_ptr(), src.cell_ptr(), arena);
157
    }
158
159
    // used by init scan key stored in string format
160
    // value_string should end with '\0'
161
    Status from_string(char* buf, const std::string& value_string, const int precision = 0,
162
112M
                       const int scale = 0) const {
163
112M
        if (type() == FieldType::OLAP_FIELD_TYPE_STRING && !value_string.empty()) {
164
3.86M
            auto slice = reinterpret_cast<Slice*>(buf);
165
3.86M
            if (slice->size < value_string.size()) {
166
1.82k
                *_long_text_buf = static_cast<char*>(realloc(*_long_text_buf, value_string.size()));
167
1.82k
                slice->data = *_long_text_buf;
168
1.82k
                slice->size = value_string.size();
169
1.82k
            }
170
3.86M
        }
171
112M
        return _type_info->from_string(buf, value_string, precision, scale);
172
112M
    }
173
174
    //  convert inner value to string
175
    //  performance is not considered, only for debug use
176
4.21M
    std::string to_string(const char* src) const { return _type_info->to_string(src); }
177
178
    template <typename CellType>
179
    std::string debug_string(const CellType& cell) const {
180
        std::stringstream ss;
181
        if (cell.is_null()) {
182
            ss << "(null)";
183
        } else {
184
            ss << _type_info->to_string(cell.cell_ptr());
185
        }
186
        return ss.str();
187
    }
188
189
336M
    FieldType type() const { return _type_info->type(); }
190
10.2M
    const TypeInfo* type_info() const { return _type_info.get(); }
191
390M
    bool is_nullable() const { return _is_nullable; }
192
193
    // similar to `full_encode_ascending`, but only encode part (the first `index_size` bytes) of the value.
194
    // only applicable to string type
195
2.27M
    void encode_ascending(const void* value, std::string* buf) const {
196
2.27M
        _key_coder->encode_ascending(value, _index_size, buf);
197
2.27M
    }
198
199
    // encode the provided `value` into `buf`.
200
22.0M
    void full_encode_ascending(const void* value, std::string* buf) const {
201
22.0M
        _key_coder->full_encode_ascending(value, buf);
202
22.0M
    }
203
966k
    void add_sub_field(std::unique_ptr<Field> sub_field) {
204
966k
        _sub_fields.emplace_back(std::move(sub_field));
205
966k
    }
206
268k
    Field* get_sub_field(size_t i) const { return _sub_fields[i].get(); }
207
88.1k
    size_t get_sub_field_count() const { return _sub_fields.size(); }
208
209
12.2M
    void set_precision(int32_t precision) { _precision = precision; }
210
12.2M
    void set_scale(int32_t scale) { _scale = scale; }
211
16.3M
    int32_t get_precision() const { return _precision; }
212
16.3M
    int32_t get_scale() const { return _scale; }
213
199M
    const TabletColumn& get_desc() const { return _desc; }
214
215
protected:
216
    TypeInfoPtr _type_info;
217
    TabletColumn _desc;
218
    // unit : byte
219
    // except for strings, other types have fixed lengths
220
    // Note that, the struct type itself has fixed length, but due to
221
    // its number of subfields is a variable, so the actual length of
222
    // a struct field is not fixed.
223
    size_t _length;
224
    // Since the length of the STRING type cannot be determined,
225
    // only dynamic memory can be used. Arena cannot realize realloc.
226
    // The schema information is shared globally. Therefore,
227
    // dynamic memory can only be managed in thread local mode.
228
    // The memory will be created and released in rowcursor.
229
    char** _long_text_buf = nullptr;
230
231
0
    char* allocate_string_value(vectorized::Arena& arena) const {
232
0
        char* type_value = arena.alloc(sizeof(Slice));
233
0
        auto slice = reinterpret_cast<Slice*>(type_value);
234
0
        slice->size = _length;
235
0
        slice->data = arena.alloc(slice->size);
236
0
        return type_value;
237
0
    }
238
239
29.3M
    void clone(Field* other) const {
240
29.3M
        other->_type_info = clone_type_info(this->_type_info.get());
241
29.3M
        other->_key_coder = this->_key_coder;
242
29.3M
        other->_name = this->_name;
243
29.3M
        other->_index_size = this->_index_size;
244
29.3M
        other->_is_nullable = this->_is_nullable;
245
29.3M
        other->_sub_fields.clear();
246
29.3M
        other->_precision = this->_precision;
247
29.3M
        other->_scale = this->_scale;
248
29.3M
        other->_unique_id = this->_unique_id;
249
29.3M
        other->_parent_unique_id = this->_parent_unique_id;
250
29.3M
        other->_is_extracted_column = this->_is_extracted_column;
251
29.3M
        for (const auto& f : _sub_fields) {
252
0
            Field* item = f->clone();
253
0
            other->add_sub_field(std::unique_ptr<Field>(item));
254
0
        }
255
29.3M
    }
256
257
private:
258
    // maximum length of Field, unit : bytes
259
    // usually equal to length, except for variable-length strings
260
    const KeyCoder* _key_coder;
261
    std::string _name;
262
    size_t _index_size;
263
    bool _is_nullable;
264
    std::vector<std::unique_ptr<Field>> _sub_fields;
265
    int32_t _precision;
266
    int32_t _scale;
267
    int32_t _unique_id;
268
    int32_t _parent_unique_id;
269
    bool _is_extracted_column = false;
270
    vectorized::PathInDataPtr _path;
271
};
272
273
class MapField : public Field {
274
public:
275
116k
    MapField(const TabletColumn& column) : Field(column) {}
276
277
0
    size_t get_variable_len() const override { return _length; }
278
};
279
280
class StructField : public Field {
281
public:
282
63.5k
    StructField(const TabletColumn& column) : Field(column) {}
283
284
0
    size_t get_variable_len() const override {
285
0
        size_t variable_len = _length;
286
0
        for (size_t i = 0; i < get_sub_field_count(); i++) {
287
0
            variable_len += get_sub_field(i)->get_variable_len();
288
0
        }
289
0
        return variable_len;
290
0
    }
291
};
292
293
class ArrayField : public Field {
294
public:
295
498k
    ArrayField(const TabletColumn& column) : Field(column) {}
296
297
0
    size_t get_variable_len() const override { return _length; }
298
};
299
300
class CharField : public Field {
301
public:
302
453k
    CharField(const TabletColumn& column) : Field(column) {}
303
304
2.49k
    size_t get_variable_len() const override { return _length; }
305
306
3.22k
    CharField* clone() const override {
307
3.22k
        auto* local = new CharField(_desc);
308
3.22k
        Field::clone(local);
309
3.22k
        return local;
310
3.22k
    }
311
312
0
    char* allocate_value(vectorized::Arena& arena) const override {
313
0
        return Field::allocate_string_value(arena);
314
0
    }
315
316
0
    void set_to_max(char* ch) const override {
317
0
        auto slice = reinterpret_cast<Slice*>(ch);
318
0
        slice->size = _length;
319
0
        memset(slice->data, 0xFF, slice->size);
320
0
    }
321
322
    // To prevent zone map cost too many memory, if varchar length
323
    // longer than `MAX_ZONE_MAP_INDEX_SIZE`. we just allocate
324
    // `MAX_ZONE_MAP_INDEX_SIZE` of memory
325
102k
    char* allocate_zone_map_value(vectorized::Arena& arena) const override {
326
102k
        char* type_value = arena.alloc(sizeof(Slice));
327
102k
        auto slice = reinterpret_cast<Slice*>(type_value);
328
102k
        slice->size = MAX_ZONE_MAP_INDEX_SIZE > _length ? _length : MAX_ZONE_MAP_INDEX_SIZE;
329
102k
        slice->data = arena.alloc(slice->size);
330
102k
        return type_value;
331
102k
    }
332
333
    // only varchar filed need modify zone map index when zone map max_value
334
    // index longer than `MAX_ZONE_MAP_INDEX_SIZE`. so here we add one
335
    // for the last byte
336
    // In UTF8 encoding, here do not appear 0xff in last byte
337
60.8k
    void modify_zone_map_index(char* src) const override {
338
60.8k
        auto slice = reinterpret_cast<Slice*>(src);
339
60.8k
        if (slice->size == MAX_ZONE_MAP_INDEX_SIZE) {
340
0
            slice->mutable_data()[slice->size - 1] += 1;
341
0
        }
342
60.8k
    }
343
344
86.3k
    void set_to_zone_map_max(char* ch) const override {
345
86.3k
        auto slice = reinterpret_cast<Slice*>(ch);
346
86.3k
        size_t length = _length < MAX_ZONE_MAP_INDEX_SIZE ? _length : MAX_ZONE_MAP_INDEX_SIZE;
347
86.3k
        slice->size = length;
348
86.3k
        memset(slice->data, 0xFF, slice->size);
349
86.3k
    }
350
};
351
352
class VarcharField : public Field {
353
public:
354
59.7M
    VarcharField(const TabletColumn& column) : Field(column) {}
355
356
1
    size_t get_variable_len() const override { return _length - OLAP_VARCHAR_MAX_BYTES; }
357
358
0
    VarcharField* clone() const override {
359
0
        auto* local = new VarcharField(_desc);
360
0
        Field::clone(local);
361
0
        return local;
362
0
    }
363
364
0
    char* allocate_value(vectorized::Arena& arena) const override {
365
0
        return Field::allocate_string_value(arena);
366
0
    }
367
368
    // To prevent zone map cost too many memory, if varchar length
369
    // longer than `MAX_ZONE_MAP_INDEX_SIZE`. we just allocate
370
    // `MAX_ZONE_MAP_INDEX_SIZE` of memory
371
602k
    char* allocate_zone_map_value(vectorized::Arena& arena) const override {
372
602k
        char* type_value = arena.alloc(sizeof(Slice));
373
602k
        auto slice = reinterpret_cast<Slice*>(type_value);
374
602k
        slice->size = MAX_ZONE_MAP_INDEX_SIZE > _length ? _length : MAX_ZONE_MAP_INDEX_SIZE;
375
602k
        slice->data = arena.alloc(slice->size);
376
602k
        return type_value;
377
602k
    }
378
379
    // only varchar/string filed need modify zone map index when zone map max_value
380
    // index longer than `MAX_ZONE_MAP_INDEX_SIZE`. so here we add one
381
    // for the last byte
382
    // In UTF8 encoding, here do not appear 0xff in last byte
383
323k
    void modify_zone_map_index(char* src) const override {
384
323k
        auto slice = reinterpret_cast<Slice*>(src);
385
323k
        if (slice->size == MAX_ZONE_MAP_INDEX_SIZE) {
386
828
            slice->mutable_data()[slice->size - 1] += 1;
387
828
        }
388
323k
    }
389
390
2
    void set_to_max(char* ch) const override {
391
2
        auto slice = reinterpret_cast<Slice*>(ch);
392
2
        slice->size = _length - OLAP_VARCHAR_MAX_BYTES;
393
2
        memset(slice->data, 0xFF, slice->size);
394
2
    }
395
473k
    void set_to_zone_map_max(char* ch) const override {
396
473k
        auto slice = reinterpret_cast<Slice*>(ch);
397
473k
        size_t length = _length < MAX_ZONE_MAP_INDEX_SIZE ? _length : MAX_ZONE_MAP_INDEX_SIZE;
398
399
473k
        slice->size = length - OLAP_VARCHAR_MAX_BYTES;
400
473k
        memset(slice->data, 0xFF, slice->size);
401
473k
    }
402
};
403
class StringField : public Field {
404
public:
405
63.5M
    StringField(const TabletColumn& column) : Field(column) {}
406
407
19.3M
    StringField* clone() const override {
408
19.3M
        auto* local = new StringField(_desc);
409
19.3M
        Field::clone(local);
410
19.3M
        return local;
411
19.3M
    }
412
413
0
    char* allocate_value(vectorized::Arena& arena) const override {
414
0
        return Field::allocate_string_value(arena);
415
0
    }
416
417
1.88M
    char* allocate_zone_map_value(vectorized::Arena& arena) const override {
418
1.88M
        char* type_value = arena.alloc(sizeof(Slice));
419
1.88M
        auto slice = reinterpret_cast<Slice*>(type_value);
420
1.88M
        slice->size = MAX_ZONE_MAP_INDEX_SIZE;
421
1.88M
        slice->data = arena.alloc(slice->size);
422
1.88M
        return type_value;
423
1.88M
    }
424
0
    void set_to_max(char* ch) const override {
425
0
        auto slice = reinterpret_cast<Slice*>(ch);
426
0
        memset(slice->data, 0xFF, slice->size);
427
0
    }
428
    // only varchar/string filed need modify zone map index when zone map max_value
429
    // index longer than `MAX_ZONE_MAP_INDEX_SIZE`. so here we add one
430
    // for the last byte
431
    // In UTF8 encoding, here do not appear 0xff in last byte
432
1.00M
    void modify_zone_map_index(char* src) const override {
433
1.00M
        auto slice = reinterpret_cast<Slice*>(src);
434
1.00M
        if (slice->size == MAX_ZONE_MAP_INDEX_SIZE) {
435
144k
            slice->mutable_data()[slice->size - 1] += 1;
436
144k
        }
437
1.00M
    }
438
439
1.47M
    void set_to_zone_map_max(char* ch) const override {
440
1.47M
        auto slice = reinterpret_cast<Slice*>(ch);
441
1.47M
        memset(slice->data, 0xFF, slice->size);
442
1.47M
    }
443
1.47M
    void set_to_zone_map_min(char* ch) const override {
444
1.47M
        auto slice = reinterpret_cast<Slice*>(ch);
445
1.47M
        memset(slice->data, 0x00, slice->size);
446
1.47M
    }
447
};
448
449
class BitmapAggField : public Field {
450
public:
451
28.7k
    BitmapAggField(const TabletColumn& column) : Field(column) {}
452
453
0
    BitmapAggField* clone() const override {
454
0
        auto* local = new BitmapAggField(_desc);
455
0
        Field::clone(local);
456
0
        return local;
457
0
    }
458
};
459
460
class QuantileStateAggField : public Field {
461
public:
462
10.9k
    QuantileStateAggField(const TabletColumn& column) : Field(column) {}
463
464
0
    QuantileStateAggField* clone() const override {
465
0
        auto* local = new QuantileStateAggField(_desc);
466
0
        Field::clone(local);
467
0
        return local;
468
0
    }
469
};
470
471
class AggStateField : public Field {
472
public:
473
9.50k
    AggStateField(const TabletColumn& column) : Field(column) {}
474
475
0
    AggStateField* clone() const override {
476
0
        auto* local = new AggStateField(_desc);
477
0
        Field::clone(local);
478
0
        return local;
479
0
    }
480
};
481
482
class HllAggField : public Field {
483
public:
484
15.4k
    HllAggField(const TabletColumn& column) : Field(column) {}
485
486
0
    HllAggField* clone() const override {
487
0
        auto* local = new HllAggField(_desc);
488
0
        Field::clone(local);
489
0
        return local;
490
0
    }
491
};
492
493
class FieldFactory {
494
public:
495
196M
    static Field* create(const TabletColumn& column) {
496
        // for key column
497
196M
        if (column.is_key()) {
498
44.9M
            switch (column.type()) {
499
49.8k
            case FieldType::OLAP_FIELD_TYPE_CHAR:
500
49.8k
                return new CharField(column);
501
33.8M
            case FieldType::OLAP_FIELD_TYPE_VARCHAR:
502
33.8M
            case FieldType::OLAP_FIELD_TYPE_STRING:
503
33.8M
                return new StringField(column);
504
0
            case FieldType::OLAP_FIELD_TYPE_STRUCT: {
505
0
                auto* local = new StructField(column);
506
0
                for (uint32_t i = 0; i < column.get_subtype_count(); i++) {
507
0
                    std::unique_ptr<Field> sub_field(
508
0
                            FieldFactory::create(column.get_sub_column(i)));
509
0
                    local->add_sub_field(std::move(sub_field));
510
0
                }
511
0
                return local;
512
33.8M
            }
513
0
            case FieldType::OLAP_FIELD_TYPE_ARRAY: {
514
0
                std::unique_ptr<Field> item_field(FieldFactory::create(column.get_sub_column(0)));
515
0
                auto* local = new ArrayField(column);
516
0
                local->add_sub_field(std::move(item_field));
517
0
                return local;
518
33.8M
            }
519
0
            case FieldType::OLAP_FIELD_TYPE_MAP: {
520
0
                std::unique_ptr<Field> key_field(FieldFactory::create(column.get_sub_column(0)));
521
0
                std::unique_ptr<Field> val_field(FieldFactory::create(column.get_sub_column(1)));
522
0
                auto* local = new MapField(column);
523
0
                local->add_sub_field(std::move(key_field));
524
0
                local->add_sub_field(std::move(val_field));
525
0
                return local;
526
33.8M
            }
527
2.95k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL:
528
2.95k
                [[fallthrough]];
529
130k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL32:
530
130k
                [[fallthrough]];
531
243k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL64:
532
243k
                [[fallthrough]];
533
385k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
534
385k
                [[fallthrough]];
535
511k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
536
511k
                [[fallthrough]];
537
644k
            case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: {
538
644k
                Field* field = new Field(column);
539
644k
                field->set_precision(column.precision());
540
644k
                field->set_scale(column.frac());
541
644k
                return field;
542
511k
            }
543
10.4M
            default:
544
10.4M
                return new Field(column);
545
44.9M
            }
546
44.9M
        }
547
548
        // for value column
549
151M
        switch (column.aggregation()) {
550
150M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE:
551
150M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_SUM:
552
150M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MIN:
553
150M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_MAX:
554
151M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE:
555
151M
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE_IF_NOT_NULL:
556
151M
            switch (column.type()) {
557
401k
            case FieldType::OLAP_FIELD_TYPE_CHAR:
558
401k
                return new CharField(column);
559
59.9M
            case FieldType::OLAP_FIELD_TYPE_VARCHAR:
560
59.9M
                return new VarcharField(column);
561
10.6M
            case FieldType::OLAP_FIELD_TYPE_STRING:
562
10.6M
                return new StringField(column);
563
63.5k
            case FieldType::OLAP_FIELD_TYPE_STRUCT: {
564
63.5k
                auto* local = new StructField(column);
565
297k
                for (uint32_t i = 0; i < column.get_subtype_count(); i++) {
566
234k
                    std::unique_ptr<Field> sub_field(
567
234k
                            FieldFactory::create(column.get_sub_column(i)));
568
234k
                    local->add_sub_field(std::move(sub_field));
569
234k
                }
570
63.5k
                return local;
571
0
            }
572
498k
            case FieldType::OLAP_FIELD_TYPE_ARRAY: {
573
498k
                std::unique_ptr<Field> item_field(FieldFactory::create(column.get_sub_column(0)));
574
498k
                auto* local = new ArrayField(column);
575
498k
                local->add_sub_field(std::move(item_field));
576
498k
                return local;
577
0
            }
578
116k
            case FieldType::OLAP_FIELD_TYPE_MAP: {
579
116k
                DCHECK(column.get_subtype_count() == 2);
580
116k
                auto* local = new MapField(column);
581
116k
                std::unique_ptr<Field> key_field(FieldFactory::create(column.get_sub_column(0)));
582
116k
                std::unique_ptr<Field> value_field(FieldFactory::create(column.get_sub_column(1)));
583
116k
                local->add_sub_field(std::move(key_field));
584
116k
                local->add_sub_field(std::move(value_field));
585
116k
                return local;
586
0
            }
587
6.42k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL:
588
6.42k
                [[fallthrough]];
589
139k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL32:
590
139k
                [[fallthrough]];
591
999k
            case FieldType::OLAP_FIELD_TYPE_DECIMAL64:
592
999k
                [[fallthrough]];
593
1.28M
            case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
594
1.28M
                [[fallthrough]];
595
1.30M
            case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
596
1.30M
                [[fallthrough]];
597
11.5M
            case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: {
598
11.5M
                Field* field = new Field(column);
599
11.5M
                field->set_precision(column.precision());
600
11.5M
                field->set_scale(column.frac());
601
11.5M
                return field;
602
1.30M
            }
603
68.6M
            default:
604
68.6M
                return new Field(column);
605
151M
            }
606
15.4k
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_HLL_UNION:
607
15.4k
            return new HllAggField(column);
608
28.7k
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_BITMAP_UNION:
609
28.7k
            return new BitmapAggField(column);
610
10.9k
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_QUANTILE_UNION:
611
10.9k
            return new QuantileStateAggField(column);
612
9.52k
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_GENERIC:
613
9.52k
            return new AggStateField(column);
614
0
        case FieldAggregationMethod::OLAP_FIELD_AGGREGATION_UNKNOWN:
615
0
            CHECK(false) << ", value column no agg type";
616
0
            return nullptr;
617
151M
        }
618
0
        return nullptr;
619
151M
    }
620
621
103M
    static Field* create_by_type(const FieldType& type) {
622
103M
        TabletColumn column(FieldAggregationMethod::OLAP_FIELD_AGGREGATION_NONE, type);
623
103M
        return create(column);
624
103M
    }
625
};
626
#include "common/compile_check_end.h"
627
} // namespace doris