Coverage Report

Created: 2026-08-18 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/key_coder.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <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 "core/data_type/primitive_type.h"
33
#include "core/decimal12.h"
34
#include "core/extended_types.h"
35
#include "core/field.h"
36
#include "core/types.h"
37
#include "exec/common/endian.h"
38
#include "storage/olap_common.h"
39
#include "storage/types.h"
40
#include "util/slice.h"
41
42
namespace doris {
43
44
using FullEncodeAscendingFunc = void (*)(const void* value, std::string* buf);
45
using EncodeAscendingFunc = void (*)(const void* value, size_t index_size, std::string* buf);
46
using DecodeAscendingFunc = Status (*)(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr);
47
48
// Order-preserving binary encoding for values of a particular type so that
49
// those values can be compared by memcpy their encoded bytes.
50
//
51
// To obtain instance of this class, use the `get_key_coder(FieldType)` method.
52
class KeyCoder {
53
public:
54
    template <typename TraitsType>
55
    KeyCoder(TraitsType traits);
56
57
    // encode the provided `value` into `buf`.
58
54.9M
    void full_encode_ascending(const void* value, std::string* buf) const {
59
54.9M
        _full_encode_ascending(value, buf);
60
54.9M
    }
61
62
    // similar to `full_encode_ascending`, but only encode part (the first `index_size` bytes) of the value.
63
    // only applicable to string type
64
153k
    void encode_ascending(const void* value, size_t index_size, std::string* buf) const {
65
153k
        _encode_ascending(value, index_size, buf);
66
153k
    }
67
68
    // Only used for test, should delete it in the future
69
169k
    Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const {
70
169k
        return _decode_ascending(encoded_key, index_size, cell_ptr);
71
169k
    }
72
73
private:
74
    FullEncodeAscendingFunc _full_encode_ascending;
75
    EncodeAscendingFunc _encode_ascending;
76
    DecodeAscendingFunc _decode_ascending;
77
};
78
79
extern const KeyCoder* get_key_coder(FieldType type);
80
81
template <FieldType field_type, typename Enable = void>
82
class KeyCoderTraits {};
83
84
template <FieldType field_type>
85
class KeyCoderTraits<field_type,
86
                     typename std::enable_if<
87
                             IsIntegral<typename CppTypeTraits<field_type>::CppType>::value ||
88
                             IsDecimalNumber<typename CppTypeTraits<field_type>::CppType>>::type> {
89
public:
90
    using CppType = typename CppTypeTraits<field_type>::CppType;
91
    using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType;
92
93
41.2M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
41.2M
        UnsignedCppType unsigned_val;
95
41.2M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
41.2M
        if (IsSigned<CppType>::value) {
98
37.7M
            unsigned_val ^=
99
37.7M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
37.7M
        }
101
        // make it bigendian
102
41.2M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
41.2M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
41.2M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
11.4M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
11.4M
        UnsignedCppType unsigned_val;
95
11.4M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
11.4M
        if (IsSigned<CppType>::value) {
98
11.4M
            unsigned_val ^=
99
11.4M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
11.4M
        }
101
        // make it bigendian
102
11.4M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
11.4M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
11.4M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
22.3M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
22.3M
        UnsignedCppType unsigned_val;
95
22.3M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
22.3M
        if (IsSigned<CppType>::value) {
98
22.3M
            unsigned_val ^=
99
22.3M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
22.3M
        }
101
        // make it bigendian
102
22.3M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
22.3M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
22.3M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
760k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
760k
        UnsignedCppType unsigned_val;
95
760k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
760k
        if (IsSigned<CppType>::value) {
98
760k
            unsigned_val ^=
99
760k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
760k
        }
101
        // make it bigendian
102
760k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
760k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
760k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
697k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
697k
        UnsignedCppType unsigned_val;
95
697k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
697k
        if (IsSigned<CppType>::value) {
98
697k
            unsigned_val ^=
99
697k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
697k
        }
101
        // make it bigendian
102
697k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
697k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
697k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.27M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.27M
        UnsignedCppType unsigned_val;
95
1.27M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.27M
        if (IsSigned<CppType>::value) {
98
0
            unsigned_val ^=
99
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
0
        }
101
        // make it bigendian
102
1.27M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.27M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.27M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.63M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.63M
        UnsignedCppType unsigned_val;
95
1.63M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.63M
        if (IsSigned<CppType>::value) {
98
0
            unsigned_val ^=
99
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
0
        }
101
        // make it bigendian
102
1.63M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.63M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.63M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
510k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
510k
        UnsignedCppType unsigned_val;
95
510k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
510k
        if (IsSigned<CppType>::value) {
98
510k
            unsigned_val ^=
99
510k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
510k
        }
101
        // make it bigendian
102
510k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
510k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
510k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
448k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
448k
        UnsignedCppType unsigned_val;
95
448k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
448k
        if (IsSigned<CppType>::value) {
98
448k
            unsigned_val ^=
99
448k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
448k
        }
101
        // make it bigendian
102
448k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
448k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
448k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
500k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
500k
        UnsignedCppType unsigned_val;
95
500k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
500k
        if (IsSigned<CppType>::value) {
98
0
            unsigned_val ^=
99
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
0
        }
101
        // make it bigendian
102
500k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
500k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
500k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
58.7k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
58.7k
        UnsignedCppType unsigned_val;
95
58.7k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
58.7k
        if (IsSigned<CppType>::value) {
98
58.7k
            unsigned_val ^=
99
58.7k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
58.7k
        }
101
        // make it bigendian
102
58.7k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
58.7k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
58.7k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
54.7k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
54.7k
        UnsignedCppType unsigned_val;
95
54.7k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
54.7k
        if (IsSigned<CppType>::value) {
98
54.7k
            unsigned_val ^=
99
54.7k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
54.7k
        }
101
        // make it bigendian
102
54.7k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
54.7k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
54.7k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.47M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.47M
        UnsignedCppType unsigned_val;
95
1.47M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.47M
        if (IsSigned<CppType>::value) {
98
1.47M
            unsigned_val ^=
99
1.47M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
1.47M
        }
101
        // make it bigendian
102
1.47M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.47M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.47M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
50.6k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
50.6k
        UnsignedCppType unsigned_val;
95
50.6k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
50.6k
        if (IsSigned<CppType>::value) {
98
50.6k
            unsigned_val ^=
99
50.6k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
50.6k
        }
101
        // make it bigendian
102
50.6k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
50.6k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
50.6k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
50.2k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
50.2k
        UnsignedCppType unsigned_val;
95
50.2k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
50.2k
        if (IsSigned<CppType>::value) {
98
0
            unsigned_val ^=
99
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
0
        }
101
        // make it bigendian
102
50.2k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
50.2k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
50.2k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
51.4k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
51.4k
        UnsignedCppType unsigned_val;
95
51.4k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
51.4k
        if (IsSigned<CppType>::value) {
98
0
            unsigned_val ^=
99
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
0
        }
101
        // make it bigendian
102
51.4k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
51.4k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
51.4k
    }
106
107
122k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
122k
        full_encode_ascending(value, buf);
109
122k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.55k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.55k
        full_encode_ascending(value, buf);
109
2.55k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.70k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.70k
        full_encode_ascending(value, buf);
109
2.70k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
87.0k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
87.0k
        full_encode_ascending(value, buf);
109
87.0k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
202
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
202
        full_encode_ascending(value, buf);
109
202
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
16.7k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
16.7k
        full_encode_ascending(value, buf);
109
16.7k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
202
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
202
        full_encode_ascending(value, buf);
109
202
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
7.19k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
7.19k
        full_encode_ascending(value, buf);
109
7.19k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
251
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
251
        full_encode_ascending(value, buf);
109
251
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
950
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
950
        full_encode_ascending(value, buf);
109
950
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
520
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
520
        full_encode_ascending(value, buf);
109
520
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
630
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
630
        full_encode_ascending(value, buf);
109
630
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.14k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.14k
        full_encode_ascending(value, buf);
109
2.14k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
497
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
497
        full_encode_ascending(value, buf);
109
497
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
452
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
452
        full_encode_ascending(value, buf);
109
452
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
449
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
449
        full_encode_ascending(value, buf);
109
449
    }
