Coverage Report

Created: 2025-04-27 02:50

/root/doris/be/src/olap/key_coder.h
Line
Count
Source (jump to first uncovered line)
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 <glog/logging.h>
21
#include <limits.h>
22
#include <stdint.h>
23
#include <string.h>
24
25
#include <algorithm>
26
#include <ostream>
27
#include <string>
28
#include <type_traits>
29
30
#include "absl/strings/substitute.h"
31
#include "common/status.h"
32
#include "gutil/endian.h"
33
#include "olap/decimal12.h"
34
#include "olap/olap_common.h"
35
#include "olap/types.h"
36
#include "util/slice.h"
37
#include "vec/core/types.h"
38
39
namespace doris {
40
41
using FullEncodeAscendingFunc = void (*)(const void* value, std::string* buf);
42
using EncodeAscendingFunc = void (*)(const void* value, size_t index_size, std::string* buf);
43
using DecodeAscendingFunc = Status (*)(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr);
44
45
// Order-preserving binary encoding for values of a particular type so that
46
// those values can be compared by memcpy their encoded bytes.
47
//
48
// To obtain instance of this class, use the `get_key_coder(FieldType)` method.
49
class KeyCoder {
50
public:
51
    template <typename TraitsType>
52
    KeyCoder(TraitsType traits);
53
54
    // encode the provided `value` into `buf`.
55
1.89M
    void full_encode_ascending(const void* value, std::string* buf) const {
56
1.89M
        _full_encode_ascending(value, buf);
57
1.89M
    }
58
59
    // similar to `full_encode_ascending`, but only encode part (the first `index_size` bytes) of the value.
60
    // only applicable to string type
61
23.7k
    void encode_ascending(const void* value, size_t index_size, std::string* buf) const {
62
23.7k
        _encode_ascending(value, index_size, buf);
63
23.7k
    }
64
65
    // Only used for test, should delete it in the future
66
38
    Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const {
67
38
        return _decode_ascending(encoded_key, index_size, cell_ptr);
68
38
    }
69
70
private:
71
    FullEncodeAscendingFunc _full_encode_ascending;
72
    EncodeAscendingFunc _encode_ascending;
73
    DecodeAscendingFunc _decode_ascending;
74
};
75
76
extern const KeyCoder* get_key_coder(FieldType type);
77
78
template <FieldType field_type, typename Enable = void>
79
class KeyCoderTraits {};
80
81
template <FieldType field_type>
82
class KeyCoderTraits<
83
        field_type,
84
        typename std::enable_if<
85
                std::is_integral<typename CppTypeTraits<field_type>::CppType>::value ||
86
                field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256 ||
87
                vectorized::IsDecimalNumber<typename CppTypeTraits<field_type>::CppType>>::type> {
88
public:
89
    using CppType = typename CppTypeTraits<field_type>::CppType;
90
    using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType;
91
92
private:
93
    // Swap value's endian from/to big endian
94
2.03M
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
2.03M
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
2.03M
            return BigEndian::FromHost256(val);
97
2.03M
        } else {
98
2.03M
            switch (sizeof(UnsignedCppType)) {
99
466
            case 1:
100
466
                return val;
101
484
            case 2:
102
484
                return BigEndian::FromHost16(val);
103
1.91M
            case 4:
104
1.91M
                return BigEndian::FromHost32(val);
105
120k
            case 8:
106
120k
                return BigEndian::FromHost64(val);
107
414
            case 16:
108
414
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
2.03M
            }
113
2.03M
        }
114
2.03M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE15swap_big_endianEm
Line
Count
Source
94
432
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
432
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
432
            return BigEndian::FromHost256(val);
97
432
        } else {
98
432
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
432
            case 8:
106
432
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
432
            }
113
432
        }
114
432
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE15swap_big_endianEj
Line
Count
Source
94
1.91M
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
1.91M
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
1.91M
            return BigEndian::FromHost256(val);
97
1.91M
        } else {
98
1.91M
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
1.91M
            case 4:
104
1.91M
                return BigEndian::FromHost32(val);
105
0
            case 8:
106
0
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
1.91M
            }
