Coverage Report

Created: 2026-08-15 21:01

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.8M
    void full_encode_ascending(const void* value, std::string* buf) const {
59
54.8M
        _full_encode_ascending(value, buf);
60
54.8M
    }
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
149k
    void encode_ascending(const void* value, size_t index_size, std::string* buf) const {
65
149k
        _encode_ascending(value, index_size, buf);
66
149k
    }
67
68
    // Only used for test, should delete it in the future
69
142k
    Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const {
70
142k
        return _decode_ascending(encoded_key, index_size, cell_ptr);
71
142k
    }
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.1M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
41.1M
        UnsignedCppType unsigned_val;
95
41.1M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
41.1M
        if (IsSigned<CppType>::value) {
98
37.6M
            unsigned_val ^=
99
37.6M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
37.6M
        }
101
        // make it bigendian
102
41.1M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
41.1M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
41.1M
    }
_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.5M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
22.5M
        UnsignedCppType unsigned_val;
95
22.5M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
22.6M
        if (IsSigned<CppType>::value) {
98
22.6M
            unsigned_val ^=
99
22.6M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
22.6M
        }
101
        // make it bigendian
102
22.5M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
22.5M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
22.5M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.64M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.64M
        UnsignedCppType unsigned_val;
95
1.64M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.64M
        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.64M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.64M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.64M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
691k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
691k
        UnsignedCppType unsigned_val;
95
691k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
691k
        if (IsSigned<CppType>::value) {
98
691k
            unsigned_val ^=
99
691k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
691k
        }
101
        // make it bigendian
102
691k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
691k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
691k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
629k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
629k
        UnsignedCppType unsigned_val;
95
629k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
629k
        if (IsSigned<CppType>::value) {
98
629k
            unsigned_val ^=
99
629k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
629k
        }
101
        // make it bigendian
102
629k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
629k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
629k
    }
_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_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
447k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
447k
        UnsignedCppType unsigned_val;
95
447k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
447k
        if (IsSigned<CppType>::value) {
98
447k
            unsigned_val ^=
99
447k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
447k
        }
101
        // make it bigendian
102
447k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
447k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
447k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
398k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
398k
        UnsignedCppType unsigned_val;
95
398k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
398k
        if (IsSigned<CppType>::value) {
98
398k
            unsigned_val ^=
99
398k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
398k
        }
101
        // make it bigendian
102
398k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
398k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
398k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
596k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
596k
        UnsignedCppType unsigned_val;
95
596k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
596k
        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
596k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
596k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
596k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE41EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
394
    static void full_encode_ascending(const void* value, std::string* buf) {
94
394
        UnsignedCppType unsigned_val;
95
394
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
394
        if (IsSigned<CppType>::value) {
98
394
            unsigned_val ^=
99
394
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
394
        }
101
        // make it bigendian
102
394
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
394
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
394
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
11.5k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
11.5k
        UnsignedCppType unsigned_val;
95
11.5k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
11.5k
        if (IsSigned<CppType>::value) {
98
11.5k
            unsigned_val ^=
99
11.5k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
11.5k
        }
101
        // make it bigendian
102
11.5k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
11.5k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
11.5k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
6.01k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
6.01k
        UnsignedCppType unsigned_val;
95
6.01k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
6.01k
        if (IsSigned<CppType>::value) {
98
6.01k
            unsigned_val ^=
99
6.01k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
6.01k
        }
101
        // make it bigendian
102
6.01k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
6.01k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
6.01k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.43M
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.43M
        UnsignedCppType unsigned_val;
95
1.43M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.43M
        if (IsSigned<CppType>::value) {
98
1.43M
            unsigned_val ^=
99
1.43M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
1.43M
        }
101
        // make it bigendian
102
1.43M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.43M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.43M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
2.64k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
2.64k
        UnsignedCppType unsigned_val;
95
2.64k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
2.64k
        if (IsSigned<CppType>::value) {
98
2.64k
            unsigned_val ^=
99
2.64k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
100
2.64k
        }
101
        // make it bigendian
102
2.64k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
2.64k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
2.64k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
2.00k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
2.00k
        UnsignedCppType unsigned_val;
95
2.00k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
2.00k
        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
2.00k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
2.00k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
2.00k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
93
1.96k
    static void full_encode_ascending(const void* value, std::string* buf) {
94
1.96k
        UnsignedCppType unsigned_val;
95
1.96k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
96
        // swap MSB to encode integer
97
1.96k
        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.96k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
103
104
1.96k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
105
1.96k
    }
106
107
116k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
116k
        full_encode_ascending(value, buf);
109
116k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.49k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.49k
        full_encode_ascending(value, buf);
109
2.49k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
2.68k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.68k
        full_encode_ascending(value, buf);
109
2.68k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
81.0k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
81.0k
        full_encode_ascending(value, buf);
109
81.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.8k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
16.8k
        full_encode_ascending(value, buf);
109
16.8k
    }