110
111
490k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
490k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
490k
        UnsignedCppType unsigned_val;
119
490k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
490k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
490k
        if (IsSigned<CppType>::value) {
122
16.3k
            unsigned_val ^=
123
16.3k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
16.3k
        }
125
490k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
490k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
490k
        return Status::OK();
128
490k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
15.7k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
15.7k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
15.7k
        UnsignedCppType unsigned_val;
119
15.7k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
15.7k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
15.7k
        if (IsSigned<CppType>::value) {
122
15.7k
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
15.7k
        }
125
15.7k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
15.7k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
15.7k
        return Status::OK();
128
15.7k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
117
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
117
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
117
        UnsignedCppType unsigned_val;
119
117
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
117
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
117
        if (IsSigned<CppType>::value) {
122
117
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
117
        }
125
117
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
117
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
117
        return Status::OK();
128
117
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
53
        UnsignedCppType unsigned_val;
119
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
53
        if (IsSigned<CppType>::value) {
122
53
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
53
        }
125
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
53
        return Status::OK();
128
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
53
        UnsignedCppType unsigned_val;
119
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
53
        if (IsSigned<CppType>::value) {
122
53
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
53
        }
125
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
53
        return Status::OK();
128
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
152k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
152k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
152k
        UnsignedCppType unsigned_val;
