Coverage Report

Created: 2026-07-04 09:32

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
55.2M
    void full_encode_ascending(const void* value, std::string* buf) const {
59
55.2M
        _full_encode_ascending(value, buf);
60
55.2M
    }
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
141k
    void encode_ascending(const void* value, size_t index_size, std::string* buf) const {
65
141k
        _encode_ascending(value, index_size, buf);
66
141k
    }
67
68
    // Only used for test, should delete it in the future
69
248k
    Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const {
70
248k
        return _decode_ascending(encoded_key, index_size, cell_ptr);
71
248k
    }
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
40.4M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
40.4M
        UnsignedCppType unsigned_val;
95
40.4M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
40.4M
        if (IsSigned<CppType>::value) {
98
37.0M
            unsigned_val ^=
99
37.0M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
37.0M
        }
101
        // make it bigendian
102
40.4M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
40.4M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
40.4M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
11.5M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
11.5M
        UnsignedCppType unsigned_val;
95
11.5M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
11.5M
        if (IsSigned<CppType>::value) {
98
11.5M
            unsigned_val ^=
99
11.5M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
11.5M
        }
101
        // make it bigendian
102
11.5M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
11.5M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
11.5M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
21.8M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
21.8M
        UnsignedCppType unsigned_val;
95
21.8M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
21.9M
        if (IsSigned<CppType>::value) {
98
21.9M
            unsigned_val ^=
99
21.9M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
21.9M
        }
101
        // make it bigendian
102
21.8M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
21.8M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
21.8M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
676k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
676k
        UnsignedCppType unsigned_val;
95
676k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
676k
        if (IsSigned<CppType>::value) {
98
676k
            unsigned_val ^=
99
676k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
676k
        }
101
        // make it bigendian
102
676k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
676k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
676k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
615k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
615k
        UnsignedCppType unsigned_val;
95
615k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
615k
        if (IsSigned<CppType>::value) {
98
615k
            unsigned_val ^=
99
615k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
615k
        }
101
        // make it bigendian
102
615k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
615k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
615k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.23M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.23M
        UnsignedCppType unsigned_val;
95
1.23M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.23M
        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.23M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.23M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.23M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.65M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.65M
        UnsignedCppType unsigned_val;
95
1.65M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.65M
        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.65M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.65M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.65M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
453k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
453k
        UnsignedCppType unsigned_val;
95
453k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
453k
        if (IsSigned<CppType>::value) {
98
453k
            unsigned_val ^=
99
453k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
453k
        }
101
        // make it bigendian
102
453k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
453k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
453k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
399k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
399k
        UnsignedCppType unsigned_val;
95
399k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
399k
        if (IsSigned<CppType>::value) {
98
399k
            unsigned_val ^=
99
399k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
399k
        }
101
        // make it bigendian
102
399k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
399k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
399k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
520k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
520k
        UnsignedCppType unsigned_val;
95
520k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
520k
        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
520k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
520k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
520k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
8.15k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
8.15k
        UnsignedCppType unsigned_val;
95
8.15k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
8.15k
        if (IsSigned<CppType>::value) {
98
8.15k
            unsigned_val ^=
99
8.15k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
8.15k
        }
101
        // make it bigendian
102
8.15k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
8.15k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
8.15k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
5.14k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
5.14k
        UnsignedCppType unsigned_val;
95
5.14k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
5.14k
        if (IsSigned<CppType>::value) {
98
5.14k
            unsigned_val ^=
99
5.14k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
5.14k
        }
101
        // make it bigendian
102
5.14k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
5.14k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
5.14k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.42M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.42M
        UnsignedCppType unsigned_val;
95
1.42M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.42M
        if (IsSigned<CppType>::value) {
98
1.42M
            unsigned_val ^=
99
1.42M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
1.42M
        }
101
        // make it bigendian
102
1.42M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.42M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.42M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
2.01k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
2.01k
        UnsignedCppType unsigned_val;
95
2.01k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
2.01k
        if (IsSigned<CppType>::value) {
98
2.01k
            unsigned_val ^=
99
2.01k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
2.01k
        }
101
        // make it bigendian
102
2.01k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
2.01k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
2.01k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.40k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.40k
        UnsignedCppType unsigned_val;
95
1.40k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.40k
        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.40k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.40k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.40k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
26.6k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
26.6k
        UnsignedCppType unsigned_val;
95
26.6k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
26.6k
        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
26.6k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
26.6k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
26.6k
    }