_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.32k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
7.32k
        full_encode_ascending(value, buf);
109
7.32k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
252
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
252
        full_encode_ascending(value, buf);
109
252
    }
_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_9FieldTypeE41EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
107
240
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
240
        full_encode_ascending(value, buf);
109
240
    }
_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.15k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
108
2.15k
        full_encode_ascending(value, buf);
109
2.15k
    }
_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
2.47M
    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
2.47M
        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
2.47M
        UnsignedCppType unsigned_val;
119
2.47M
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
2.47M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
2.47M
        if (IsSigned<CppType>::value) {
122
14.9k
            unsigned_val ^=
123
14.9k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
14.9k
        }
125
2.47M
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
2.47M
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
2.47M
        return Status::OK();
128
2.47M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
14.3k
    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
14.3k
        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
14.3k
        UnsignedCppType unsigned_val;
119
14.3k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
14.3k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
14.3k
        if (IsSigned<CppType>::value) {
122
14.3k
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
14.3k
        }
125
14.3k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
14.3k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
14.3k
        return Status::OK();
128
14.3k
    }
_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_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
2.32M
    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
2.32M
        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
2.32M
        UnsignedCppType unsigned_val;
119
2.32M
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
2.32M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
2.32M
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
2.32M
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
2.32M
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
2.32M
        return Status::OK();
128
2.32M
    }
_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
127k
    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
127k
        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
127k
        UnsignedCppType unsigned_val;
119
127k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
127k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
127k
        if (IsSigned<CppType>::value) {
122
0
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
0
        }
125
127k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
127k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
127k
        return Status::OK();
128
127k
    }
_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_9FieldTypeE41EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
111
2
    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
2
        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
2
        UnsignedCppType unsigned_val;
119
2
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
120
2
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
121
2
        if (IsSigned<CppType>::value) {
122
2
            unsigned_val ^=
123
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
124
2
        }
125
2
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
126
2
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
127
2
        return Status::OK();
128
2
    }
_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
414k
    static void full_encode_ascending(const void* value, std::string* buf) {
140
414k
        UnsignedCppType unsigned_val;
141
414k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
142
        // make it bigendian
143
414k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
144
414k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
145
414k
    }
146
147
249
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
148
249
        full_encode_ascending(value, buf);
149
249
    }
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
734k
    static void full_encode_ascending(const void* value, std::string* buf) {
174
734k
        UnsignedCppType unsigned_val;
175
734k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
176
        // make it bigendian
177
734k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
178
734k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
179
734k
    }
180
181
6.38k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
182
6.38k
        full_encode_ascending(value, buf);
183
6.38k
    }
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.10M
    static void full_encode_ascending(const void* value, std::string* buf) {
209
1.10M
        UnsignedCppType unsigned_val;
210
1.10M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
211
        // make it bigendian
212
1.10M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
213
1.10M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
214
1.10M
    }
215
216
2.60k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
217
2.60k
        full_encode_ascending(value, buf);
