Coverage Report

Created: 2026-10-29 11:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/core/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
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Field.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <fmt/format.h>
24
#include <glog/logging.h>
25
26
#include <algorithm>
27
#include <cassert>
28
#include <cmath>
29
#include <cstring>
30
#include <string>
31
#include <string_view>
32
#include <type_traits>
33
#include <utility>
34
#include <vector>
35
36
#include "common/compiler_util.h" // IWYU pragma: keep
37
#include "common/exception.h"
38
#include "core/data_type/primitive_type.h"
39
#include "core/string_view.h"
40
#include "core/types.h"
41
#include "core/uint128.h"
42
#include "core/value/bitmap_value.h"
43
#include "core/value/hll.h"
44
#include "core/value/quantile_state.h"
45
#include "core/value/variant/variant_field.h"
46
47
namespace doris {
48
template <PrimitiveType type>
49
struct PrimitiveTypeTraits;
50
template <typename T>
51
struct TypeName;
52
struct PackedInt128;
53
} // namespace doris
54
55
namespace doris {
56
57
class Field;
58
59
using FieldVector = std::vector<Field>;
60
61
/// Array and Struct use the same storage type -- FieldVector, but we declare
62
/// distinct types for them, so that the caller can choose whether it wants to
63
/// construct a Field of Array or a Struct type. An alternative approach would be
64
/// to construct both of these types from FieldVector, and have the caller
65
/// specify the desired Field type explicitly.
66
struct Array : public FieldVector {
67
    using FieldVector::FieldVector;
68
};
69
70
struct Struct : public FieldVector {
71
    using FieldVector::FieldVector;
72
};
73
74
struct Map : public FieldVector {
75
    using FieldVector::FieldVector;
76
};
77
78
//TODO: rethink if we really need this? it only save one pointer from std::string
79
// not POD type so could only use read/write_json_binary instead of read/write_binary
80
class JsonbField {
81
public:
82
43.9k
    JsonbField() = default;
83
175k
    ~JsonbField() = default; // unique_ptr will handle cleanup automatically
84
85
44.0k
    JsonbField(const char* ptr, size_t len) : size(len) {
86
44.0k
        data = std::make_unique<char[]>(size);
87
44.0k
        if (!data) {
88
0
            throw Exception(Status::FatalError("new data buffer failed, size: {}", size));
89
0
        }
90
44.0k
        if (size > 0) {
91
43.4k
            memcpy(data.get(), ptr, size);
92
43.4k
        }
93
44.0k
    }
94
95
24
    JsonbField(const JsonbField& x) : size(x.size) {
96
24
        data = std::make_unique<char[]>(size);
97
24
        if (!data) {
98
0
            throw Exception(Status::FatalError("new data buffer failed, size: {}", size));
99
0
        }
100
24
        if (size > 0) {
101
24
            memcpy(data.get(), x.data.get(), size);
102
24
        }
103
24
    }
104
105
87.9k
    JsonbField(JsonbField&& x) noexcept : data(std::move(x.data)), size(x.size) { x.size = 0; }
106
107
    // dispatch for all type of storage. so need this. but not really used now.
108
2
    JsonbField& operator=(const JsonbField& x) {
109
2
        if (this != &x) {
110
2
            data = std::make_unique<char[]>(x.size);
111
2
            if (!data) {
112
0
                throw Exception(Status::FatalError("new data buffer failed, size: {}", x.size));
113
0
            }
114
2
            if (x.size > 0) {
115
1
                memcpy(data.get(), x.data.get(), x.size);
116
1
            }
117
2
            size = x.size;
118
2
        }
119
2
        return *this;
120
2
    }
121
122
43.9k
    JsonbField& operator=(JsonbField&& x) noexcept {
123
43.9k
        if (this != &x) {
124
43.9k
            data = std::move(x.data);
125
43.9k
            size = x.size;
126
43.9k
            x.size = 0;
127
43.9k
        }
128
43.9k
        return *this;
129
43.9k
    }
130
131
44.0k
    const char* get_value() const { return data.get(); }
132
44.0k
    size_t get_size() const { return size; }
133
134
0
    bool operator<(const JsonbField& r) const {
135
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
136
0
    }
137
0
    bool operator<=(const JsonbField& r) const {
138
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
139
0
    }
140
0
    bool operator==(const JsonbField& r) const {
141
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
142
0
    }
143
0
    bool operator>(const JsonbField& r) const {
144
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
145
0
    }
146
0
    bool operator>=(const JsonbField& r) const {
147
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
148
0
    }
149
0
    bool operator!=(const JsonbField& r) const {
150
0
        throw Exception(Status::FatalError("comparing between JsonbField is not supported"));
151
0
    }
152
153
0
    const JsonbField& operator+=(const JsonbField& r) {
154
0
        throw Exception(Status::FatalError("Not support plus opration on JsonbField"));
155
0
    }
156
157
0
    const JsonbField& operator-=(const JsonbField& r) {
158
0
        throw Exception(Status::FatalError("Not support minus opration on JsonbField"));
159
0
    }
160
161
private:
162
    std::unique_ptr<char[]> data = nullptr;
163
    size_t size = 0;
164
};
165
166
template <typename T>
167
bool decimal_equal(T x, T y, UInt32 x_scale, UInt32 y_scale);
168
template <typename T>
169
bool decimal_less(T x, T y, UInt32 x_scale, UInt32 y_scale);
170
template <typename T>
171
bool decimal_less_or_equal(T x, T y, UInt32 x_scale, UInt32 y_scale);
172
173
/** 32 is enough. Round number is used for alignment and for better arithmetic inside std::vector.
174
  * NOTE: Actually, sizeof(std::string) is 32 when using libc++, so Field is 40 bytes.
175
  */
176
constexpr size_t DBMS_MIN_FIELD_SIZE = 32;
177
178
/** Discriminated union of several types.
179
  * Made for replacement of `boost::variant`
180
  *  is not generalized,
181
  *  but somewhat more efficient, and simpler.
182
  *
183
  * Used to represent a single value of one of several types in memory.
184
  * Warning! Prefer to use chunks of columns instead of single values. See Column.h
185
  */
186
class Field {
187
public:
188
    static const int MIN_NON_POD = 16;
189
192M
    Field() : type(PrimitiveType::TYPE_NULL) {}
190
    // set Types::Null explictly and avoid other types
191
8.85M
    Field(PrimitiveType w) : type(w) {}
192
    template <PrimitiveType T>
193
30.9M
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
30.9M
        auto f = Field();
197
30.9M
        f.template create_concrete<T>(data);
198
30.9M
        return f;
199
30.9M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE23EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
1.08M
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
1.08M
        auto f = Field();
197
1.08M
        f.template create_concrete<T>(data);
198
1.08M
        return f;
199
1.08M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE37EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
24.3k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
24.3k
        auto f = Field();
197
24.3k
        f.template create_concrete<T>(data);
198
24.3k
        return f;
199
24.3k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE41EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
66
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
66
        auto f = Field();
197
66
        f.template create_concrete<T>(data);
198
66
        return f;
199
66
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE5EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
26.8M
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
26.8M
        auto f = Field();
197
26.8M
        f.template create_concrete<T>(data);
198
26.8M
        return f;
199
26.8M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE17EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
60.0k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
60.0k
        auto f = Field();
197
60.0k
        f.template create_concrete<T>(data);
198
60.0k
        return f;
199
60.0k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE28EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
21.8k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
21.8k
        auto f = Field();
197
21.8k
        f.template create_concrete<T>(data);
198
21.8k
        return f;
199
21.8k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE29EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
29.1k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
29.1k
        auto f = Field();
197
29.1k
        f.template create_concrete<T>(data);
198
29.1k
        return f;
199
29.1k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE20EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
8.65k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
8.65k
        auto f = Field();
197
8.65k
        f.template create_concrete<T>(data);
198
8.65k
        return f;
199
8.65k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE30EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
27.7k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
27.7k
        auto f = Field();
197
27.7k
        f.template create_concrete<T>(data);
198
27.7k
        return f;
199
27.7k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE35EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
38.5k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
38.5k
        auto f = Field();
197
38.5k
        f.template create_concrete<T>(data);
198
38.5k
        return f;
199
38.5k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE19EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
409
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
409
        auto f = Field();
197
409
        f.template create_concrete<T>(data);
198
409
        return f;
199
409
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE24EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
22.3k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
22.3k
        auto f = Field();
197
22.3k
        f.template create_concrete<T>(data);
198
22.3k
        return f;
199
22.3k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE22EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
2.43k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
2.43k
        auto f = Field();
197
2.43k
        f.template create_concrete<T>(data);
198
2.43k
        return f;
199
2.43k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE2EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
30.0k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
30.0k
        auto f = Field();
197
30.0k
        f.template create_concrete<T>(data);
198
30.0k
        return f;
199
30.0k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE3EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
414k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
414k
        auto f = Field();
197
414k
        f.template create_concrete<T>(data);
198
414k
        return f;
199
414k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE4EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
51.7k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
51.7k
        auto f = Field();
197
51.7k
        f.template create_concrete<T>(data);
198
51.7k
        return f;
199
51.7k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE6EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
207k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
207k
        auto f = Field();
197
207k
        f.template create_concrete<T>(data);
198
207k
        return f;
199
207k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE7EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
38.4k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
38.4k
        auto f = Field();
197
38.4k
        f.template create_concrete<T>(data);
198
38.4k
        return f;
199
38.4k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE8EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
47.5k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
47.5k
        auto f = Field();
197
47.5k
        f.template create_concrete<T>(data);
198
47.5k
        return f;
199
47.5k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE9EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
777k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
777k
        auto f = Field();
197
777k
        f.template create_concrete<T>(data);
198
777k
        return f;
199
777k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE36EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
33.7k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
33.7k
        auto f = Field();
197
33.7k
        f.template create_concrete<T>(data);
198
33.7k
        return f;
199
33.7k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE44EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
107k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
107k
        auto f = Field();
197
107k
        f.template create_concrete<T>(data);
198
107k
        return f;
199
107k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE11EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
13.1k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
13.1k
        auto f = Field();
197
13.1k
        f.template create_concrete<T>(data);
198
13.1k
        return f;
199
13.1k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE25EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
578k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
578k
        auto f = Field();
197
578k
        f.template create_concrete<T>(data);
198
578k
        return f;
199
578k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE12EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
13.9k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
13.9k
        auto f = Field();
197
13.9k
        f.template create_concrete<T>(data);
198
13.9k
        return f;
199
13.9k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE26EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
99.7k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
99.7k
        auto f = Field();
197
99.7k
        f.template create_concrete<T>(data);
198
99.7k
        return f;
199
99.7k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE43EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
6.77k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
6.77k
        auto f = Field();
197
6.77k
        f.template create_concrete<T>(data);
198
6.77k
        return f;
199
6.77k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE27EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
325
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
325
        auto f = Field();
197
325
        f.template create_concrete<T>(data);
198
325
        return f;
199
325
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE42EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
17.2k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
17.2k
        auto f = Field();
197
17.2k
        f.template create_concrete<T>(data);
198
17.2k
        return f;
199
17.2k
    }
Unexecuted instantiation: _ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE38EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Unexecuted instantiation: _ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE39EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE15EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
1.11k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
1.11k
        auto f = Field();
197
1.11k
        f.template create_concrete<T>(data);
198
1.11k
        return f;
199
1.11k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE10EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
324k
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
324k
        auto f = Field();
197
324k
        f.template create_concrete<T>(data);
198
324k
        return f;
199
324k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE31EEES0_RKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
193
9
    static Field create_field(const typename PrimitiveTypeTraits<T>::CppType& data) {
194
        // Publish the type only after construction succeeds, so allocation failures cannot
195
        // destroy uninitialized owned storage (including long binary values).
196
9
        auto f = Field();
197
9
        f.template create_concrete<T>(data);
198
9
        return f;
199
9
    }
200
    template <PrimitiveType T>
201
93.5M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
93.5M
        auto f = Field();
203
93.5M
        f.template create_concrete<T>(std::move(data));
204
93.5M
        return f;
205
93.5M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE23EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
17.6M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
17.6M
        auto f = Field();
203
17.6M
        f.template create_concrete<T>(std::move(data));
204
17.6M
        return f;
205
17.6M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE17EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
133k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
133k
        auto f = Field();
203
133k
        f.template create_concrete<T>(std::move(data));
204
133k
        return f;
205
133k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE1EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
84.8k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
84.8k
        auto f = Field();
203
84.8k
        f.template create_concrete<T>(std::move(data));
204
84.8k
        return f;
205
84.8k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE18EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
24.1k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
24.1k
        auto f = Field();
203
24.1k
        f.template create_concrete<T>(std::move(data));
204
24.1k
        return f;
205
24.1k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE25EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
283k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
283k
        auto f = Field();
203
283k
        f.template create_concrete<T>(std::move(data));
204
283k
        return f;
205
283k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE26EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
2.13M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
2.13M
        auto f = Field();
203
2.13M
        f.template create_concrete<T>(std::move(data));
204
2.13M
        return f;
205
2.13M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE12EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
10.9k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
10.9k
        auto f = Field();
203
10.9k
        f.template create_concrete<T>(std::move(data));
204
10.9k
        return f;
205
10.9k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE28EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
54.6k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
54.6k
        auto f = Field();
203
54.6k
        f.template create_concrete<T>(std::move(data));
204
54.6k
        return f;
205
54.6k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE29EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
13.6M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
13.6M
        auto f = Field();
203
13.6M
        f.template create_concrete<T>(std::move(data));
204
13.6M
        return f;
205
13.6M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE20EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
11.4k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
11.4k
        auto f = Field();
203
11.4k
        f.template create_concrete<T>(std::move(data));
204
11.4k
        return f;
205
11.4k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE30EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
103k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
103k
        auto f = Field();
203
103k
        f.template create_concrete<T>(std::move(data));
204
103k
        return f;
205
103k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE35EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
10.7k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
10.7k
        auto f = Field();
203
10.7k
        f.template create_concrete<T>(std::move(data));
204
10.7k
        return f;
205
10.7k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE36EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
5.90k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
5.90k
        auto f = Field();
203
5.90k
        f.template create_concrete<T>(std::move(data));
204
5.90k
        return f;
205
5.90k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE31EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
87.9k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
87.9k
        auto f = Field();
203
87.9k
        f.template create_concrete<T>(std::move(data));
204
87.9k
        return f;
205
87.9k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE44EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
17.3k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
17.3k
        auto f = Field();
203
17.3k
        f.template create_concrete<T>(std::move(data));
204
17.3k
        return f;
205
17.3k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE41EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
181
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
181
        auto f = Field();
203
181
        f.template create_concrete<T>(std::move(data));
204
181
        return f;
205
181
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE22EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
51
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
51
        auto f = Field();
203
51
        f.template create_concrete<T>(std::move(data));
204
51
        return f;
205
51
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE11EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
7.66k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
7.66k
        auto f = Field();
203
7.66k
        f.template create_concrete<T>(std::move(data));
204
7.66k
        return f;
205
7.66k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE19EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
15
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
15
        auto f = Field();
203
15
        f.template create_concrete<T>(std::move(data));
204
15
        return f;
205
15
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE37EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
3.76k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
3.76k
        auto f = Field();
203
3.76k
        f.template create_concrete<T>(std::move(data));
204
3.76k
        return f;
205
3.76k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE16EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
4.49k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
4.49k
        auto f = Field();
203
4.49k
        f.template create_concrete<T>(std::move(data));
204
4.49k
        return f;
205
4.49k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE32EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
6.71k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
6.71k
        auto f = Field();
203
6.71k
        f.template create_concrete<T>(std::move(data));
204
6.71k
        return f;
205
6.71k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE2EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
28.3M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
28.3M
        auto f = Field();
203
28.3M
        f.template create_concrete<T>(std::move(data));
204
28.3M
        return f;
205
28.3M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE3EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
4.54M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
4.54M
        auto f = Field();
203
4.54M
        f.template create_concrete<T>(std::move(data));
204
4.54M
        return f;
205
4.54M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE4EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
122k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
122k
        auto f = Field();
203
122k
        f.template create_concrete<T>(std::move(data));
204
122k
        return f;
205
122k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE5EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
2.05M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
2.05M
        auto f = Field();
203
2.05M
        f.template create_concrete<T>(std::move(data));
204
2.05M
        return f;
205
2.05M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE6EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
22.6M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
22.6M
        auto f = Field();
203
22.6M
        f.template create_concrete<T>(std::move(data));
204
22.6M
        return f;
205
22.6M
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE7EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
166k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
166k
        auto f = Field();
203
166k
        f.template create_concrete<T>(std::move(data));
204
166k
        return f;
205
166k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE8EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
69.5k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
69.5k
        auto f = Field();
203
69.5k
        f.template create_concrete<T>(std::move(data));
204
69.5k
        return f;
205
69.5k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE9EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
85.4k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
85.4k
        auto f = Field();
203
85.4k
        f.template create_concrete<T>(std::move(data));
204
85.4k
        return f;
205
85.4k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE27EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
7
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
7
        auto f = Field();
203
7
        f.template create_concrete<T>(std::move(data));
204
7
        return f;
205
7
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE24EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
12
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
12
        auto f = Field();
203
12
        f.template create_concrete<T>(std::move(data));
204
12
        return f;
205
12
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE42EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
38.9k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
38.9k
        auto f = Field();
203
38.9k
        f.template create_concrete<T>(std::move(data));
204
38.9k
        return f;
205
38.9k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE43EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
1.05k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
1.05k
        auto f = Field();
203
1.05k
        f.template create_concrete<T>(std::move(data));
204
1.05k
        return f;
205
1.05k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE15EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
88.4k
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
88.4k
        auto f = Field();
203
88.4k
        f.template create_concrete<T>(std::move(data));
204
88.4k
        return f;
205
88.4k
    }