119
152k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
152k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
152k
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
152k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
152k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
152k
        return Status::OK();
128
152k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
321k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
321k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
321k
        UnsignedCppType unsigned_val;
119
321k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
321k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
321k
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
321k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
321k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
321k
        return Status::OK();
128
321k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
53
        UnsignedCppType unsigned_val;
119
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
53
        if (IsSigned<CppType>::value) {
122
53
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
53
        }
125
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
53
        return Status::OK();
128
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
53
        UnsignedCppType unsigned_val;
119
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
53
        if (IsSigned<CppType>::value) {
122
53
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
53
        }
125
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
53
        return Status::OK();
128
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
51
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
51
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
51
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
51
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
51
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
51
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
51
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
51
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
112
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
113
        // currently, we reduce the usage of this method.
114
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
115
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
116
0
                                           sizeof(UnsignedCppType), encoded_key->size);
117
0
        }
118
51
        UnsignedCppType unsigned_val;
119
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
51
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
51
        return Status::OK();
128
51
    }
129
};
130
131
template <>
132
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATE> {
133
public:
134
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::CppType;
135
    using UnsignedCppType =
136
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::UnsignedCppType;
137
138
public:
139
451k
    static void full_encode_ascending(const void* value, std::string* buf) {
140
451k
        UnsignedCppType unsigned_val;
141
451k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
142
        // make it bigendian
143
451k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
144
451k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
145
451k
    }
146
147
353
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
148
353
        full_encode_ascending(value, buf);
149
353
    }
150
151
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
152
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
153
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
154
0
                                           sizeof(UnsignedCppType), encoded_key->size);
155
0
        }
156
53
        UnsignedCppType unsigned_val;
157
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
158
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
159
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
160
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
161
53
        return Status::OK();
162
53
    }
163
};
164
165
template <>
166
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATEV2> {
167
public:
168
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::CppType;
169
    using UnsignedCppType =
170
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::UnsignedCppType;
171
172
public:
173
806k
    static void full_encode_ascending(const void* value, std::string* buf) {
174
806k
        UnsignedCppType unsigned_val;
175
806k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
176
        // make it bigendian
177
806k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
178
806k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
179
806k
    }
180
181
6.30k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
182
6.30k
        full_encode_ascending(value, buf);
183
6.30k
    }
184
185
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
186
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
187
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
188
0
                                                            sizeof(UnsignedCppType),
189
0
                                                            encoded_key->size));
190
0
        }
191
51
        UnsignedCppType unsigned_val;
192
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
193
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
194
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
195
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
196
51
        return Status::OK();
197
51
    }
198
};
199
200
template <>
201
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2> {
202
public:
203
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::CppType;
204
    using UnsignedCppType =
205
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::UnsignedCppType;
206
207
public:
208
1.13M
    static void full_encode_ascending(const void* value, std::string* buf) {
209
1.13M
        UnsignedCppType unsigned_val;
210
1.13M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
211
        // make it bigendian
212
1.13M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
213
1.13M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
214
1.13M
    }
215
216
2.62k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
217
2.62k
        full_encode_ascending(value, buf);
218
2.62k
    }
219
220
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
221
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
222
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
223
0
                                                            sizeof(UnsignedCppType),
224
0
                                                            encoded_key->size));
225
0
        }
226
51
        UnsignedCppType unsigned_val;
227
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
228
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
229
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
230
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
231
51
        return Status::OK();
232
51
    }
233
};
234
235
template <>
236
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ> {
237
public:
238
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ>::CppType;
239
    using UnsignedCppType =
240
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ>::UnsignedCppType;
241
242
public:
243
63.8k
    static void full_encode_ascending(const void* value, std::string* buf) {
244
63.8k
        UnsignedCppType unsigned_val;
245
63.8k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
246
        // make it bigendian
247
63.8k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
248
63.8k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
249
63.8k
    }
250
251
1.76k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
252
1.76k
        full_encode_ascending(value, buf);
253
1.76k
    }
254
255
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
256
0
        if (encoded_key->size < sizeof(UnsignedCppType)) {
257
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
258
0
                                                            sizeof(UnsignedCppType),
259
0
                                                            encoded_key->size));
260
0
        }
261
0
        UnsignedCppType unsigned_val;
262
0
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
263
0
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
264
0
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
265
0
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
266
0
        return Status::OK();
267
0
    }
268
};
269
270
template <>
271
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL> {
272
public:
273
48.8k
    static void full_encode_ascending(const void* value, std::string* buf) {
274
48.8k
        decimal12_t decimal_val;
275
48.8k
        memcpy(&decimal_val, value, sizeof(decimal12_t));
276
48.8k
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::full_encode_ascending(
277
48.8k
                &decimal_val.integer, buf);
278
48.8k
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::full_encode_ascending(&decimal_val.fraction,
279
48.8k
                                                                              buf);
280
48.8k
    } // namespace doris
281
282
72
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
283
72
        full_encode_ascending(value, buf);
284
72
    }