106
107
111k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
111k
        full_encode_ascending(value, buf);
109
111k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.06k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.06k
        full_encode_ascending(value, buf);
109
2.06k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.12k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.12k
        full_encode_ascending(value, buf);
109
2.12k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
79.7k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
79.7k
        full_encode_ascending(value, buf);
109
79.7k
    }
_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.9k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
16.9k
        full_encode_ascending(value, buf);
109
16.9k
    }
_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
6.78k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
6.78k
        full_encode_ascending(value, buf);
109
6.78k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
228
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
228
        full_encode_ascending(value, buf);
109
228
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
580
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
580
        full_encode_ascending(value, buf);
109
580
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
150
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
150
        full_encode_ascending(value, buf);
109
150
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
261
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
261
        full_encode_ascending(value, buf);
109
261
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
1.75k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
1.75k
        full_encode_ascending(value, buf);
109
1.75k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
127
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
127
        full_encode_ascending(value, buf);
109
127
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
77
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
77
        full_encode_ascending(value, buf);
109
77
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
74
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
74
        full_encode_ascending(value, buf);
109
74
    }
110
111
584k
    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
584k
        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
584k
        UnsignedCppType unsigned_val;
119
584k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
584k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
584k
        if (IsSigned<CppType>::value) {
122
115k
            unsigned_val ^=
123
115k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
115k
        }
125
584k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
584k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
584k
        return Status::OK();
128
584k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
114k
    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
114k
        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
114k
        UnsignedCppType unsigned_val;
119
114k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
114k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
114k
        if (IsSigned<CppType>::value) {
122
114k
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
114k
        }
125
114k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
114k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
114k
        return Status::OK();
128
114k
    }
_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
132k
    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
132k
        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
132k
        UnsignedCppType unsigned_val;
119
132k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
132k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
132k
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
132k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
132k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
132k
        return Status::OK();
128
132k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
336k
    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
336k
        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
336k
        UnsignedCppType unsigned_val;
119
336k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
336k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
336k
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
336k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
336k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
336k
        return Status::OK();
128
336k
    }
_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
401k
    static void full_encode_ascending(const void* value, std::string* buf) {
140
401k
        UnsignedCppType unsigned_val;
141
401k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
142
        // make it bigendian
143
401k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
144
401k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
145
401k
    }
146
147
226
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
148
226
        full_encode_ascending(value, buf);
149
226
    }
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
814k
    static void full_encode_ascending(const void* value, std::string* buf) {
174
814k
        UnsignedCppType unsigned_val;
175
814k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
176
        // make it bigendian
177
814k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
178
814k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
179
814k
    }
180
181
6.08k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
182
6.08k
        full_encode_ascending(value, buf);
183
6.08k
    }
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.07M
    static void full_encode_ascending(const void* value, std::string* buf) {
209
1.07M
        UnsignedCppType unsigned_val;
210
1.07M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
211
        // make it bigendian
212
1.07M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
213
1.07M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
214
1.07M
    }
215
216
1.98k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
217
1.98k
        full_encode_ascending(value, buf);
218
1.98k
    }
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
13.4k
    static void full_encode_ascending(const void* value, std::string* buf) {
244
13.4k
        UnsignedCppType unsigned_val;
245
13.4k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
246
        // make it bigendian
247
13.4k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
248
13.4k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
249
13.4k
    }
250
251
1.32k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
252
1.32k
        full_encode_ascending(value, buf);
253
1.32k
    }
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
363
    static void full_encode_ascending(const void* value, std::string* buf) {
274
363
        decimal12_t decimal_val;
275
363
        memcpy(&decimal_val, value, sizeof(decimal12_t));
276
363
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::full_encode_ascending(
277
363
                &decimal_val.integer, buf);
278
363
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::full_encode_ascending(&decimal_val.fraction,
279
363
                                                                              buf);
280
363
    } // namespace doris
281
282
52
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
283
52
        full_encode_ascending(value, buf);
284
52
    }
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
2.49k
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
301
2.49k
        auto slice = reinterpret_cast<const Slice*>(value);
302
2.49k
        buf->append(slice->get_data(), slice->get_size());
303
2.49k
    }
304
305
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
306
1.14k
                                                       std::string* buf) {
307
1.14k
        const Slice* slice = (const Slice*)value;
308
1.14k
        CHECK(index_size <= slice->size)
309
0
                << "index size is larger than char size, index=" << index_size
310
0
                << ", char=" << slice->size;
311
1.14k
        buf->append(slice->data, index_size);
312
1.14k
    }
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
14.5M
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
323
14.5M
        auto slice = reinterpret_cast<const Slice*>(value);