218
2.60k
    }
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
15.9k
    static void full_encode_ascending(const void* value, std::string* buf) {
244
15.9k
        UnsignedCppType unsigned_val;
245
15.9k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
246
        // make it bigendian
247
15.9k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
248
15.9k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
249
15.9k
    }
250
251
1.77k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
252
1.77k
        full_encode_ascending(value, buf);
253
1.77k
    }
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
901
    static void full_encode_ascending(const void* value, std::string* buf) {
274
901
        decimal12_t decimal_val;
275
901
        memcpy(&decimal_val, value, sizeof(decimal12_t));
276
901
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::full_encode_ascending(
277
901
                &decimal_val.integer, buf);
278
901
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::full_encode_ascending(&decimal_val.fraction,
279
901
                                                                              buf);
280
901
    } // 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.46k
                                                       std::string* buf) {
307
1.46k
        const Slice* slice = (const Slice*)value;
308
1.46k
        CHECK(index_size <= slice->size)
309
0
                << "index size is larger than char size, index=" << index_size
310
0
                << ", char=" << slice->size;
311
1.46k
        buf->append(slice->data, index_size);
312
1.46k
    }
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.3M
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf) {
323
13.3M
        auto slice = reinterpret_cast<const Slice*>(value);
324
13.3M
        buf->append(slice->get_data(), slice->get_size());
325
13.3M
    }
326
327
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
328
19.5k
                                                       std::string* buf) {
329
19.5k
        const Slice* slice = (const Slice*)value;
330
19.5k
        size_t copy_size = std::min(index_size, slice->size);
331
19.5k
        buf->append(slice->data, copy_size);
332
19.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
627
    static UnsignedCppType encode_float(CppType value) {
366
627
        return sortable_float_bits(float_to_int_bits(value));
367
627
    }
_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
330
    static UnsignedCppType encode_float(CppType value) {
366
330
        return sortable_float_bits(float_to_int_bits(value));
367
330
    }
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
627
    static void full_encode_ascending(const void* value, std::string* buf) {
375
627
        CppType val;
376
627
        std::memcpy(&val, value, sizeof(CppType));
377
627
        UnsignedCppType sortable_val = encode_float(val);
378
627
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
627
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
627
        sortable_val ^= sign_bit;
381
627
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
627
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
627
    }
_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
330
    static void full_encode_ascending(const void* value, std::string* buf) {
375
330
        CppType val;
376
330
        std::memcpy(&val, value, sizeof(CppType));
377
330
        UnsignedCppType sortable_val = encode_float(val);
378
330
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
379
330
                                             << (sizeof(UnsignedCppType) * 8 - 1);
380
330
        sortable_val ^= sign_bit;
381
330
        sortable_val = to_endian<std::endian::big>(sortable_val);
382
330
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
383
330
    }
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
627
    static UnsignedCppType float_to_int_bits(CppType value) {
409
627
        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
627
        std::memcpy(&result, &value, sizeof(CppType));
419
627
        return result;
420
627
    }
_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
330
    static UnsignedCppType float_to_int_bits(CppType value) {
409
330
        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
330
        std::memcpy(&result, &value, sizeof(CppType));
419
330
        return result;
420
330
    }
421
422
755
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
755
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
755
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
755
        if ((bits & sign_bit) != 0) {
426
212
            return bits ^ (sign_bit - 1);
427
543
        } else {
428
543
            return bits;
429
543
        }
430
755
    }
_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
394
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
423
394
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
424
394
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
425
394
        if ((bits & sign_bit) != 0) {
426
106
            return bits ^ (sign_bit - 1);
427
288
        } else {
428
288
            return bits;
429
288
        }
430
394
    }
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.9k
    M(OLAP_FIELD_TYPE_BOOL, TYPE_BOOLEAN)                 \
456
150k
    M(OLAP_FIELD_TYPE_TINYINT, TYPE_TINYINT)              \
457
150k
    M(OLAP_FIELD_TYPE_SMALLINT, TYPE_SMALLINT)            \
458
702k
    M(OLAP_FIELD_TYPE_INT, TYPE_INT)                      \