285
286
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
287
64
        decimal12_t decimal_val = {0, 0};
288
64
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::decode_ascending(
289
64
                encoded_key, sizeof(decimal_val.integer), (uint8_t*)&decimal_val.integer));
290
64
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::decode_ascending(
291
64
                encoded_key, sizeof(decimal_val.fraction), (uint8_t*)&decimal_val.fraction));
292
64
        memcpy(cell_ptr, &decimal_val, sizeof(decimal12_t));
293
64
        return Status::OK();
294
64
    }
295
};
296
297
template <>
298
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_CHAR> {
299
public:
300
3.40k
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
301
3.40k
        auto slice = reinterpret_cast<const Slice*>(value);
302
3.40k
        buf->append(slice->get_data(), slice->get_size());
303
3.40k
    }
304
305
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
306
1.62k
                                                       std::string* buf) {
307
1.62k
        const Slice* slice = (const Slice*)value;
308
1.62k
        CHECK(index_size <= slice->size)
309
0
                << "index size is larger than char size, index=" << index_size
310
0
                << ", char=" << slice->size;
311
1.62k
        buf->append(slice->data, index_size);
312
1.62k
    }
313
314
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
315
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
316
0
    }
317
};
318
319
template <>
320
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_VARCHAR> {
321
public:
322
13.1M
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
323
13.1M
        auto slice = reinterpret_cast<const Slice*>(value);
324
13.1M
        buf->append(slice->get_data(), slice->get_size());
325
13.1M
    }
326
327
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
328
18.5k
                                                       std::string* buf) {
329
18.5k
        const Slice* slice = (const Slice*)value;
330
18.5k
        size_t copy_size = std::min(index_size, slice->size);
331
18.5k
        buf->append(slice->data, copy_size);
332
18.5k
    }
333
334
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
335
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
336
0
    }
337
};
338
339
template <>
340
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_STRING> {
341
public:
342
889
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
343
889
        auto slice = reinterpret_cast<const Slice*>(value);
344
889
        buf->append(slice->get_data(), slice->get_size());
345
889
    }
346
347
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
348
49
                                                       std::string* buf) {
349
49
        const Slice* slice = (const Slice*)value;
350
49
        size_t copy_size = std::min(index_size, slice->size);
351
49
        buf->append(slice->data, copy_size);
352
49
    }
353
354
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
355
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
356
0
    }