113
1.91M
        }
114
1.91M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE15swap_big_endianEh
Line
Count
Source
94
466
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
466
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
466
            return BigEndian::FromHost256(val);
97
466
        } else {
98
466
            switch (sizeof(UnsignedCppType)) {
99
466
            case 1:
100
466
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
0
            case 8:
106
0
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
466
            }
113
466
        }
114
466
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE15swap_big_endianEt
Line
Count
Source
94
484
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
484
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
484
            return BigEndian::FromHost256(val);
97
484
        } else {
98
484
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
484
            case 2:
102
484
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
0
            case 8:
106
0
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
484
            }
113
484
        }
114
484
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE15swap_big_endianEj
Line
Count
Source
94
416
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
416
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
416
            return BigEndian::FromHost256(val);
97
416
        } else {
98
416
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
416
            case 4:
104
416
                return BigEndian::FromHost32(val);
105
0
            case 8:
106
0
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
416
            }
113
416
        }
114
416
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE15swap_big_endianEm
Line
Count
Source
94
119k
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
119k
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
119k
            return BigEndian::FromHost256(val);
97
119k
        } else {
98
119k
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
119k
            case 8:
106
119k
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
119k
            }
113
119k
        }
114
119k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE15swap_big_endianEo
Line
Count
Source
94
414
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
414
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
414
            return BigEndian::FromHost256(val);
97
414
        } else {
98
414
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
0
            case 8:
106
0
                return BigEndian::FromHost64(val);
107
414
            case 16:
108
414
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
414
            }
113
414
        }
114
414
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE15swap_big_endianEm
Line
Count
Source
94
420
    static UnsignedCppType swap_big_endian(UnsignedCppType val) {
95
420
        if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
96
420
            return BigEndian::FromHost256(val);
97
420
        } else {
98
420
            switch (sizeof(UnsignedCppType)) {
99
0
            case 1:
100
0
                return val;
101
0
            case 2:
102
0
                return BigEndian::FromHost16(val);
103
0
            case 4:
104
0
                return BigEndian::FromHost32(val);
105
420
            case 8:
106
420
                return BigEndian::FromHost64(val);
107
0
            case 16:
108
0
                return BigEndian::FromHost128(val);
109
0
            default:
110
0
                throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}",
111
0
                                                   int(field_type), sizeof(UnsignedCppType)));
112
420
            }
113
420
        }