_ZN5doris5Field12create_fieldILNS_13PrimitiveTypeE10EEES0_ONS_19PrimitiveTypeTraitsIXT_EE7CppTypeE
Line
Count
Source
201
1.07M
    static Field create_field(typename PrimitiveTypeTraits<T>::CppType&& data) {
202
1.07M
        auto f = Field();
203
1.07M
        f.template create_concrete<T>(std::move(data));
204
1.07M
        return f;
205
1.07M
    }
206
207
    /** Despite the presence of a template constructor, this constructor is still needed,
208
      *  since, in its absence, the compiler will still generate the default constructor.
209
      */
210
    Field(const Field& rhs);
211
212
    Field(Field&& rhs);
213
214
    Field& operator=(const Field& rhs);
215
216
0
    bool is_complex_field() const {
217
0
        return type == PrimitiveType::TYPE_ARRAY || type == PrimitiveType::TYPE_MAP ||
218
0
               type == PrimitiveType::TYPE_STRUCT || type == PrimitiveType::TYPE_VARIANT;
219
0
    }
220
221
62.1M
    Field& operator=(Field&& rhs) {
222
62.1M
        if (this != &rhs) {
223
62.1M
            if (type != rhs.type) {
224
59.6M
                destroy();
225
59.6M
                type = TYPE_NULL;
226
59.6M
                create(std::move(rhs));
227
59.6M
            } else {
228
2.45M
                assign(std::move(rhs));
229
2.45M
            }
230
62.1M
        }
231
62.1M
        return *this;
232
62.1M
    }