357
};
358
359
template <FieldType field_type>
360
class KeyCoderTraitsForFloat {
361
public:
362
    using CppType = typename CppTypeTraits<field_type>::CppType;
363
    using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType;
364
365
97.0k
    static UnsignedCppType encode_float(CppType value) {
366
97.0k
        return sortable_float_bits(float_to_int_bits(value));
367
97.0k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE12encode_floatEf
Line
Count
Source
365
48.5k
    static UnsignedCppType encode_float(CppType value) {
366
48.5k
        return sortable_float_bits(float_to_int_bits(value));
367
48.5k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE12encode_floatEd
Line
Count
Source
365
48.5k
    static UnsignedCppType encode_float(CppType value) {
366
48.5k
        return sortable_float_bits(float_to_int_bits(value));
367
48.5k
    }
368
369
128
    static CppType decode_float(UnsignedCppType sortable_bits) {
370
128
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
371
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE12decode_floatEj
Line
Count
Source
369
64
    static CppType decode_float(UnsignedCppType sortable_bits) {
370
64
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
371
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE12decode_floatEm
Line
Count
Source
369
64
    static CppType decode_float(UnsignedCppType sortable_bits) {
370
64
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
371
64
    }
372
373
    // -infinity < -100.0 < -1.0 < -0.0 < 0.0 < 1.0 < 100.0 < infinity < NaN
374
97.0k
    static void full_encode_ascending(const void* value, std::string* buf) {
375
97.0k
        CppType val;
376
97.0k
        std::memcpy(&val, value, sizeof(CppType));
377
97.0k
        UnsignedCppType sortable_val = encode_float(val);
378
97.0k
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
97.0k
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
97.0k
        sortable_val ^= sign_bit;
381
97.0k
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
97.0k
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
97.0k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
374
48.5k
    static void full_encode_ascending(const void* value, std::string* buf) {
375
48.5k
        CppType val;
376
48.5k
        std::memcpy(&val, value, sizeof(CppType));
377
48.5k
        UnsignedCppType sortable_val = encode_float(val);
378
48.5k
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
48.5k
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
48.5k
        sortable_val ^= sign_bit;
381
48.5k
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
48.5k
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
48.5k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
374
48.5k
    static void full_encode_ascending(const void* value, std::string* buf) {
375
48.5k
        CppType val;
376
48.5k
        std::memcpy(&val, value, sizeof(CppType));
377
48.5k
        UnsignedCppType sortable_val = encode_float(val);
378
48.5k
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
48.5k
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
48.5k
        sortable_val ^= sign_bit;
381
48.5k
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
48.5k
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
48.5k
    }
384
385
0
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
386
0
        full_encode_ascending(value, buf);
387
0
    }
Unexecuted instantiation: _ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
388
389
128
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
390
128
        if (encoded_key->size < sizeof(UnsignedCppType)) {
391
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
392
0
                                                            sizeof(UnsignedCppType),
393
0
                                                            encoded_key->size));
394
0
        }
395
128
        UnsignedCppType sortable_val;
396
128
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
397
128
        sortable_val = to_endian<std::endian::big>(sortable_val);
398
128
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
399
128
                                             << (sizeof(UnsignedCppType) * 8 - 1);
400
128
        sortable_val ^= sign_bit;
401
128
        CppType val = decode_float(sortable_val);
402
128
        std::memcpy(cell_ptr, &val, sizeof(CppType));
403
128
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
404
128
        return Status::OK();
405
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
389
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
390
64
        if (encoded_key->size < sizeof(UnsignedCppType)) {
391
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
392
0
                                                            sizeof(UnsignedCppType),
393
0
                                                            encoded_key->size));
394
0
        }
395
64
        UnsignedCppType sortable_val;
396
64
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
397
64
        sortable_val = to_endian<std::endian::big>(sortable_val);
398
64
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
399
64
                                             << (sizeof(UnsignedCppType) * 8 - 1);
400
64
        sortable_val ^= sign_bit;
401
64
        CppType val = decode_float(sortable_val);
402
64
        std::memcpy(cell_ptr, &val, sizeof(CppType));
403
64
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
404
64
        return Status::OK();
405
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
389
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
390
64
        if (encoded_key->size < sizeof(UnsignedCppType)) {
391
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
392
0
                                                            sizeof(UnsignedCppType),
393
0
                                                            encoded_key->size));
394
0
        }
395
64
        UnsignedCppType sortable_val;
396
64
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
397
64
        sortable_val = to_endian<std::endian::big>(sortable_val);
398
64
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
399
64
                                             << (sizeof(UnsignedCppType) * 8 - 1);
400
64
        sortable_val ^= sign_bit;
401
64
        CppType val = decode_float(sortable_val);
402
64
        std::memcpy(cell_ptr, &val, sizeof(CppType));
403
64
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
404
64
        return Status::OK();
405
64
    }