114
420
    }
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE15swap_big_endianEb
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE15swap_big_endianEj
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE15swap_big_endianEm
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE15swap_big_endianEo
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE15swap_big_endianEN4wide7integerILm256EjEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE15swap_big_endianEj
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE15swap_big_endianEo
115
116
public:
117
2.00M
    static void full_encode_ascending(const void* value, std::string* buf) {
118
2.00M
        UnsignedCppType unsigned_val;
119
2.00M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
2.00M
        if (std::is_signed<CppType>::value) {
122
1.91M
            unsigned_val ^=
123
1.91M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
1.91M
        }
125
        // make it bigendian
126
2.00M
        unsigned_val = swap_big_endian(unsigned_val);
127
128
2.00M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
2.00M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
426
    static void full_encode_ascending(const void* value, std::string* buf) {
118
426
        UnsignedCppType unsigned_val;
119
426
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
426
        if (std::is_signed<CppType>::value) {
122
426
            unsigned_val ^=
123
426
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
426
        }
125
        // make it bigendian
126
426
        unsigned_val = swap_big_endian(unsigned_val);
127
128
426
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
426
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
1.91M
    static void full_encode_ascending(const void* value, std::string* buf) {
118
1.91M
        UnsignedCppType unsigned_val;
119
1.91M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
1.91M
        if (std::is_signed<CppType>::value) {
122
1.91M
            unsigned_val ^=
123
1.91M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
1.91M
        }
125
        // make it bigendian
126
1.91M
        unsigned_val = swap_big_endian(unsigned_val);
127
128
1.91M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
1.91M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
462
    static void full_encode_ascending(const void* value, std::string* buf) {
118
462
        UnsignedCppType unsigned_val;
119
462
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
462
        if (std::is_signed<CppType>::value) {
122
462
            unsigned_val ^=
123
462
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
462
        }
125
        // make it bigendian
126
462
        unsigned_val = swap_big_endian(unsigned_val);
127
128
462
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
462
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
480
    static void full_encode_ascending(const void* value, std::string* buf) {
118
480
        UnsignedCppType unsigned_val;
119
480
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
480
        if (std::is_signed<CppType>::value) {
122
480
            unsigned_val ^=
123
480
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
480
        }
125
        // make it bigendian
126
480
        unsigned_val = swap_big_endian(unsigned_val);
127
128
480
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
480
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
412
    static void full_encode_ascending(const void* value, std::string* buf) {
118
412
        UnsignedCppType unsigned_val;
119
412
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
412
        if (std::is_signed<CppType>::value) {
122
0
            unsigned_val ^=
123
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
        // make it bigendian
126
412
        unsigned_val = swap_big_endian(unsigned_val);
127
128
412
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
412
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
85.5k
    static void full_encode_ascending(const void* value, std::string* buf) {
118
85.5k
        UnsignedCppType unsigned_val;
119
85.5k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
85.5k
        if (std::is_signed<CppType>::value) {
122
0
            unsigned_val ^=
123
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
        // make it bigendian
126
85.5k
        unsigned_val = swap_big_endian(unsigned_val);
127
128
85.5k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
85.5k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
410
    static void full_encode_ascending(const void* value, std::string* buf) {
118
410
        UnsignedCppType unsigned_val;
119
410
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
410
        if (std::is_signed<CppType>::value) {
122
410
            unsigned_val ^=
123
410
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
410
        }
125
        // make it bigendian
126
410
        unsigned_val = swap_big_endian(unsigned_val);
127
128
410
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
410
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
416
    static void full_encode_ascending(const void* value, std::string* buf) {
118
416
        UnsignedCppType unsigned_val;
119
416
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
120
        // swap MSB to encode integer
121
416
        if (std::is_signed<CppType>::value) {
122
416
            unsigned_val ^=
123
416
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
416
        }
125
        // make it bigendian
126
416
        unsigned_val = swap_big_endian(unsigned_val);
127
128
416
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
129
416
    }
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
130
131
23.3k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
23.3k
        full_encode_ascending(value, buf);
133
23.3k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
418
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
418
        full_encode_ascending(value, buf);
133
418
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
424
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
424
        full_encode_ascending(value, buf);
133
424
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
20.4k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
20.4k
        full_encode_ascending(value, buf);
133
20.4k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
404
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
404
        full_encode_ascending(value, buf);
133
404
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
406
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
406
        full_encode_ascending(value, buf);
133
406
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
404
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
404
        full_encode_ascending(value, buf);
133
404
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
406
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
406
        full_encode_ascending(value, buf);
133
406
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
131
404
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
132
404
        full_encode_ascending(value, buf);
133
404
    }
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
134
135
34.2k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
34.2k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
34.2k
        UnsignedCppType unsigned_val;
143
34.2k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
34.2k
        unsigned_val = swap_big_endian(unsigned_val);
145
34.2k
        if (std::is_signed<CppType>::value) {
146
28
            unsigned_val ^=
147
28
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
28
        }
149
34.2k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
34.2k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
34.2k
        return Status::OK();
152
34.2k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
6
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
6
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
6
        UnsignedCppType unsigned_val;
143
6
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
6
        unsigned_val = swap_big_endian(unsigned_val);
145
6
        if (std::is_signed<CppType>::value) {
146
6
            unsigned_val ^=
147
6
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
6
        }
149
6
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
6
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
6
        return Status::OK();
152
6
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
6
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
6
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
6
        UnsignedCppType unsigned_val;
143
6
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
6
        unsigned_val = swap_big_endian(unsigned_val);
145
6
        if (std::is_signed<CppType>::value) {
146
6
            unsigned_val ^=
147
6
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
6
        }
149
6
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
6
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
6
        return Status::OK();
152
6
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
4
        UnsignedCppType unsigned_val;
143
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
4
        unsigned_val = swap_big_endian(unsigned_val);
145
4
        if (std::is_signed<CppType>::value) {
146
4
            unsigned_val ^=
147
4
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
4
        }
149
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
4
        return Status::OK();
152
4
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
4
        UnsignedCppType unsigned_val;
143
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
4
        unsigned_val = swap_big_endian(unsigned_val);
145
4
        if (std::is_signed<CppType>::value) {
146
4
            unsigned_val ^=
147
4
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
4
        }
149
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
4
        return Status::OK();
152
4
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
4
        UnsignedCppType unsigned_val;
143
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
4
        unsigned_val = swap_big_endian(unsigned_val);
145
4
        if (std::is_signed<CppType>::value) {
146
0
            unsigned_val ^=
147
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
0
        }
149
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
4
        return Status::OK();
152
4
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
34.2k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
34.2k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
34.2k
        UnsignedCppType unsigned_val;
143
34.2k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
34.2k
        unsigned_val = swap_big_endian(unsigned_val);
145
34.2k
        if (std::is_signed<CppType>::value) {
146
0
            unsigned_val ^=
147
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
0
        }
149
34.2k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
34.2k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
34.2k
        return Status::OK();
152
34.2k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
4
        UnsignedCppType unsigned_val;
143
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
4
        unsigned_val = swap_big_endian(unsigned_val);
145
4
        if (std::is_signed<CppType>::value) {
146
4
            unsigned_val ^=
147
4
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
4
        }
149
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
4
        return Status::OK();
152
4
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
135
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
136
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
137
        // currently, we reduce the usage of this method.
138
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
139
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
140
0
                                           sizeof(UnsignedCppType), encoded_key->size);
141
0
        }
142
4
        UnsignedCppType unsigned_val;
143
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
144
4
        unsigned_val = swap_big_endian(unsigned_val);
145
4
        if (std::is_signed<CppType>::value) {
146
4
            unsigned_val ^=
147
4
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
148
4
        }
149
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
150
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
151
4
        return Status::OK();
152
4
    }
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16decode_ascendingEPNS_5SliceEmPh
Unexecuted instantiation: _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16decode_ascendingEPNS_5SliceEmPh
153
};
154
155
template <>
156
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATE> {
157
public:
158
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::CppType;
159
    using UnsignedCppType =
160
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::UnsignedCppType;
161
162
public:
163
418
    static void full_encode_ascending(const void* value, std::string* buf) {
164
418
        UnsignedCppType unsigned_val;
165
418
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
166
        // make it bigendian
167
418
        unsigned_val = BigEndian::FromHost24(unsigned_val);
168
418
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
169
418
    }
170
171
406
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
172
406
        full_encode_ascending(value, buf);
173
406
    }
174
175
4
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
176
4
        if (encoded_key->size < sizeof(UnsignedCppType)) {
177
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
178
0
                                           sizeof(UnsignedCppType), encoded_key->size);
179
0
        }
180
4
        UnsignedCppType unsigned_val;
181
4
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
182
4
        unsigned_val = BigEndian::FromHost24(unsigned_val);
183
4
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
184
4
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
185
4
        return Status::OK();
186
4
    }
187
};
188
189
template <>
190
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATEV2> {
191
public:
192
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::CppType;
193
    using UnsignedCppType =
194
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::UnsignedCppType;
195
196
public:
197
4
    static void full_encode_ascending(const void* value, std::string* buf) {
198
4
        UnsignedCppType unsigned_val;
199
4
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
200
        // make it bigendian
201
4
        unsigned_val = BigEndian::FromHost32(unsigned_val);
202
4
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
203
4
    }
204
205
0
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
206
0
        full_encode_ascending(value, buf);
207
0
    }
208
209
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
210
0
        if (encoded_key->size < sizeof(UnsignedCppType)) {
211
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
212
0
                                                            sizeof(UnsignedCppType),
213
0
                                                            encoded_key->size));
214
0
        }