459
702k
    M(OLAP_FIELD_TYPE_BIGINT, TYPE_BIGINT)                \
460
37.3k
    M(OLAP_FIELD_TYPE_LARGEINT, TYPE_LARGEINT)            \
461
14.3k
    M(OLAP_FIELD_TYPE_FLOAT, TYPE_FLOAT)                  \
462
23
    M(OLAP_FIELD_TYPE_DOUBLE, TYPE_DOUBLE)                \
463
137
    M(OLAP_FIELD_TYPE_DECIMAL, TYPE_DECIMALV2)            \
464
449
    M(OLAP_FIELD_TYPE_DECIMAL32, TYPE_DECIMAL32)          \
465
449
    M(OLAP_FIELD_TYPE_DECIMAL64, TYPE_DECIMAL64)          \
466
1.14k
    M(OLAP_FIELD_TYPE_DECIMAL128I, TYPE_DECIMAL128I)      \
467
1.14k
    M(OLAP_FIELD_TYPE_DECIMAL256, TYPE_DECIMAL256)        \
468
14.1k
    M(OLAP_FIELD_TYPE_DATE, TYPE_DATE)                    \
469
14.1k
    M(OLAP_FIELD_TYPE_DATETIME, TYPE_DATETIME)            \
470
232k
    M(OLAP_FIELD_TYPE_DATEV2, TYPE_DATEV2)                \
471
232k
    M(OLAP_FIELD_TYPE_DATETIMEV2, TYPE_DATETIMEV2)        \
472
7.87k
    M(OLAP_FIELD_TYPE_TIMESTAMP_NS, TYPE_TIMESTAMP_NS)    \
473
8.31k
    M(OLAP_FIELD_TYPE_TIMESTAMPTZ, TYPE_TIMESTAMPTZ)      \
474
8.31k
    M(OLAP_FIELD_TYPE_IPV4, TYPE_IPV4)                    \
475
195
    M(OLAP_FIELD_TYPE_IPV6, TYPE_IPV6)
476
477
// True for exactly the PrimitiveTypes listed in
478
// DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES. Strings (CHAR/VARCHAR/STRING/
479
// VARBINARY) have their own short-key code path in row_cursor.cpp that calls
480
// storage_field->full_encode_ascending directly, and nested/aggregate types
481
// (ARRAY/MAP/STRUCT/VARIANT/HLL/BITMAP/JSONB/QUANTILE_STATE/AGG_STATE) are not
482
// key-encodable at all -- both groups must never reach the helpers below.
483
0
constexpr bool is_key_encodable_non_string_type(PrimitiveType pt) {
484
0
    switch (pt) {
485
0
#define DORIS_KEY_ENCODABLE_CASE(FT, PT) \
486
0
    case PrimitiveType::PT:              \
487
0
        return true;
488
0
        DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(DORIS_KEY_ENCODABLE_CASE)
489
0
#undef DORIS_KEY_ENCODABLE_CASE
490
0
    default:
491
0
        return false;
492
0
    }
493
0
}
494
495
// Convert a Field value to its storage representation (via PrimitiveTypeConvertor)
496
// and full-encode it as a byte-comparable ascending key via KeyCoder.
497
template <PrimitiveType PT>
498
1.18M
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
1.18M
    static_assert(is_key_encodable_non_string_type(PT),
500
1.18M
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
1.18M
                  "strings have their own path in RowCursor that calls "
502
1.18M
                  "storage_field->full_encode_ascending directly, and nested / "
503
1.18M
                  "aggregate types are not key-encodable");
504
1.18M
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
1.18M
    coder->full_encode_ascending(&v, buf);
506
1.18M
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE2EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
11.9k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
11.9k
    static_assert(is_key_encodable_non_string_type(PT),
500
11.9k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
11.9k
                  "strings have their own path in RowCursor that calls "
502
11.9k
                  "storage_field->full_encode_ascending directly, and nested / "
503
11.9k
                  "aggregate types are not key-encodable");