324
14.5M
        buf->append(slice->get_data(), slice->get_size());
325
14.5M
    }
326
327
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
328
18.7k
                                                       std::string* buf) {
329
18.7k
        const Slice* slice = (const Slice*)value;
330
18.7k
        size_t copy_size = std::min(index_size, slice->size);
331
18.7k
        buf->append(slice->data, copy_size);
332
18.7k
    }
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
643
    static UnsignedCppType encode_float(CppType value) {
366
643
        return sortable_float_bits(float_to_int_bits(value));
367
643
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE12encode_floatEf
Line
Count
Source
365
297
    static UnsignedCppType encode_float(CppType value) {
366
297
        return sortable_float_bits(float_to_int_bits(value));
367
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE12encode_floatEd
Line
Count
Source
365
346
    static UnsignedCppType encode_float(CppType value) {
366
346
        return sortable_float_bits(float_to_int_bits(value));
367
346
    }
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
643
    static void full_encode_ascending(const void* value, std::string* buf) {
375
643
        CppType val;
376
643
        std::memcpy(&val, value, sizeof(CppType));
377
643
        UnsignedCppType sortable_val = encode_float(val);
378
643
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
643
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
643
        sortable_val ^= sign_bit;
381
643
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
643
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
643
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
374
297
    static void full_encode_ascending(const void* value, std::string* buf) {
375
297
        CppType val;
376
297
        std::memcpy(&val, value, sizeof(CppType));
377
297
        UnsignedCppType sortable_val = encode_float(val);
378
297
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
297
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
297
        sortable_val ^= sign_bit;
381
297
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
297
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
374
346
    static void full_encode_ascending(const void* value, std::string* buf) {
375
346
        CppType val;
376
346
        std::memcpy(&val, value, sizeof(CppType));
377
346
        UnsignedCppType sortable_val = encode_float(val);
378
346
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
346
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
346
        sortable_val ^= sign_bit;
381
346
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
346
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
346
    }
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
643
    static UnsignedCppType float_to_int_bits(CppType value) {
409
643
        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
643
        std::memcpy(&result, &value, sizeof(CppType));
419
643
        return result;
420
643
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE17float_to_int_bitsEf
Line
Count
Source
408
297
    static UnsignedCppType float_to_int_bits(CppType value) {
409
297
        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
297
        std::memcpy(&result, &value, sizeof(CppType));
419
297
        return result;
420
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE17float_to_int_bitsEd
Line
Count
Source
408
346
    static UnsignedCppType float_to_int_bits(CppType value) {
409
346
        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
346
        std::memcpy(&result, &value, sizeof(CppType));
419
346
        return result;
420
346
    }
421
422
771
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
771
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
771
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
771
        if ((bits & sign_bit) != 0) {
426
212
            return bits ^ (sign_bit - 1);
427
559
        } else {
428
559
            return bits;
429
559
        }
430
771
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE19sortable_float_bitsEj
Line
Count
Source
422
361
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
361
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
361
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
361
        if ((bits & sign_bit) != 0) {
426
106
            return bits ^ (sign_bit - 1);
427
255
        } else {
428
255
            return bits;
429
255
        }
430
361
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE19sortable_float_bitsEm
Line
Count
Source
422
410
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
410
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
410
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
410
        if ((bits & sign_bit) != 0) {
426
106
            return bits ^ (sign_bit - 1);
427
304
        } else {
428
304
            return bits;
429
304
        }
430
410
    }
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.5k
    M(OLAP_FIELD_TYPE_BOOL, TYPE_BOOLEAN)                 \
456
148k
    M(OLAP_FIELD_TYPE_TINYINT, TYPE_TINYINT)              \
457
148k
    M(OLAP_FIELD_TYPE_SMALLINT, TYPE_SMALLINT)            \
458
650k
    M(OLAP_FIELD_TYPE_INT, TYPE_INT)                      \
459
650k
    M(OLAP_FIELD_TYPE_BIGINT, TYPE_BIGINT)                \
460
35.0k
    M(OLAP_FIELD_TYPE_LARGEINT, TYPE_LARGEINT)            \
461
14.0k
    M(OLAP_FIELD_TYPE_FLOAT, TYPE_FLOAT)                  \
462
23
    M(OLAP_FIELD_TYPE_DOUBLE, TYPE_DOUBLE)                \
463
131
    M(OLAP_FIELD_TYPE_DECIMAL, TYPE_DECIMALV2)            \
464
446
    M(OLAP_FIELD_TYPE_DECIMAL32, TYPE_DECIMAL32)          \
465
446
    M(OLAP_FIELD_TYPE_DECIMAL64, TYPE_DECIMAL64)          \
466
1.36k
    M(OLAP_FIELD_TYPE_DECIMAL128I, TYPE_DECIMAL128I)      \
467
1.36k
    M(OLAP_FIELD_TYPE_DECIMAL256, TYPE_DECIMAL256)        \
468
2.30k
    M(OLAP_FIELD_TYPE_DATE, TYPE_DATE)                    \
469
2.30k
    M(OLAP_FIELD_TYPE_DATETIME, TYPE_DATETIME)            \
470
257k
    M(OLAP_FIELD_TYPE_DATEV2, TYPE_DATEV2)                \
471
257k
    M(OLAP_FIELD_TYPE_DATETIMEV2, TYPE_DATETIMEV2)        \
472
7.79k
    M(OLAP_FIELD_TYPE_TIMESTAMPTZ, TYPE_TIMESTAMPTZ)      \
473
7.79k
    M(OLAP_FIELD_TYPE_IPV4, TYPE_IPV4)                    \
474
218
    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.14M
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
1.14M
    static_assert(is_key_encodable_non_string_type(PT),
499
1.14M
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
1.14M
                  "strings have their own path in RowCursor that calls "
501
1.14M
                  "storage_field->full_encode_ascending directly, and nested / "
502
1.14M
                  "aggregate types are not key-encodable");
503
1.14M
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
1.14M
    coder->full_encode_ascending(&v, buf);
505
1.14M
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE2EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
11.5k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
11.5k
    static_assert(is_key_encodable_non_string_type(PT),
499
11.5k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
11.5k
                  "strings have their own path in RowCursor that calls "
501
11.5k
                  "storage_field->full_encode_ascending directly, and nested / "
502
11.5k
                  "aggregate types are not key-encodable");
503
11.5k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
11.5k
    coder->full_encode_ascending(&v, buf);
505
11.5k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE3EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
148k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
148k
    static_assert(is_key_encodable_non_string_type(PT),
499
148k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
148k
                  "strings have their own path in RowCursor that calls "
501
148k
                  "storage_field->full_encode_ascending directly, and nested / "
502
148k
                  "aggregate types are not key-encodable");
503
148k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
148k
    coder->full_encode_ascending(&v, buf);
505
148k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE4EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
5.43k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
5.43k
    static_assert(is_key_encodable_non_string_type(PT),
499
5.43k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
5.43k
                  "strings have their own path in RowCursor that calls "
501
5.43k
                  "storage_field->full_encode_ascending directly, and nested / "
502
5.43k
                  "aggregate types are not key-encodable");
503
5.43k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
5.43k
    coder->full_encode_ascending(&v, buf);
505
5.43k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE5EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
649k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
649k
    static_assert(is_key_encodable_non_string_type(PT),
499
649k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
649k
                  "strings have their own path in RowCursor that calls "
501
649k
                  "storage_field->full_encode_ascending directly, and nested / "
502
649k
                  "aggregate types are not key-encodable");
503
649k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
649k
    coder->full_encode_ascending(&v, buf);
505
649k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE6EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
35.0k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
35.0k
    static_assert(is_key_encodable_non_string_type(PT),
499
35.0k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
35.0k
                  "strings have their own path in RowCursor that calls "
501
35.0k
                  "storage_field->full_encode_ascending directly, and nested / "
502
35.0k
                  "aggregate types are not key-encodable");
503
35.0k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
35.0k
    coder->full_encode_ascending(&v, buf);
505
35.0k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE7EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
14.0k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
14.0k
    static_assert(is_key_encodable_non_string_type(PT),
499
14.0k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
14.0k
                  "strings have their own path in RowCursor that calls "
501
14.0k
                  "storage_field->full_encode_ascending directly, and nested / "
502
14.0k
                  "aggregate types are not key-encodable");
503
14.0k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
14.0k
    coder->full_encode_ascending(&v, buf);
505
14.0k
}
_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
134
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
134
    static_assert(is_key_encodable_non_string_type(PT),
499
134
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
134
                  "strings have their own path in RowCursor that calls "
501
134
                  "storage_field->full_encode_ascending directly, and nested / "
502
134
                  "aggregate types are not key-encodable");
503
134
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
134
    coder->full_encode_ascending(&v, buf);
505
134
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE28EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
461
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
461
    static_assert(is_key_encodable_non_string_type(PT),
499
461
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
461
                  "strings have their own path in RowCursor that calls "
501
461
                  "storage_field->full_encode_ascending directly, and nested / "
502
461
                  "aggregate types are not key-encodable");
503
461
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
461
    coder->full_encode_ascending(&v, buf);
505
461
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE29EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
393
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
393
    static_assert(is_key_encodable_non_string_type(PT),
499
393
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
393
                  "strings have their own path in RowCursor that calls "
501
393
                  "storage_field->full_encode_ascending directly, and nested / "
502
393
                  "aggregate types are not key-encodable");
503
393
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
393
    coder->full_encode_ascending(&v, buf);
505
393
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE30EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
1.37k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
1.37k
    static_assert(is_key_encodable_non_string_type(PT),
499
1.37k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
1.37k
                  "strings have their own path in RowCursor that calls "
501
1.37k
                  "storage_field->full_encode_ascending directly, and nested / "
502
1.37k
                  "aggregate types are not key-encodable");
503
1.37k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
1.37k
    coder->full_encode_ascending(&v, buf);
505
1.37k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE35EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
784
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
784
    static_assert(is_key_encodable_non_string_type(PT),
499
784
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
784
                  "strings have their own path in RowCursor that calls "
501
784
                  "storage_field->full_encode_ascending directly, and nested / "
502
784
                  "aggregate types are not key-encodable");
503
784
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
784
    coder->full_encode_ascending(&v, buf);
505
784
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE11EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
2.30k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
2.30k
    static_assert(is_key_encodable_non_string_type(PT),
499
2.30k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
2.30k
                  "strings have their own path in RowCursor that calls "
501
2.30k
                  "storage_field->full_encode_ascending directly, and nested / "
502
2.30k
                  "aggregate types are not key-encodable");
503
2.30k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
2.30k
    coder->full_encode_ascending(&v, buf);
505
2.30k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE12EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
329
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
329
    static_assert(is_key_encodable_non_string_type(PT),
499
329
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
329
                  "strings have their own path in RowCursor that calls "
501
329
                  "storage_field->full_encode_ascending directly, and nested / "
502
329
                  "aggregate types are not key-encodable");
503
329
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
329
    coder->full_encode_ascending(&v, buf);
505
329
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE25EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
257k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
257k
    static_assert(is_key_encodable_non_string_type(PT),
499
257k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
257k
                  "strings have their own path in RowCursor that calls "
501
257k
                  "storage_field->full_encode_ascending directly, and nested / "
502
257k
                  "aggregate types are not key-encodable");
503
257k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
257k
    coder->full_encode_ascending(&v, buf);
505
257k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE26EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
7.12k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
7.12k
    static_assert(is_key_encodable_non_string_type(PT),
499
7.12k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
7.12k
                  "strings have their own path in RowCursor that calls "
501
7.12k
                  "storage_field->full_encode_ascending directly, and nested / "
502
7.12k
                  "aggregate types are not key-encodable");
503
7.12k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
7.12k
    coder->full_encode_ascending(&v, buf);
505
7.12k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE42EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
7.78k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
7.78k
    static_assert(is_key_encodable_non_string_type(PT),
499
7.78k
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
7.78k
                  "strings have their own path in RowCursor that calls "
501
7.78k
                  "storage_field->full_encode_ascending directly, and nested / "
502
7.78k
                  "aggregate types are not key-encodable");
503
7.78k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
7.78k
    coder->full_encode_ascending(&v, buf);
505
7.78k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE36EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
209
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
209
    static_assert(is_key_encodable_non_string_type(PT),
499
209
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
209
                  "strings have their own path in RowCursor that calls "
501
209
                  "storage_field->full_encode_ascending directly, and nested / "
502
209
                  "aggregate types are not key-encodable");
503
209
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
209
    coder->full_encode_ascending(&v, buf);
505
209
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE37EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
497
165
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
498
165
    static_assert(is_key_encodable_non_string_type(PT),
499
165
                  "full_encode_field_as_key is for non-string scalar keys only; "
500
165
                  "strings have their own path in RowCursor that calls "
501
165
                  "storage_field->full_encode_ascending directly, and nested / "
502
165
                  "aggregate types are not key-encodable");
503
165
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
504
165
    coder->full_encode_ascending(&v, buf);
505
165
}
506
507
} // namespace doris