215
0
        UnsignedCppType unsigned_val;
216
0
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
217
0
        unsigned_val = BigEndian::FromHost32(unsigned_val);
218
0
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
219
0
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
220
0
        return Status::OK();
221
0
    }
222
};
223
224
template <>
225
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2> {
226
public:
227
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::CppType;
228
    using UnsignedCppType =
229
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::UnsignedCppType;
230
231
public:
232
0
    static void full_encode_ascending(const void* value, std::string* buf) {
233
0
        UnsignedCppType unsigned_val;
234
0
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
235
        // make it bigendian
236
0
        unsigned_val = BigEndian::FromHost64(unsigned_val);
237
0
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
238
0
    }
239
240
0
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
241
0
        full_encode_ascending(value, buf);
242
0
    }
243
244
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
245
0
        if (encoded_key->size < sizeof(UnsignedCppType)) {
246
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
247
0
                                                            sizeof(UnsignedCppType),
248
0
                                                            encoded_key->size));
249
0
        }
250
0
        UnsignedCppType unsigned_val;
251
0
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
252
0
        unsigned_val = BigEndian::FromHost64(unsigned_val);
253
0
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
254
0
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
255
0
        return Status::OK();
256
0
    }
257
};
258
259
template <>
260
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL> {
261
public:
262
12
    static void full_encode_ascending(const void* value, std::string* buf) {
263
12
        decimal12_t decimal_val;
264
12
        memcpy(&decimal_val, value, sizeof(decimal12_t));
265
12
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::full_encode_ascending(
266
12
                &decimal_val.integer, buf);
267
12
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::full_encode_ascending(&decimal_val.fraction,
268
12
                                                                              buf);
269
12
    } // namespace doris
270
271
8
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
272
8
        full_encode_ascending(value, buf);
273
8
    }
