Coverage Report

Created: 2026-04-14 07:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/row_cursor.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 "storage/row_cursor.h"
19
20
#include <glog/logging.h>
21
22
#include <algorithm>
23
#include <numeric>
24
#include <ostream>
25
26
#include "common/cast_set.h"
27
#include "common/consts.h"
28
#include "core/data_type/primitive_type.h"
29
#include "core/field.h"
30
#include "storage/field.h"
31
#include "storage/olap_common.h"
32
#include "storage/olap_define.h"
33
#include "storage/tablet/tablet_schema.h"
34
#include "storage/types.h"
35
#include "util/slice.h"
36
37
namespace doris {
38
using namespace ErrorCode;
39
40
4.13M
RowCursor::RowCursor() = default;
41
4.13M
RowCursor::~RowCursor() = default;
42
0
RowCursor::RowCursor(RowCursor&&) noexcept = default;
43
0
RowCursor& RowCursor::operator=(RowCursor&&) noexcept = default;
44
45
358
void RowCursor::_init_schema(TabletSchemaSPtr schema, uint32_t column_count) {
46
358
    std::vector<uint32_t> columns(column_count);
47
358
    std::iota(columns.begin(), columns.end(), 0);
48
358
    _schema.reset(new Schema(schema->columns(), columns));
49
358
}
50
51
3.37M
void RowCursor::_init_schema(const std::shared_ptr<Schema>& shared_schema, uint32_t column_count) {
52
3.37M
    _schema.reset(new Schema(*shared_schema));
53
3.37M
}
54
55
94
Status RowCursor::init(TabletSchemaSPtr schema, size_t num_columns) {
56
94
    if (num_columns > schema->num_columns()) {
57
0
        return Status::Error<INVALID_ARGUMENT>(
58
0
                "Input param are invalid. Column count is bigger than num_columns of schema. "
59
0
                "column_count={}, schema.num_columns={}",
60
0
                num_columns, schema->num_columns());
61
0
    }
62
94
    _init_schema(schema, cast_set<uint32_t>(num_columns));
63
    // Initialize all fields as null (TYPE_NULL).
64
94
    _fields.resize(num_columns);
65
94
    return Status::OK();
66
94
}
67
68
0
Status RowCursor::init(TabletSchemaSPtr schema, const OlapTuple& tuple) {
69
0
    size_t key_size = tuple.size();
70
0
    if (key_size > schema->num_columns()) {
71
0
        return Status::Error<INVALID_ARGUMENT>(
72
0
                "Input param are invalid. Column count is bigger than num_columns of schema. "
73
0
                "column_count={}, schema.num_columns={}",
74
0
                key_size, schema->num_columns());
75
0
    }
76
0
    _init_schema(schema, cast_set<uint32_t>(key_size));
77
0
    return from_tuple(tuple);
78
0
}
79
80
Status RowCursor::init(TabletSchemaSPtr schema, const OlapTuple& tuple,
81
3.38M
                       const std::shared_ptr<Schema>& shared_schema) {
82
3.38M
    size_t key_size = tuple.size();
83
3.38M
    if (key_size > schema->num_columns()) {
84
0
        return Status::Error<INVALID_ARGUMENT>(
85
0
                "Input param are invalid. Column count is bigger than num_columns of schema. "
86
0
                "column_count={}, schema.num_columns={}",
87
0
                key_size, schema->num_columns());
88
0
    }
89
3.38M
    _init_schema(shared_schema, cast_set<uint32_t>(key_size));
90
3.38M
    return from_tuple(tuple);
91
3.38M
}
92
93
264
Status RowCursor::init_scan_key(TabletSchemaSPtr schema, std::vector<Field> fields) {
94
264
    size_t key_size = fields.size();
95
264
    if (key_size > schema->num_columns()) {
96
0
        return Status::Error<INVALID_ARGUMENT>(
97
0
                "Input param are invalid. Column count is bigger than num_columns of schema. "
98
0
                "column_count={}, schema.num_columns={}",
99
0
                key_size, schema->num_columns());
100
0
    }
101
264
    _init_schema(schema, cast_set<uint32_t>(key_size));
102
264
    _fields = std::move(fields);
103
264
    return Status::OK();
104
264
}
105
106
3.38M
Status RowCursor::from_tuple(const OlapTuple& tuple) {
107
3.38M
    if (tuple.size() != _schema->num_column_ids()) {
108
0
        return Status::Error<INVALID_ARGUMENT>(
109
0
                "column count does not match. tuple_size={}, field_count={}", tuple.size(),
110
0
                _schema->num_column_ids());
111
0
    }
112
3.38M
    _fields.resize(tuple.size());
113
11.0M
    for (size_t i = 0; i < tuple.size(); ++i) {
114
7.63M
        _fields[i] = tuple.get_field(i);
115
7.63M
    }
116
3.38M
    return Status::OK();
117
3.38M
}
118
119
751k
RowCursor RowCursor::clone() const {
120
751k
    RowCursor result;
121
751k
    result._schema = std::make_unique<Schema>(*_schema);
122
751k
    result._fields = _fields;
123
751k
    return result;
124
751k
}
125
126
752k
void RowCursor::pad_char_fields() {
127
1.51M
    for (size_t i = 0; i < _fields.size(); ++i) {
128
765k
        const StorageField* col = _schema->column(cast_set<uint32_t>(i));
129
765k
        if (col->type() == FieldType::OLAP_FIELD_TYPE_CHAR && !_fields[i].is_null()) {
130
724
            String padded = _fields[i].get<TYPE_CHAR>();
131
724
            padded.resize(col->length(), '\0');
132
724
            _fields[i] = Field::create_field<TYPE_CHAR>(std::move(padded));
133
724
        }
134
765k
    }
135
752k
}
136
137
8.99M
std::string RowCursor::to_string() const {
138
8.99M
    std::string result;
139
32.6M
    for (size_t i = 0; i < _fields.size(); ++i) {
140
23.6M
        if (i > 0) {
141
14.6M
            result.append("|");
142
14.6M
        }
143
23.6M
        if (_fields[i].is_null()) {
144
362k
            result.append("1&NULL");
145
23.2M
        } else {
146
23.2M
            result.append("0&");
147
23.2M
            result.append(_fields[i].to_debug_string(
148
23.2M
                    _schema->column(cast_set<uint32_t>(i))->get_scale()));
149
23.2M
        }
150
23.6M
    }
151
8.99M
    return result;
152
8.99M
}
153
154
// Convert a Field value to its storage representation via PrimitiveTypeConvertor and encode.
155
// For most types this is an identity conversion; for DATE, DATETIME, DECIMALV2 it does
156
// actual conversion to the olap storage format.
157
template <PrimitiveType PT>
158
static void encode_non_string_field(const StorageField* storage_field, const Field& f,
159
1.11M
                                    bool full_encode, std::string* buf) {
160
1.11M
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
1.11M
    if (full_encode) {
162
460k
        storage_field->full_encode_ascending(&storage_val, buf);
163
657k
    } else {
164
657k
        storage_field->encode_ascending(&storage_val, buf);
165
657k
    }
166
1.11M
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE2EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
2.53k
                                    bool full_encode, std::string* buf) {
160
2.53k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
2.53k
    if (full_encode) {
162
232
        storage_field->full_encode_ascending(&storage_val, buf);
163
2.29k
    } else {
164
2.29k
        storage_field->encode_ascending(&storage_val, buf);
165
2.29k
    }
166
2.53k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE3EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
150k
                                    bool full_encode, std::string* buf) {
160
150k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
150k
    if (full_encode) {
162
6.52k
        storage_field->full_encode_ascending(&storage_val, buf);
163
143k
    } else {
164
143k
        storage_field->encode_ascending(&storage_val, buf);
165
143k
    }
166
150k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE4EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
10.0k
                                    bool full_encode, std::string* buf) {
160
10.0k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
10.0k
    if (full_encode) {
162
2.26k
        storage_field->full_encode_ascending(&storage_val, buf);
163
7.78k
    } else {
164
7.78k
        storage_field->encode_ascending(&storage_val, buf);
165
7.78k
    }
166
10.0k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE5EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
618k
                                    bool full_encode, std::string* buf) {
160
618k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
618k
    if (full_encode) {
162
409k
        storage_field->full_encode_ascending(&storage_val, buf);
163
409k
    } else {
164
209k
        storage_field->encode_ascending(&storage_val, buf);
165
209k
    }
166
618k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE6EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
27.6k
                                    bool full_encode, std::string* buf) {
160
27.6k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
27.6k
    if (full_encode) {
162
5.00k
        storage_field->full_encode_ascending(&storage_val, buf);
163
22.6k
    } else {
164
22.6k
        storage_field->encode_ascending(&storage_val, buf);
165
22.6k
    }
166
27.6k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE7EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
13.2k
                                    bool full_encode, std::string* buf) {
160
13.2k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
13.2k
    if (full_encode) {
162
1.53k
        storage_field->full_encode_ascending(&storage_val, buf);
163
11.6k
    } else {
164
11.6k
        storage_field->encode_ascending(&storage_val, buf);
165
11.6k
    }
166
13.2k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE8EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
8
                                    bool full_encode, std::string* buf) {
160
8
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
8
    if (full_encode) {
162
2
        storage_field->full_encode_ascending(&storage_val, buf);
163
6
    } else {
164
6
        storage_field->encode_ascending(&storage_val, buf);
165
6
    }
166
8
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE9EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
3
                                    bool full_encode, std::string* buf) {
160
3
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
3
    if (full_encode) {
162
1
        storage_field->full_encode_ascending(&storage_val, buf);
163
2
    } else {
164
2
        storage_field->encode_ascending(&storage_val, buf);
165
2
    }
166
3
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE11EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
2.04k
                                    bool full_encode, std::string* buf) {
160
2.04k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
2.04k
    if (full_encode) {
162
1
        storage_field->full_encode_ascending(&storage_val, buf);
163
2.04k
    } else {
164
2.04k
        storage_field->encode_ascending(&storage_val, buf);
165
2.04k
    }
166
2.04k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE12EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
135
                                    bool full_encode, std::string* buf) {
160
135
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
135
    if (full_encode) {
162
1
        storage_field->full_encode_ascending(&storage_val, buf);
163
134
    } else {
164
134
        storage_field->encode_ascending(&storage_val, buf);
165
134
    }
166
135
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE25EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
276k
                                    bool full_encode, std::string* buf) {
160
276k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
276k
    if (full_encode) {
162
30.6k
        storage_field->full_encode_ascending(&storage_val, buf);
163
245k
    } else {
164
245k
        storage_field->encode_ascending(&storage_val, buf);
165
245k
    }
166
276k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE26EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
6.48k
                                    bool full_encode, std::string* buf) {
160
6.48k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
6.48k
    if (full_encode) {
162
1.81k
        storage_field->full_encode_ascending(&storage_val, buf);
163
4.66k
    } else {
164
4.66k
        storage_field->encode_ascending(&storage_val, buf);
165
4.66k
    }
166
6.48k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE42EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
8.02k
                                    bool full_encode, std::string* buf) {
160
8.02k
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
8.02k
    if (full_encode) {
162
3.11k
        storage_field->full_encode_ascending(&storage_val, buf);
163
4.91k
    } else {
164
4.91k
        storage_field->encode_ascending(&storage_val, buf);
165
4.91k
    }
166
8.02k
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE20EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
96
                                    bool full_encode, std::string* buf) {
160
96
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
96
    if (full_encode) {
162
11
        storage_field->full_encode_ascending(&storage_val, buf);
163
85
    } else {
164
85
        storage_field->encode_ascending(&storage_val, buf);
165
85
    }
166
96
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE28EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
431
                                    bool full_encode, std::string* buf) {
160
431
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
431
    if (full_encode) {
162
70
        storage_field->full_encode_ascending(&storage_val, buf);
163
361
    } else {
164
361
        storage_field->encode_ascending(&storage_val, buf);
165
361
    }
166
431
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE29EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
349
                                    bool full_encode, std::string* buf) {
160
349
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
349
    if (full_encode) {
162
54
        storage_field->full_encode_ascending(&storage_val, buf);
163
295
    } else {
164
295
        storage_field->encode_ascending(&storage_val, buf);
165
295
    }
166
349
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE30EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
827
                                    bool full_encode, std::string* buf) {
160
827
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
827
    if (full_encode) {
162
99
        storage_field->full_encode_ascending(&storage_val, buf);
163
728
    } else {
164
728
        storage_field->encode_ascending(&storage_val, buf);
165
728
    }
166
827
}
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE35EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
750
                                    bool full_encode, std::string* buf) {
160
750
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
750
    if (full_encode) {
162
0
        storage_field->full_encode_ascending(&storage_val, buf);
163
750
    } else {
164
750
        storage_field->encode_ascending(&storage_val, buf);
165
750
    }
166
750
}
Unexecuted instantiation: row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE36EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
row_cursor.cpp:_ZN5dorisL23encode_non_string_fieldILNS_13PrimitiveTypeE37EEEvPKNS_12StorageFieldERKNS_5FieldEbPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
159
2
                                    bool full_encode, std::string* buf) {
160
2
    auto storage_val = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
161
2
    if (full_encode) {
162
0
        storage_field->full_encode_ascending(&storage_val, buf);
163
2
    } else {
164
2
        storage_field->encode_ascending(&storage_val, buf);
165
2
    }
166
2
}
167
168
void RowCursor::_encode_field(const StorageField* storage_field, const Field& f, bool full_encode,
169
12.3M
                              std::string* buf) const {
170
12.3M
    FieldType ft = storage_field->type();
171
172
12.3M
    if (field_is_slice_type(ft)) {
173
        // String types: CHAR, VARCHAR, STRING — all stored as String in Field.
174
11.2M
        const String& str = f.get<TYPE_STRING>();
175
176
11.2M
        if (ft == FieldType::OLAP_FIELD_TYPE_CHAR) {
177
            // CHAR type: must pad with \0 to the declared column length
178
759
            size_t col_len = storage_field->length();
179
759
            String padded(col_len, '\0');
180
759
            memcpy(padded.data(), str.data(), std::min(str.size(), col_len));
181
182
759
            Slice slice(padded.data(), col_len);
183
759
            if (full_encode) {
184
32
                storage_field->full_encode_ascending(&slice, buf);
185
727
            } else {
186
727
                storage_field->encode_ascending(&slice, buf);
187
727
            }
188
11.2M
        } else {
189
            // VARCHAR / STRING: use actual length
190
11.2M
            Slice slice(str.data(), str.size());
191
11.2M
            if (full_encode) {
192
11.2M
                storage_field->full_encode_ascending(&slice, buf);
193
11.2M
            } else {
194
18.4k
                storage_field->encode_ascending(&slice, buf);
195
18.4k
            }
196
11.2M
        }
197
11.2M
        return;
198
11.2M
    }
199
200
    // Non-string types: convert Field value to storage format via PrimitiveTypeConvertor,
201
    // then encode. For most types this is an identity conversion.
202
1.11M
    switch (ft) {
203
2.53k
    case FieldType::OLAP_FIELD_TYPE_BOOL:
204
2.53k
        encode_non_string_field<TYPE_BOOLEAN>(storage_field, f, full_encode, buf);
205
2.53k
        break;
206
150k
    case FieldType::OLAP_FIELD_TYPE_TINYINT:
207
150k
        encode_non_string_field<TYPE_TINYINT>(storage_field, f, full_encode, buf);
208
150k
        break;
209
10.0k
    case FieldType::OLAP_FIELD_TYPE_SMALLINT:
210
10.0k
        encode_non_string_field<TYPE_SMALLINT>(storage_field, f, full_encode, buf);
211
10.0k
        break;
212
618k
    case FieldType::OLAP_FIELD_TYPE_INT:
213
618k
        encode_non_string_field<TYPE_INT>(storage_field, f, full_encode, buf);
214
618k
        break;
215
27.6k
    case FieldType::OLAP_FIELD_TYPE_BIGINT:
216
27.6k
        encode_non_string_field<TYPE_BIGINT>(storage_field, f, full_encode, buf);
217
27.6k
        break;
218
13.2k
    case FieldType::OLAP_FIELD_TYPE_LARGEINT:
219
13.2k
        encode_non_string_field<TYPE_LARGEINT>(storage_field, f, full_encode, buf);
220
13.2k
        break;
221
8
    case FieldType::OLAP_FIELD_TYPE_FLOAT:
222
8
        encode_non_string_field<TYPE_FLOAT>(storage_field, f, full_encode, buf);
223
8
        break;
224
3
    case FieldType::OLAP_FIELD_TYPE_DOUBLE:
225
3
        encode_non_string_field<TYPE_DOUBLE>(storage_field, f, full_encode, buf);
226
3
        break;
227
2.04k
    case FieldType::OLAP_FIELD_TYPE_DATE:
228
2.04k
        encode_non_string_field<TYPE_DATE>(storage_field, f, full_encode, buf);
229
2.04k
        break;
230
135
    case FieldType::OLAP_FIELD_TYPE_DATETIME:
231
135
        encode_non_string_field<TYPE_DATETIME>(storage_field, f, full_encode, buf);
232
135
        break;
233
276k
    case FieldType::OLAP_FIELD_TYPE_DATEV2:
234
276k
        encode_non_string_field<TYPE_DATEV2>(storage_field, f, full_encode, buf);
235
276k
        break;
236
6.48k
    case FieldType::OLAP_FIELD_TYPE_DATETIMEV2:
237
6.48k
        encode_non_string_field<TYPE_DATETIMEV2>(storage_field, f, full_encode, buf);
238
6.48k
        break;
239
8.02k
    case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ:
240
8.02k
        encode_non_string_field<TYPE_TIMESTAMPTZ>(storage_field, f, full_encode, buf);
241
8.02k
        break;
242
96
    case FieldType::OLAP_FIELD_TYPE_DECIMAL:
243
96
        encode_non_string_field<TYPE_DECIMALV2>(storage_field, f, full_encode, buf);
244
96
        break;
245
431
    case FieldType::OLAP_FIELD_TYPE_DECIMAL32:
246
431
        encode_non_string_field<TYPE_DECIMAL32>(storage_field, f, full_encode, buf);
247
431
        break;
248
349
    case FieldType::OLAP_FIELD_TYPE_DECIMAL64:
249
349
        encode_non_string_field<TYPE_DECIMAL64>(storage_field, f, full_encode, buf);
250
349
        break;
251
827
    case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
252
827
        encode_non_string_field<TYPE_DECIMAL128I>(storage_field, f, full_encode, buf);
253
827
        break;
254
750
    case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
255
750
        encode_non_string_field<TYPE_DECIMAL256>(storage_field, f, full_encode, buf);
256
750
        break;
257
0
    case FieldType::OLAP_FIELD_TYPE_IPV4:
258
0
        encode_non_string_field<TYPE_IPV4>(storage_field, f, full_encode, buf);
259
0
        break;
260
2
    case FieldType::OLAP_FIELD_TYPE_IPV6:
261
2
        encode_non_string_field<TYPE_IPV6>(storage_field, f, full_encode, buf);
262
2
        break;
263
0
    default:
264
0
        LOG(FATAL) << "unsupported field type for encoding: " << int(ft);
265
0
        break;
266
1.11M
    }
267
1.11M
}
268
269
template <bool is_mow>
270
void RowCursor::encode_key_with_padding(std::string* buf, size_t num_keys,
271
3.71M
                                        bool padding_minimal) const {
272
15.8M
    for (uint32_t cid = 0; cid < num_keys; cid++) {
273
15.6M
        auto* storage_field = _schema->column(cid);
274
15.6M
        if (storage_field == nullptr) {
275
3.46M
            if (padding_minimal) {
276
1.60M
                buf->push_back(KeyConsts::KEY_MINIMAL_MARKER);
277
1.86M
            } else {
278
1.86M
                if (is_mow) {
279
1.55M
                    buf->push_back(KeyConsts::KEY_NORMAL_NEXT_MARKER);
280
1.55M
                } else {
281
312k
                    buf->push_back(KeyConsts::KEY_MAXIMAL_MARKER);
282
312k
                }
283
1.86M
            }
284
3.46M
            break;
285
3.46M
        }
286
287
12.1M
        if (cid >= _fields.size() || _fields[cid].is_null()) {
288
111k
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
289
111k
            continue;
290
111k
        }
291
292
12.0M
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
293
12.0M
        _encode_field(storage_field, _fields[cid], is_mow, buf);
294
12.0M
    }
295
3.71M
}
_ZNK5doris9RowCursor23encode_key_with_paddingILb0EEEvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb
Line
Count
Source
271
751k
                                        bool padding_minimal) const {
272
1.51M
    for (uint32_t cid = 0; cid < num_keys; cid++) {
273
1.31M
        auto* storage_field = _schema->column(cid);
274
1.31M
        if (storage_field == nullptr) {
275
553k
            if (padding_minimal) {
276
240k
                buf->push_back(KeyConsts::KEY_MINIMAL_MARKER);
277
312k
            } else {
278
312k
                if (is_mow) {
279
0
                    buf->push_back(KeyConsts::KEY_NORMAL_NEXT_MARKER);
280
312k
                } else {
281
312k
                    buf->push_back(KeyConsts::KEY_MAXIMAL_MARKER);
282
312k
                }
283
312k
            }
284
553k
            break;
285
553k
        }
286
287
764k
        if (cid >= _fields.size() || _fields[cid].is_null()) {
288
95.7k
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
289
95.7k
            continue;
290
95.7k
        }
291
292
666k
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
293
666k
        _encode_field(storage_field, _fields[cid], is_mow, buf);
294
666k
    }
295
751k
}
_ZNK5doris9RowCursor23encode_key_with_paddingILb1EEEvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb
Line
Count
Source
271
2.96M
                                        bool padding_minimal) const {
272
14.3M
    for (uint32_t cid = 0; cid < num_keys; cid++) {
273
14.2M
        auto* storage_field = _schema->column(cid);
274
14.2M
        if (storage_field == nullptr) {
275
2.91M
            if (padding_minimal) {
276
1.35M
                buf->push_back(KeyConsts::KEY_MINIMAL_MARKER);
277
1.55M
            } else {
278
1.55M
                if (is_mow) {
279
1.55M
                    buf->push_back(KeyConsts::KEY_NORMAL_NEXT_MARKER);
280
18.4E
                } else {
281
18.4E
                    buf->push_back(KeyConsts::KEY_MAXIMAL_MARKER);
282
18.4E
                }
283
1.55M
            }
284
2.91M
            break;
285
2.91M
        }
286
287
11.3M
        if (cid >= _fields.size() || _fields[cid].is_null()) {
288
15.4k
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
289
15.4k
            continue;
290
15.4k
        }
291
292
11.3M
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
293
11.3M
        _encode_field(storage_field, _fields[cid], is_mow, buf);
294
11.3M
    }
295
2.96M
}
296
297
// Explicit template instantiations
298
template void RowCursor::encode_key_with_padding<false>(std::string*, size_t, bool) const;
299
template void RowCursor::encode_key_with_padding<true>(std::string*, size_t, bool) const;
300
301
template <bool full_encode>
302
129k
void RowCursor::encode_key(std::string* buf, size_t num_keys) const {
303
387k
    for (uint32_t cid = 0; cid < num_keys; cid++) {
304
258k
        if (cid >= _fields.size() || _fields[cid].is_null()) {
305
6
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
306
6
            continue;
307
6
        }
308
258k
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
309
258k
        _encode_field(_schema->column(cid), _fields[cid], full_encode, buf);
310
258k
    }
311
129k
}
_ZNK5doris9RowCursor10encode_keyILb0EEEvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
302
33
void RowCursor::encode_key(std::string* buf, size_t num_keys) const {
303
82
    for (uint32_t cid = 0; cid < num_keys; cid++) {
304
49
        if (cid >= _fields.size() || _fields[cid].is_null()) {
305
6
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
306
6
            continue;
307
6
        }
308
43
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
309
43
        _encode_field(_schema->column(cid), _fields[cid], full_encode, buf);
310
43
    }
311
33
}
_ZNK5doris9RowCursor10encode_keyILb1EEEvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
302
129k
void RowCursor::encode_key(std::string* buf, size_t num_keys) const {
303
387k
    for (uint32_t cid = 0; cid < num_keys; cid++) {
304
258k
        if (cid >= _fields.size() || _fields[cid].is_null()) {
305
0
            buf->push_back(KeyConsts::KEY_NULL_FIRST_MARKER);
306
0
            continue;
307
0
        }
308
258k
        buf->push_back(KeyConsts::KEY_NORMAL_MARKER);
309
258k
        _encode_field(_schema->column(cid), _fields[cid], full_encode, buf);
310
258k
    }
311
129k
}
312
313
template void RowCursor::encode_key<false>(std::string*, size_t) const;
314
template void RowCursor::encode_key<true>(std::string*, size_t) const;
315
316
} // namespace doris