233
234
413M
    ~Field() { destroy(); }
235
236
31.1M
    PrimitiveType get_type() const { return type; }
237
    std::string get_type_name() const;
238
239
146M
    bool is_null() const { return type == PrimitiveType::TYPE_NULL; }
240
241
    // The template parameter T needs to be consistent with `which`.
242
    // If not, use NearestFieldType<> externally.
243
    // Maybe modify this in the future, reference: https://github.com/ClickHouse/ClickHouse/pull/22003
244
    template <PrimitiveType T>
245
    typename PrimitiveTypeTraits<T>::CppType& get();
246
247
    template <PrimitiveType T>
248
    const typename PrimitiveTypeTraits<T>::CppType& get() const;
249
250
8.52k
    bool is_nan() const {
251
        // Keep type dispatch with the value so callers cannot reinterpret Field storage using a
252
        // mismatched PrimitiveType.
253
8.52k
        if (type == PrimitiveType::TYPE_FLOAT) {
254
474
            return std::isnan(get<TYPE_FLOAT>());
255
474
        }
256
8.05k
        if (type == PrimitiveType::TYPE_DOUBLE) {
257
484
            return std::isnan(get<TYPE_DOUBLE>());
258
484
        }
259
7.57k
        return false;
260
8.05k
    }
261
262
8.54M
    bool operator==(const Field& rhs) const {
263
8.54M
        return operator<=>(rhs) == std::strong_ordering::equal;
264
8.54M
    }