274
275
2
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
276
2
        decimal12_t decimal_val = {0, 0};
277
2
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::decode_ascending(
278
2
                encoded_key, sizeof(decimal_val.integer), (uint8_t*)&decimal_val.integer));
279
2
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::decode_ascending(
280
2
                encoded_key, sizeof(decimal_val.fraction), (uint8_t*)&decimal_val.fraction));
281
2
        memcpy(cell_ptr, &decimal_val, sizeof(decimal12_t));
282
2
        return Status::OK();
283
2
    }
284
};
285
286
template <>
287
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_CHAR> {
288
public:
289
4
    static void full_encode_ascending(const void* value, std::string* buf) {
290
4
        auto slice = reinterpret_cast<const Slice*>(value);
291
4
        buf->append(slice->get_data(), slice->get_size());
292
4
    }
293
294
4
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
295
4
        const Slice* slice = (const Slice*)value;
296
4
        CHECK(index_size <= slice->size)
297
0
                << "index size is larger than char size, index=" << index_size
298
0
                << ", char=" << slice->size;
299
4
        buf->append(slice->data, index_size);
300
4
    }
301
302
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
303
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
304
0
    }
305
};
306
307
template <>
308
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_VARCHAR> {
309
public:
310
422
    static void full_encode_ascending(const void* value, std::string* buf) {
311
422
        auto slice = reinterpret_cast<const Slice*>(value);
312
422
        buf->append(slice->get_data(), slice->get_size());
313
422
    }
314
315
4
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
316
4
        const Slice* slice = (const Slice*)value;
317
4
        size_t copy_size = std::min(index_size, slice->size);
318
4
        buf->append(slice->data, copy_size);
319
4
    }
320
321
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
322
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
323
0
    }
324
};
325
326
template <>
327
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_STRING> {
328
public:
329
1.76k
    static void full_encode_ascending(const void* value, std::string* buf) {
330
1.76k
        auto slice = reinterpret_cast<const Slice*>(value);
331
1.76k
        buf->append(slice->get_data(), slice->get_size());
332
1.76k
    }
333
334
0
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
335
0
        const Slice* slice = (const Slice*)value;
336
0
        size_t copy_size = std::min(index_size, slice->size);
337
0
        buf->append(slice->data, copy_size);
338
0
    }
339
340
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
341
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
342
0
    }
343
};
344
345
} // namespace doris