406
407
private:
408
97.0k
    static UnsignedCppType float_to_int_bits(CppType value) {
409
97.0k
        if (std::isnan(value)) {
410
49
            if constexpr (std::is_same_v<CppType, float>) {
411
24
                return 0x7FC00000U;
412
25
            } else {
413
25
                return 0x7FF8000000000000ULL;
414
25
            }
415
49
        }
416
417
0
        UnsignedCppType result;
418
97.0k
        std::memcpy(&result, &value, sizeof(CppType));
419
97.0k
        return result;
420
97.0k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE17float_to_int_bitsEf
Line
Count
Source
408
48.5k
    static UnsignedCppType float_to_int_bits(CppType value) {
409
48.5k
        if (std::isnan(value)) {
410
24
            if constexpr (std::is_same_v<CppType, float>) {
411
24
                return 0x7FC00000U;
412
            } else {
413
                return 0x7FF8000000000000ULL;
414
            }
415
24
        }
416
417
0
        UnsignedCppType result;
418
48.5k
        std::memcpy(&result, &value, sizeof(CppType));
419
48.5k
        return result;
420
48.5k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE17float_to_int_bitsEd
Line
Count
Source
408
48.5k
    static UnsignedCppType float_to_int_bits(CppType value) {
409
48.5k
        if (std::isnan(value)) {
410
            if constexpr (std::is_same_v<CppType, float>) {
411
                return 0x7FC00000U;
412
25
            } else {
413
25
                return 0x7FF8000000000000ULL;
414
25
            }
415
25
        }
416
417
0
        UnsignedCppType result;
418
48.5k
        std::memcpy(&result, &value, sizeof(CppType));
419
48.5k
        return result;
420
48.5k
    }
421
422
97.2k
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
97.2k
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
97.2k
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
97.2k
        if ((bits & sign_bit) != 0) {
426
6.03k
            return bits ^ (sign_bit - 1);
427
91.1k
        } else {
428
91.1k
            return bits;
429
91.1k
        }
430
97.2k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE19sortable_float_bitsEj
Line
Count
Source
422
48.5k
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
48.5k
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
48.5k
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
48.5k
        if ((bits & sign_bit) != 0) {
426
2.98k
            return bits ^ (sign_bit - 1);
427
45.5k
        } else {
428
45.5k
            return bits;
429
45.5k
        }
430
48.5k
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE19sortable_float_bitsEm
Line
Count
Source
422
48.6k
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
48.6k
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
48.6k
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
48.6k
        if ((bits & sign_bit) != 0) {
426
3.04k
            return bits ^ (sign_bit - 1);
427
45.5k
        } else {
428
45.5k
            return bits;
429
45.5k
        }
430
48.6k
    }
431
432
128
    static CppType int_bits_to_float(UnsignedCppType bits) {
433
128
        CppType result;
434
128
        std::memcpy(&result, &bits, sizeof(CppType));
435
128
        return result;
436
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE17int_bits_to_floatEj
Line
Count
Source
432
64
    static CppType int_bits_to_float(UnsignedCppType bits) {
433
64
        CppType result;
434
64
        std::memcpy(&result, &bits, sizeof(CppType));
435
64
        return result;
436
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE17int_bits_to_floatEm
Line
Count
Source
432
64
    static CppType int_bits_to_float(UnsignedCppType bits) {
433
64
        CppType result;
434
64
        std::memcpy(&result, &bits, sizeof(CppType));
435
64
        return result;
436
64
    }
437
438
128
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
439
128
        return sortable_float_bits(sortable_bits);
440
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE21unsortable_float_bitsEj
Line
Count
Source
438
64
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
439
64
        return sortable_float_bits(sortable_bits);
440
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE21unsortable_float_bitsEm
Line
Count
Source
438
64
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
439
64
        return sortable_float_bits(sortable_bits);
440
64
    }
441
};
442
443
template <>
444
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_FLOAT>
445
        : public KeyCoderTraitsForFloat<FieldType::OLAP_FIELD_TYPE_FLOAT> {};
446
447
template <>
448
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DOUBLE>
449
        : public KeyCoderTraitsForFloat<FieldType::OLAP_FIELD_TYPE_DOUBLE> {};
450
451
// X-macro listing every (FieldType, PrimitiveType) pair that goes through KeyCoder
452
// as a non-string scalar key. Strings are handled separately because they need
453
// length / padding logic outside KeyCoder. Each entry: M(FT_suffix, PT_suffix).
454
#define DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(M) \
455
11.7k
    M(OLAP_FIELD_TYPE_BOOL, TYPE_BOOLEAN)                 \
456
153k
    M(OLAP_FIELD_TYPE_TINYINT, TYPE_TINYINT)              \
457
153k
    M(OLAP_FIELD_TYPE_SMALLINT, TYPE_SMALLINT)            \
458
763k
    M(OLAP_FIELD_TYPE_INT, TYPE_INT)                      \
459
763k
    M(OLAP_FIELD_TYPE_BIGINT, TYPE_BIGINT)                \
460
36.1k
    M(OLAP_FIELD_TYPE_LARGEINT, TYPE_LARGEINT)            \
461
14.2k
    M(OLAP_FIELD_TYPE_FLOAT, TYPE_FLOAT)                  \
462
23
    M(OLAP_FIELD_TYPE_DOUBLE, TYPE_DOUBLE)                \
463
55
    M(OLAP_FIELD_TYPE_DECIMAL, TYPE_DECIMALV2)            \
464
441
    M(OLAP_FIELD_TYPE_DECIMAL32, TYPE_DECIMAL32)          \
465
441
    M(OLAP_FIELD_TYPE_DECIMAL64, TYPE_DECIMAL64)          \
466
1.12k
    M(OLAP_FIELD_TYPE_DECIMAL128I, TYPE_DECIMAL128I)      \
467
1.12k
    M(OLAP_FIELD_TYPE_DECIMAL256, TYPE_DECIMAL256)        \
468
3.05k
    M(OLAP_FIELD_TYPE_DATE, TYPE_DATE)                    \
469
3.05k
    M(OLAP_FIELD_TYPE_DATETIME, TYPE_DATETIME)            \
470
254k
    M(OLAP_FIELD_TYPE_DATEV2, TYPE_DATEV2)                \
471
254k
    M(OLAP_FIELD_TYPE_DATETIMEV2, TYPE_DATETIMEV2)        \
472
8.27k
    M(OLAP_FIELD_TYPE_TIMESTAMPTZ, TYPE_TIMESTAMPTZ)      \
473
8.27k
    M(OLAP_FIELD_TYPE_IPV4, TYPE_IPV4)                    \
474
193
    M(OLAP_FIELD_TYPE_IPV6, TYPE_IPV6)
475
476
// True for exactly the PrimitiveTypes listed in
477
// DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES. Strings (CHAR/VARCHAR/STRING/
478
// VARBINARY) have their own short-key code path in row_cursor.cpp that calls
479
// storage_field->full_encode_ascending directly, and nested/aggregate types
480
// (ARRAY/MAP/STRUCT/VARIANT/HLL/BITMAP/JSONB/QUANTILE_STATE/AGG_STATE) are not
481
// key-encodable at all -- both groups must never reach the helpers below.
482
0
constexpr bool is_key_encodable_non_string_type(PrimitiveType pt) {
483
0
    switch (pt) {
484
0
#define DORIS_KEY_ENCODABLE_CASE(FT, PT) \
485
0
    case PrimitiveType::PT:              \
486
0
        return true;
487
0
        DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(DORIS_KEY_ENCODABLE_CASE)
488
0
#undef DORIS_KEY_ENCODABLE_CASE
489
0
    default:
490
0
        return false;
491
0
    }
492
0
}
493
494
// Convert a Field value to its storage representation (via PrimitiveTypeConvertor)
495
// and full-encode it as a byte-comparable ascending key via KeyCoder.
496
template <PrimitiveType PT>
497
1.25M
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
1.25M
    static_assert(is_key_encodable_non_string_type(PT),
499
1.25M
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
1.25M
                  "strings have their own path in RowCursor that calls "
501
1.25M
                  "storage_field->full_encode_ascending directly, and nested / "
502
1.25M
                  "aggregate types are not key-encodable");
503
1.25M
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
1.25M
    coder->full_encode_ascending(&v, buf);
505
1.25M
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE2EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
11.7k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
11.7k
    static_assert(is_key_encodable_non_string_type(PT),
499
11.7k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
11.7k
                  "strings have their own path in RowCursor that calls "
501
11.7k
                  "storage_field->full_encode_ascending directly, and nested / "
502
11.7k
                  "aggregate types are not key-encodable");
503
11.7k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
11.7k
    coder->full_encode_ascending(&v, buf);
505
11.7k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE3EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
153k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
153k
    static_assert(is_key_encodable_non_string_type(PT),
499
153k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
153k
                  "strings have their own path in RowCursor that calls "
501
153k
                  "storage_field->full_encode_ascending directly, and nested / "
502
153k
                  "aggregate types are not key-encodable");
503
153k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
153k
    coder->full_encode_ascending(&v, buf);
505
153k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE4EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
5.49k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
5.49k
    static_assert(is_key_encodable_non_string_type(PT),
499
5.49k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
5.49k
                  "strings have their own path in RowCursor that calls "
501
5.49k
                  "storage_field->full_encode_ascending directly, and nested / "
502
5.49k
                  "aggregate types are not key-encodable");
503
5.49k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
5.49k
    coder->full_encode_ascending(&v, buf);
505
5.49k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE5EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
762k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
762k
    static_assert(is_key_encodable_non_string_type(PT),
499
762k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
762k
                  "strings have their own path in RowCursor that calls "
501
762k
                  "storage_field->full_encode_ascending directly, and nested / "
502
762k
                  "aggregate types are not key-encodable");
503
762k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
762k
    coder->full_encode_ascending(&v, buf);
505
762k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE6EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
36.0k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
36.0k
    static_assert(is_key_encodable_non_string_type(PT),
499
36.0k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
36.0k
                  "strings have their own path in RowCursor that calls "
501
36.0k
                  "storage_field->full_encode_ascending directly, and nested / "
502
36.0k
                  "aggregate types are not key-encodable");
503
36.0k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
36.0k
    coder->full_encode_ascending(&v, buf);
505
36.0k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE7EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
14.1k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
14.1k
    static_assert(is_key_encodable_non_string_type(PT),
499
14.1k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
14.1k
                  "strings have their own path in RowCursor that calls "
501
14.1k
                  "storage_field->full_encode_ascending directly, and nested / "
502
14.1k
                  "aggregate types are not key-encodable");
503
14.1k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
14.1k
    coder->full_encode_ascending(&v, buf);
505
14.1k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE8EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
28
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
28
    static_assert(is_key_encodable_non_string_type(PT),
499
28
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
28
                  "strings have their own path in RowCursor that calls "
501
28
                  "storage_field->full_encode_ascending directly, and nested / "
502
28
                  "aggregate types are not key-encodable");
503
28
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
28
    coder->full_encode_ascending(&v, buf);
505
28
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE9EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
26
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
26
    static_assert(is_key_encodable_non_string_type(PT),
499
26
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
26
                  "strings have their own path in RowCursor that calls "
501
26
                  "storage_field->full_encode_ascending directly, and nested / "
502
26
                  "aggregate types are not key-encodable");
503
26
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
26
    coder->full_encode_ascending(&v, buf);
505
26
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE20EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
58
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
58
    static_assert(is_key_encodable_non_string_type(PT),
499
58
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
58
                  "strings have their own path in RowCursor that calls "
501
58
                  "storage_field->full_encode_ascending directly, and nested / "
502
58
                  "aggregate types are not key-encodable");
503
58
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
58
    coder->full_encode_ascending(&v, buf);
505
58
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE28EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
456
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
456
    static_assert(is_key_encodable_non_string_type(PT),
499
456
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
456
                  "strings have their own path in RowCursor that calls "
501
456
                  "storage_field->full_encode_ascending directly, and nested / "
502
456
                  "aggregate types are not key-encodable");
503
456
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
456
    coder->full_encode_ascending(&v, buf);
505
456
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE29EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
392
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
392
    static_assert(is_key_encodable_non_string_type(PT),
499
392
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
392
                  "strings have their own path in RowCursor that calls "
501
392
                  "storage_field->full_encode_ascending directly, and nested / "
502
392
                  "aggregate types are not key-encodable");
503
392
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
392
    coder->full_encode_ascending(&v, buf);
505
392
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE30EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
1.13k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
1.13k
    static_assert(is_key_encodable_non_string_type(PT),
499
1.13k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
1.13k
                  "strings have their own path in RowCursor that calls "
501
1.13k
                  "storage_field->full_encode_ascending directly, and nested / "
502
1.13k
                  "aggregate types are not key-encodable");
503
1.13k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
1.13k
    coder->full_encode_ascending(&v, buf);
505
1.13k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE35EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
775
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
775
    static_assert(is_key_encodable_non_string_type(PT),
499
775
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
775
                  "strings have their own path in RowCursor that calls "
501
775
                  "storage_field->full_encode_ascending directly, and nested / "
502
775
                  "aggregate types are not key-encodable");
503
775
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
775
    coder->full_encode_ascending(&v, buf);
505
775
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE11EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
3.04k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
3.04k
    static_assert(is_key_encodable_non_string_type(PT),
499
3.04k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
3.04k
                  "strings have their own path in RowCursor that calls "
501
3.04k
                  "storage_field->full_encode_ascending directly, and nested / "
502
3.04k
                  "aggregate types are not key-encodable");
503
3.04k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
3.04k
    coder->full_encode_ascending(&v, buf);
505
3.04k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE12EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
374
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
374
    static_assert(is_key_encodable_non_string_type(PT),
499
374
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
374
                  "strings have their own path in RowCursor that calls "
501
374
                  "storage_field->full_encode_ascending directly, and nested / "
502
374
                  "aggregate types are not key-encodable");
503
374
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
374
    coder->full_encode_ascending(&v, buf);
505
374
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE25EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
254k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
254k
    static_assert(is_key_encodable_non_string_type(PT),
499
254k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
254k
                  "strings have their own path in RowCursor that calls "
501
254k
                  "storage_field->full_encode_ascending directly, and nested / "
502
254k
                  "aggregate types are not key-encodable");
503
254k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
254k
    coder->full_encode_ascending(&v, buf);
505
254k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE26EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
6.46k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
6.46k
    static_assert(is_key_encodable_non_string_type(PT),
499
6.46k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
6.46k
                  "strings have their own path in RowCursor that calls "
501
6.46k
                  "storage_field->full_encode_ascending directly, and nested / "
502
6.46k
                  "aggregate types are not key-encodable");
503
6.46k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
6.46k
    coder->full_encode_ascending(&v, buf);
505
6.46k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE42EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
8.25k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
8.25k
    static_assert(is_key_encodable_non_string_type(PT),
499
8.25k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
8.25k
                  "strings have their own path in RowCursor that calls "
501
8.25k
                  "storage_field->full_encode_ascending directly, and nested / "
502
8.25k
                  "aggregate types are not key-encodable");
503
8.25k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
8.25k
    coder->full_encode_ascending(&v, buf);
505
8.25k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE36EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
185
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
185
    static_assert(is_key_encodable_non_string_type(PT),
499
185
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
185
                  "strings have their own path in RowCursor that calls "
501
185
                  "storage_field->full_encode_ascending directly, and nested / "
502
185
                  "aggregate types are not key-encodable");
503
185
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
185
    coder->full_encode_ascending(&v, buf);
505
185
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE37EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
164
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
164
    static_assert(is_key_encodable_non_string_type(PT),
499
164
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
164
                  "strings have their own path in RowCursor that calls "
501
164
                  "storage_field->full_encode_ascending directly, and nested / "
502
164
                  "aggregate types are not key-encodable");
503
164
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
164
    coder->full_encode_ascending(&v, buf);
505
164
}
506
507
} // namespace doris