265
266
    std::strong_ordering operator<=>(const Field& rhs) const;
267
268
    std::string_view as_string_view() const;
269
270
    // Return a human-readable representation of the stored value for debugging.
271
    // Unlike get_type_name() which returns the type, this prints the actual value.
272
    // For decimal types, caller can provide scale for accurate formatting.
273
    std::string to_debug_string(int scale) const;
274
275
private:
276
    std::aligned_union_t<DBMS_MIN_FIELD_SIZE - sizeof(PrimitiveType), Null, UInt64, UInt128, Int64,
277
                         Int128, IPv6, Float64, String, JsonbField, StringView, Array, Struct, Map,
278
                         VariantField, Decimal32, Decimal64, DecimalV2Value, Decimal128V3,
279
                         Decimal256, BitmapValue, HyperLogLog, QuantileState>
280
            storage;
281
282
    PrimitiveType type;
283
284
    /// Assuming there was no allocated state or it was deallocated (see destroy).
285
    template <PrimitiveType Type>
286
    void create_concrete(typename PrimitiveTypeTraits<Type>::CppType&& x);
287
    template <PrimitiveType Type>
288
    void create_concrete(const typename PrimitiveTypeTraits<Type>::CppType& x);
289
    /// Assuming same types.
290
    template <PrimitiveType Type>