504
11.9k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
11.9k
    coder->full_encode_ascending(&v, buf);
506
11.9k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE3EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
150k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
150k
    static_assert(is_key_encodable_non_string_type(PT),
500
150k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
150k
                  "strings have their own path in RowCursor that calls "
502
150k
                  "storage_field->full_encode_ascending directly, and nested / "
503
150k
                  "aggregate types are not key-encodable");
504
150k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
150k
    coder->full_encode_ascending(&v, buf);
506
150k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE4EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
5.35k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
5.35k
    static_assert(is_key_encodable_non_string_type(PT),
500
5.35k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
5.35k
                  "strings have their own path in RowCursor that calls "
502
5.35k
                  "storage_field->full_encode_ascending directly, and nested / "
503
5.35k
                  "aggregate types are not key-encodable");
504
5.35k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
5.35k
    coder->full_encode_ascending(&v, buf);
506
5.35k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE5EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
700k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
700k
    static_assert(is_key_encodable_non_string_type(PT),
500
700k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
700k
                  "strings have their own path in RowCursor that calls "
502
700k
                  "storage_field->full_encode_ascending directly, and nested / "
503
700k
                  "aggregate types are not key-encodable");
504
700k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
700k
    coder->full_encode_ascending(&v, buf);
506
700k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE6EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
37.2k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
37.2k
    static_assert(is_key_encodable_non_string_type(PT),
500
37.2k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
37.2k
                  "strings have their own path in RowCursor that calls "
502
37.2k
                  "storage_field->full_encode_ascending directly, and nested / "
503
37.2k
                  "aggregate types are not key-encodable");
504
37.2k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
37.2k
    coder->full_encode_ascending(&v, buf);
506
37.2k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE7EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
14.3k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
14.3k
    static_assert(is_key_encodable_non_string_type(PT),
500
14.3k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
14.3k
                  "strings have their own path in RowCursor that calls "
502
14.3k
                  "storage_field->full_encode_ascending directly, and nested / "
503
14.3k
                  "aggregate types are not key-encodable");
504
14.3k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
14.3k
    coder->full_encode_ascending(&v, buf);
506
14.3k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE8EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
28
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
28
    static_assert(is_key_encodable_non_string_type(PT),
500
28
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
28
                  "strings have their own path in RowCursor that calls "
502
28
                  "storage_field->full_encode_ascending directly, and nested / "
503
28
                  "aggregate types are not key-encodable");
504
28
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
28
    coder->full_encode_ascending(&v, buf);
506
28
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE9EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
26
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
26
    static_assert(is_key_encodable_non_string_type(PT),
500
26
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
26
                  "strings have their own path in RowCursor that calls "
502
26
                  "storage_field->full_encode_ascending directly, and nested / "
503
26
                  "aggregate types are not key-encodable");
504
26
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
26
    coder->full_encode_ascending(&v, buf);
506
26
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE20EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
140
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
140
    static_assert(is_key_encodable_non_string_type(PT),
500
140
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
140
                  "strings have their own path in RowCursor that calls "
502
140
                  "storage_field->full_encode_ascending directly, and nested / "
503
140
                  "aggregate types are not key-encodable");
504
140
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
140
    coder->full_encode_ascending(&v, buf);
506
140
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE28EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
464
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
464
    static_assert(is_key_encodable_non_string_type(PT),
500
464
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
464
                  "strings have their own path in RowCursor that calls "
502
464
                  "storage_field->full_encode_ascending directly, and nested / "
503
464
                  "aggregate types are not key-encodable");
504
464
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
464
    coder->full_encode_ascending(&v, buf);
506
464
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE29EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
390
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
390
    static_assert(is_key_encodable_non_string_type(PT),
500
390
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
390
                  "strings have their own path in RowCursor that calls "
502
390
                  "storage_field->full_encode_ascending directly, and nested / "
503
390
                  "aggregate types are not key-encodable");
504
390
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
390
    coder->full_encode_ascending(&v, buf);