291
    void assign_concrete(typename PrimitiveTypeTraits<Type>::CppType&& x);
292
    template <PrimitiveType Type>
293
    void assign_concrete(const typename PrimitiveTypeTraits<Type>::CppType& x);
294
295
    void create(const Field& field);
296
    void create(Field&& field);
297
298
    void assign(const Field& x);
299
    void assign(Field&& x);
300
301
    void destroy();
302
303
    template <PrimitiveType T>
304
    void destroy();
305
};
306
307
struct FieldWithDataType {
308
    Field field;
309
    // used for nested type of array
310
    PrimitiveType base_scalar_type_id = PrimitiveType::INVALID_TYPE;
311
    uint8_t num_dimensions = 0;
312
    int precision = -1;
313
    int scale = -1;
314
    // True when the array elements are mixed-type and must be converted to the common base
315
    // type on insert. Mirrors FieldInfo::need_convert so it survives the FieldWithDataType
316
    // round trip in the sparse read path.
317
    bool need_convert = false;
318
};
319
320
} // namespace doris
321
322
template <>
323
struct std::hash<doris::Field> {
324
7.05k
    size_t operator()(const doris::Field& field) const {
325
7.05k
        if (field.is_null()) {
326
295
            return 0;
327
295
        }
328
6.75k
        std::hash<std::string_view> hasher;
329
6.75k
        return hasher(field.as_string_view());
330
7.05k
    }
331
};