506
390
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE30EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
1.14k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
1.14k
    static_assert(is_key_encodable_non_string_type(PT),
500
1.14k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
1.14k
                  "strings have their own path in RowCursor that calls "
502
1.14k
                  "storage_field->full_encode_ascending directly, and nested / "
503
1.14k
                  "aggregate types are not key-encodable");
504
1.14k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
1.14k
    coder->full_encode_ascending(&v, buf);
506
1.14k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE35EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
778
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
778
    static_assert(is_key_encodable_non_string_type(PT),
500
778
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
778
                  "strings have their own path in RowCursor that calls "
502
778
                  "storage_field->full_encode_ascending directly, and nested / "
503
778
                  "aggregate types are not key-encodable");
504
778
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
778
    coder->full_encode_ascending(&v, buf);
506
778
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE11EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
14.1k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
14.1k
    static_assert(is_key_encodable_non_string_type(PT),
500
14.1k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
14.1k
                  "strings have their own path in RowCursor that calls "
502
14.1k
                  "storage_field->full_encode_ascending directly, and nested / "
503
14.1k
                  "aggregate types are not key-encodable");
504
14.1k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
14.1k
    coder->full_encode_ascending(&v, buf);
506
14.1k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE12EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
528
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
528
    static_assert(is_key_encodable_non_string_type(PT),
500
528
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
528
                  "strings have their own path in RowCursor that calls "
502
528
                  "storage_field->full_encode_ascending directly, and nested / "
503
528
                  "aggregate types are not key-encodable");
504
528
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
528
    coder->full_encode_ascending(&v, buf);
506
528
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE25EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
231k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
231k
    static_assert(is_key_encodable_non_string_type(PT),
500
231k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
231k
                  "strings have their own path in RowCursor that calls "
502
231k
                  "storage_field->full_encode_ascending directly, and nested / "
503
231k
                  "aggregate types are not key-encodable");
504
231k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
231k
    coder->full_encode_ascending(&v, buf);
506
231k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE26EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
7.88k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
7.88k
    static_assert(is_key_encodable_non_string_type(PT),
500
7.88k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
7.88k
                  "strings have their own path in RowCursor that calls "
502
7.88k
                  "storage_field->full_encode_ascending directly, and nested / "
503
7.88k
                  "aggregate types are not key-encodable");
504
7.88k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
7.88k
    coder->full_encode_ascending(&v, buf);
506
7.88k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE43EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
45
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
45
    static_assert(is_key_encodable_non_string_type(PT),
500
45
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
45
                  "strings have their own path in RowCursor that calls "
502
45
                  "storage_field->full_encode_ascending directly, and nested / "
503
45
                  "aggregate types are not key-encodable");
504
45
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
45
    coder->full_encode_ascending(&v, buf);
506
45
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE42EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
8.29k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
8.29k
    static_assert(is_key_encodable_non_string_type(PT),
500
8.29k
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
8.29k
                  "strings have their own path in RowCursor that calls "
502
8.29k
                  "storage_field->full_encode_ascending directly, and nested / "
503
8.29k
                  "aggregate types are not key-encodable");
504
8.29k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
8.29k
    coder->full_encode_ascending(&v, buf);
506
8.29k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE36EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
185
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
185
    static_assert(is_key_encodable_non_string_type(PT),
500
185
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
185
                  "strings have their own path in RowCursor that calls "
502
185
                  "storage_field->full_encode_ascending directly, and nested / "
503
185
                  "aggregate types are not key-encodable");
504
185
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
185
    coder->full_encode_ascending(&v, buf);
506
185
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE37EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
498
165
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
499
165
    static_assert(is_key_encodable_non_string_type(PT),
500
165
                  "full_encode_field_as_key is for non-string scalar keys only; "
501
165
                  "strings have their own path in RowCursor that calls "
502
165
                  "storage_field->full_encode_ascending directly, and nested / "
503
165
                  "aggregate types are not key-encodable");
504
165
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
505
165
    coder->full_encode_ascending(&v, buf);
506
165
}
507
508
} // namespace doris