Coverage Report

Created: 2026-05-15 12:36

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
// `schema_length` is only meaningful for CHAR — the declared CHAR(N) column
45
// length. CHAR full-encoding pads the slice up to schema_length with trailing
46
// '\0' so the encoded bytes are the canonical fixed-width form used by PK
47
// and segment min/max indexes, regardless of the slice's actual character
48
// length. Other types ignore this arg.
49
using FullEncodeAscendingFunc = void (*)(const void* value, std::string* buf, size_t schema_length);
50
using EncodeAscendingFunc = void (*)(const void* value, size_t index_size, std::string* buf);
51
using DecodeAscendingFunc = Status (*)(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr);
52
53
// Order-preserving binary encoding for values of a particular type so that
54
// those values can be compared by memcpy their encoded bytes.
55
//
56
// To obtain instance of this class, use the `get_key_coder(FieldType)` method.
57
class KeyCoder {
58
public:
59
    template <typename TraitsType>
60
    KeyCoder(TraitsType traits);
61
62
    // encode the provided `value` into `buf`.
63
    // `schema_length` is the CHAR(N) declared length so KeyCoder for CHAR
64
    // can pad the (unpadded) source slice up to the canonical fixed-width
65
    // encoding. Pass 0 for non-CHAR columns (ignored).
66
    void full_encode_ascending(const void* value, std::string* buf,
67
59.4M
                               size_t schema_length = 0) const {
68
59.4M
        _full_encode_ascending(value, buf, schema_length);
69
59.4M
    }
70
71
    // similar to `full_encode_ascending`, but only encode part (the first `index_size` bytes) of the value.
72
    // only applicable to string type
73
147k
    void encode_ascending(const void* value, size_t index_size, std::string* buf) const {
74
147k
        _encode_ascending(value, index_size, buf);
75
147k
    }
76
77
    // Only used for test, should delete it in the future
78
251k
    Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const {
79
251k
        return _decode_ascending(encoded_key, index_size, cell_ptr);
80
251k
    }
81
82
private:
83
    FullEncodeAscendingFunc _full_encode_ascending;
84
    EncodeAscendingFunc _encode_ascending;
85
    DecodeAscendingFunc _decode_ascending;
86
};
87
88
extern const KeyCoder* get_key_coder(FieldType type);
89
90
template <FieldType field_type, typename Enable = void>
91
class KeyCoderTraits {};
92
93
template <FieldType field_type>
94
class KeyCoderTraits<field_type,
95
                     typename std::enable_if<
96
                             IsIntegral<typename CppTypeTraits<field_type>::CppType>::value ||
97
                             IsDecimalNumber<typename CppTypeTraits<field_type>::CppType>>::type> {
98
public:
99
    using CppType = typename CppTypeTraits<field_type>::CppType;
100
    using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType;
101
102
    static void full_encode_ascending(const void* value, std::string* buf,
103
41.2M
                                      size_t /*schema_length*/) {
104
41.2M
        UnsignedCppType unsigned_val;
105
41.2M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
41.2M
        if (IsSigned<CppType>::value) {
108
37.3M
            unsigned_val ^=
109
37.3M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
37.3M
        }
111
        // make it bigendian
112
41.2M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
41.2M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
41.2M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
11.6M
                                      size_t /*schema_length*/) {
104
11.6M
        UnsignedCppType unsigned_val;
105
11.6M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
11.6M
        if (IsSigned<CppType>::value) {
108
11.6M
            unsigned_val ^=
109
11.6M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
11.6M
        }
111
        // make it bigendian
112
11.6M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
11.6M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
11.6M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
21.9M
                                      size_t /*schema_length*/) {
104
21.9M
        UnsignedCppType unsigned_val;
105
21.9M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
21.9M
        if (IsSigned<CppType>::value) {
108
21.9M
            unsigned_val ^=
109
21.9M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
21.9M
        }
111
        // make it bigendian
112
21.9M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
21.9M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
21.9M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
677k
                                      size_t /*schema_length*/) {
104
677k
        UnsignedCppType unsigned_val;
105
677k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
677k
        if (IsSigned<CppType>::value) {
108
677k
            unsigned_val ^=
109
677k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
677k
        }
111
        // make it bigendian
112
677k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
677k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
677k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
614k
                                      size_t /*schema_length*/) {
104
614k
        UnsignedCppType unsigned_val;
105
614k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
614k
        if (IsSigned<CppType>::value) {
108
614k
            unsigned_val ^=
109
614k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
614k
        }
111
        // make it bigendian
112
614k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
614k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
614k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
1.21M
                                      size_t /*schema_length*/) {
104
1.21M
        UnsignedCppType unsigned_val;
105
1.21M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
1.21M
        if (IsSigned<CppType>::value) {
108
0
            unsigned_val ^=
109
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
0
        }
111
        // make it bigendian
112
1.21M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
1.21M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
1.21M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
1.95M
                                      size_t /*schema_length*/) {
104
1.95M
        UnsignedCppType unsigned_val;
105
1.95M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
1.95M
        if (IsSigned<CppType>::value) {
108
0
            unsigned_val ^=
109
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
0
        }
111
        // make it bigendian
112
1.95M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
1.95M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
1.95M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
524k
                                      size_t /*schema_length*/) {
104
524k
        UnsignedCppType unsigned_val;
105
524k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
524k
        if (IsSigned<CppType>::value) {
108
524k
            unsigned_val ^=
109
524k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
524k
        }
111
        // make it bigendian
112
524k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
524k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
524k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
400k
                                      size_t /*schema_length*/) {
104
400k
        UnsignedCppType unsigned_val;
105
400k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
400k
        if (IsSigned<CppType>::value) {
108
400k
            unsigned_val ^=
109
400k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
400k
        }
111
        // make it bigendian
112
400k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
400k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
400k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
586k
                                      size_t /*schema_length*/) {
104
586k
        UnsignedCppType unsigned_val;
105
586k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
586k
        if (IsSigned<CppType>::value) {
108
0
            unsigned_val ^=
109
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
0
        }
111
        // make it bigendian
112
586k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
586k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
586k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
8.80k
                                      size_t /*schema_length*/) {
104
8.80k
        UnsignedCppType unsigned_val;
105
8.80k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
8.80k
        if (IsSigned<CppType>::value) {
108
8.80k
            unsigned_val ^=
109
8.80k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
8.80k
        }
111
        // make it bigendian
112
8.80k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
8.80k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
8.80k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
5.42k
                                      size_t /*schema_length*/) {
104
5.42k
        UnsignedCppType unsigned_val;
105
5.42k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
5.42k
        if (IsSigned<CppType>::value) {
108
5.42k
            unsigned_val ^=
109
5.42k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
5.42k
        }
111
        // make it bigendian
112
5.42k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
5.42k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
5.42k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
1.59M
                                      size_t /*schema_length*/) {
104
1.59M
        UnsignedCppType unsigned_val;
105
1.59M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
1.59M
        if (IsSigned<CppType>::value) {
108
1.59M
            unsigned_val ^=
109
1.59M
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
1.59M
        }
111
        // make it bigendian
112
1.59M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
1.59M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
1.59M
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
2.00k
                                      size_t /*schema_length*/) {
104
2.00k
        UnsignedCppType unsigned_val;
105
2.00k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
2.00k
        if (IsSigned<CppType>::value) {
108
2.00k
            unsigned_val ^=
109
2.00k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
2.00k
        }
111
        // make it bigendian
112
2.00k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
2.00k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
2.00k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
66.7k
                                      size_t /*schema_length*/) {
104
66.7k
        UnsignedCppType unsigned_val;
105
66.7k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
66.7k
        if (IsSigned<CppType>::value) {
108
0
            unsigned_val ^=
109
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
0
        }
111
        // make it bigendian
112
66.7k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
66.7k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
66.7k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
103
56.9k
                                      size_t /*schema_length*/) {
104
56.9k
        UnsignedCppType unsigned_val;
105
56.9k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
106
        // swap MSB to encode integer
107
56.9k
        if (IsSigned<CppType>::value) {
108
0
            unsigned_val ^=
109
0
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
110
0
        }
111
        // make it bigendian
112
56.9k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
113
114
56.9k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
115
56.9k
    }
116
117
114k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
114k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
114k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
2.11k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
2.11k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
2.11k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
2.25k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
2.25k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
2.25k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
82.9k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
82.9k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
82.9k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
202
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
202
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
202
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
17.0k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
17.0k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
17.0k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
202
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
202
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
202
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
6.36k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
6.36k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
6.36k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
228
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
228
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
228
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
761
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
761
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
761
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
158
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
158
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
158
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
271
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
271
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
271
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
1.75k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
1.75k
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
1.75k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
127
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
127
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
127
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
77
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
77
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
77
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
117
74
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
118
74
        full_encode_ascending(value, buf, /*schema_length=*/0);
119
74
    }
120
121
572k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
572k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
572k
        UnsignedCppType unsigned_val;
129
572k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
572k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
572k
        if (IsSigned<CppType>::value) {
132
128k
            unsigned_val ^=
133
128k
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
128k
        }
135
572k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
572k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
572k
        return Status::OK();
138
572k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
127k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
127k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
127k
        UnsignedCppType unsigned_val;
129
127k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
127k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
127k
        if (IsSigned<CppType>::value) {
132
127k
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
127k
        }
135
127k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
127k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
127k
        return Status::OK();
138
127k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
117
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
117
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
117
        UnsignedCppType unsigned_val;
129
117
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
117
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
117
        if (IsSigned<CppType>::value) {
132
117
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
117
        }
135
117
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
117
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
117
        return Status::OK();
138
117
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
53
        UnsignedCppType unsigned_val;
129
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
53
        if (IsSigned<CppType>::value) {
132
53
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
53
        }
135
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
53
        return Status::OK();
138
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
53
        UnsignedCppType unsigned_val;
129
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
53
        if (IsSigned<CppType>::value) {
132
53
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
53
        }
135
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
53
        return Status::OK();
138
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
122k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
122k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
122k
        UnsignedCppType unsigned_val;
129
122k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
122k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
122k
        if (IsSigned<CppType>::value) {
132
0
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
0
        }
135
122k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
122k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
122k
        return Status::OK();
138
122k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
321k
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
321k
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
321k
        UnsignedCppType unsigned_val;
129
321k
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
321k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
321k
        if (IsSigned<CppType>::value) {
132
0
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
0
        }
135
321k
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
321k
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
321k
        return Status::OK();
138
321k
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
53
        UnsignedCppType unsigned_val;
129
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
53
        if (IsSigned<CppType>::value) {
132
53
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
53
        }
135
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
53
        return Status::OK();
138
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
53
        UnsignedCppType unsigned_val;
129
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
53
        if (IsSigned<CppType>::value) {
132
53
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
53
        }
135
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
53
        return Status::OK();
138
53
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE24EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
0
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
0
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE31EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
51
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
51
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE32EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
51
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
51
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE33EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
51
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
51
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE37EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
51
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
51
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE38EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
0
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
0
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE39EvE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
121
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
122
        // decode_ascending only used in orinal index page, maybe should remove it in the future.
123
        // currently, we reduce the usage of this method.
124
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
125
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
126
0
                                           sizeof(UnsignedCppType), encoded_key->size);
127
0
        }
128
51
        UnsignedCppType unsigned_val;
129
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
130
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
131
51
        if (IsSigned<CppType>::value) {
132
0
            unsigned_val ^=
133
                    (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1));
134
0
        }
135
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
136
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
137
51
        return Status::OK();
138
51
    }
139
};
140
141
template <>
142
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATE> {
143
public:
144
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::CppType;
145
    using UnsignedCppType =
146
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::UnsignedCppType;
147
148
public:
149
    static void full_encode_ascending(const void* value, std::string* buf,
150
416k
                                      size_t /*schema_length*/) {
151
416k
        UnsignedCppType unsigned_val;
152
416k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
153
        // make it bigendian
154
416k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
155
416k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
156
416k
    }
157
158
236
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
159
236
        full_encode_ascending(value, buf, /*schema_length=*/0);
160
236
    }
161
162
53
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
163
53
        if (encoded_key->size < sizeof(UnsignedCppType)) {
164
0
            return Status::InvalidArgument("Key too short, need={} vs real={}",
165
0
                                           sizeof(UnsignedCppType), encoded_key->size);
166
0
        }
167
53
        UnsignedCppType unsigned_val;
168
53
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
169
53
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
170
53
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
171
53
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
172
53
        return Status::OK();
173
53
    }
174
};
175
176
template <>
177
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATEV2> {
178
public:
179
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::CppType;
180
    using UnsignedCppType =
181
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::UnsignedCppType;
182
183
public:
184
    static void full_encode_ascending(const void* value, std::string* buf,
185
941k
                                      size_t /*schema_length*/) {
186
941k
        UnsignedCppType unsigned_val;
187
941k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
188
        // make it bigendian
189
941k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
190
941k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
191
941k
    }
192
193
6.19k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
194
6.19k
        full_encode_ascending(value, buf, /*schema_length=*/0);
195
6.19k
    }
196
197
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
198
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
199
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
200
0
                                                            sizeof(UnsignedCppType),
201
0
                                                            encoded_key->size));
202
0
        }
203
51
        UnsignedCppType unsigned_val;
204
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
205
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
206
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
207
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
208
51
        return Status::OK();
209
51
    }
210
};
211
212
template <>
213
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2> {
214
public:
215
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::CppType;
216
    using UnsignedCppType =
217
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::UnsignedCppType;
218
219
public:
220
    static void full_encode_ascending(const void* value, std::string* buf,
221
1.16M
                                      size_t /*schema_length*/) {
222
1.16M
        UnsignedCppType unsigned_val;
223
1.16M
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
224
        // make it bigendian
225
1.16M
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
226
1.16M
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
227
1.16M
    }
228
229
2.14k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
230
2.14k
        full_encode_ascending(value, buf, /*schema_length=*/0);
231
2.14k
    }
232
233
51
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
234
51
        if (encoded_key->size < sizeof(UnsignedCppType)) {
235
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
236
0
                                                            sizeof(UnsignedCppType),
237
0
                                                            encoded_key->size));
238
0
        }
239
51
        UnsignedCppType unsigned_val;
240
51
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
241
51
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
242
51
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
243
51
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
244
51
        return Status::OK();
245
51
    }
246
};
247
248
template <>
249
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ> {
250
public:
251
    using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ>::CppType;
252
    using UnsignedCppType =
253
            typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ>::UnsignedCppType;
254
255
public:
256
    static void full_encode_ascending(const void* value, std::string* buf,
257
13.5k
                                      size_t /*schema_length*/) {
258
13.5k
        UnsignedCppType unsigned_val;
259
13.5k
        memcpy(&unsigned_val, value, sizeof(unsigned_val));
260
        // make it bigendian
261
13.5k
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
262
13.5k
        buf->append((char*)&unsigned_val, sizeof(unsigned_val));
263
13.5k
    }
264
265
1.32k
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
266
1.32k
        full_encode_ascending(value, buf, /*schema_length=*/0);
267
1.32k
    }
268
269
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
270
0
        if (encoded_key->size < sizeof(UnsignedCppType)) {
271
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
272
0
                                                            sizeof(UnsignedCppType),
273
0
                                                            encoded_key->size));
274
0
        }
275
0
        UnsignedCppType unsigned_val;
276
0
        memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType));
277
0
        unsigned_val = to_endian<std::endian::big>(unsigned_val);
278
0
        memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType));
279
0
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
280
0
        return Status::OK();
281
0
    }
282
};
283
284
template <>
285
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL> {
286
public:
287
    static void full_encode_ascending(const void* value, std::string* buf,
288
369
                                      size_t /*schema_length*/) {
289
369
        decimal12_t decimal_val;
290
369
        memcpy(&decimal_val, value, sizeof(decimal12_t));
291
369
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::full_encode_ascending(
292
369
                &decimal_val.integer, buf, /*schema_length=*/0);
293
369
        KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::full_encode_ascending(
294
369
                &decimal_val.fraction, buf, /*schema_length=*/0);
295
369
    } // namespace doris
296
297
52
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
298
52
        full_encode_ascending(value, buf, /*schema_length=*/0);
299
52
    }
300
301
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
302
64
        decimal12_t decimal_val = {0, 0};
303
64
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_BIGINT>::decode_ascending(
304
64
                encoded_key, sizeof(decimal_val.integer), (uint8_t*)&decimal_val.integer));
305
64
        RETURN_IF_ERROR(KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_INT>::decode_ascending(
306
64
                encoded_key, sizeof(decimal_val.fraction), (uint8_t*)&decimal_val.fraction));
307
64
        memcpy(cell_ptr, &decimal_val, sizeof(decimal12_t));
308
64
        return Status::OK();
309
64
    }
310
};
311
312
template <>
313
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_CHAR> {
314
public:
315
    // Pad to the declared CHAR(N) length so the encoded key bytes match the
316
    // canonical fixed-width form, regardless of the slice's actual character
317
    // length. With OlapBlockDataConvertorChar no longer pre-padding CHAR,
318
    // slice->size is the real character length (≤ schema_length).
319
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf,
320
2.44k
                                                            size_t schema_length) {
321
2.44k
        const Slice* slice = reinterpret_cast<const Slice*>(value);
322
2.44k
        size_t copy_size = std::min(slice->size, schema_length);
323
2.44k
        buf->append(slice->data, copy_size);
324
2.44k
        if (copy_size < schema_length) {
325
1.72k
            buf->append(schema_length - copy_size, '\0');
326
1.72k
        }
327
2.44k
    }
328
329
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
330
1.18k
                                                       std::string* buf) {
331
1.18k
        const Slice* slice = (const Slice*)value;
332
1.18k
        size_t copy_size = std::min(index_size, slice->size);
333
1.18k
        buf->append(slice->data, copy_size);
334
1.18k
        if (copy_size < index_size) {
335
868
            buf->append(index_size - copy_size, '\0');
336
868
        }
337
1.18k
    }
338
339
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
340
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
341
0
    }
342
};
343
344
template <>
345
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_VARCHAR> {
346
public:
347
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf,
348
17.8M
                                                            size_t /*schema_length*/) {
349
17.8M
        auto slice = reinterpret_cast<const Slice*>(value);
350
17.8M
        buf->append(slice->get_data(), slice->get_size());
351
17.8M
    }
352
353
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
354
21.3k
                                                       std::string* buf) {
355
21.3k
        const Slice* slice = (const Slice*)value;
356
21.3k
        size_t copy_size = std::min(index_size, slice->size);
357
21.3k
        buf->append(slice->data, copy_size);
358
21.3k
    }
359
360
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
361
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
362
0
    }
363
};
364
365
template <>
366
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_STRING> {
367
public:
368
    NO_SANITIZE_UNDEFINED static void full_encode_ascending(const void* value, std::string* buf,
369
889
                                                            size_t /*schema_length*/) {
370
889
        auto slice = reinterpret_cast<const Slice*>(value);
371
889
        buf->append(slice->get_data(), slice->get_size());
372
889
    }
373
374
    NO_SANITIZE_UNDEFINED static void encode_ascending(const void* value, size_t index_size,
375
49
                                                       std::string* buf) {
376
49
        const Slice* slice = (const Slice*)value;
377
49
        size_t copy_size = std::min(index_size, slice->size);
378
49
        buf->append(slice->data, copy_size);
379
49
    }
380
381
0
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
382
0
        throw Exception(Status::FatalError("decode_ascending is not implemented"));
383
0
    }
384
};
385
386
template <FieldType field_type>
387
class KeyCoderTraitsForFloat {
388
public:
389
    using CppType = typename CppTypeTraits<field_type>::CppType;
390
    using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType;
391
392
636
    static UnsignedCppType encode_float(CppType value) {
393
636
        return sortable_float_bits(float_to_int_bits(value));
394
636
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE12encode_floatEf
Line
Count
Source
392
297
    static UnsignedCppType encode_float(CppType value) {
393
297
        return sortable_float_bits(float_to_int_bits(value));
394
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE12encode_floatEd
Line
Count
Source
392
339
    static UnsignedCppType encode_float(CppType value) {
393
339
        return sortable_float_bits(float_to_int_bits(value));
394
339
    }
395
396
128
    static CppType decode_float(UnsignedCppType sortable_bits) {
397
128
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
398
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE12decode_floatEj
Line
Count
Source
396
64
    static CppType decode_float(UnsignedCppType sortable_bits) {
397
64
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
398
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE12decode_floatEm
Line
Count
Source
396
64
    static CppType decode_float(UnsignedCppType sortable_bits) {
397
64
        return int_bits_to_float(unsortable_float_bits(sortable_bits));
398
64
    }
399
400
    // -infinity < -100.0 < -1.0 < -0.0 < 0.0 < 1.0 < 100.0 < infinity < NaN
401
    static void full_encode_ascending(const void* value, std::string* buf,
402
636
                                      size_t /*schema_length*/) {
403
636
        CppType val;
404
636
        std::memcpy(&val, value, sizeof(CppType));
405
636
        UnsignedCppType sortable_val = encode_float(val);
406
636
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
407
636
                                             << (sizeof(UnsignedCppType) * 8 - 1);
408
636
        sortable_val ^= sign_bit;
409
636
        sortable_val = to_endian<std::endian::big>(sortable_val);
410
636
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
411
636
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
402
297
                                      size_t /*schema_length*/) {
403
297
        CppType val;
404
297
        std::memcpy(&val, value, sizeof(CppType));
405
297
        UnsignedCppType sortable_val = encode_float(val);
406
297
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
407
297
                                             << (sizeof(UnsignedCppType) * 8 - 1);
408
297
        sortable_val ^= sign_bit;
409
297
        sortable_val = to_endian<std::endian::big>(sortable_val);
410
297
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
411
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
402
339
                                      size_t /*schema_length*/) {
403
339
        CppType val;
404
339
        std::memcpy(&val, value, sizeof(CppType));
405
339
        UnsignedCppType sortable_val = encode_float(val);
406
339
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
407
339
                                             << (sizeof(UnsignedCppType) * 8 - 1);
408
339
        sortable_val ^= sign_bit;
409
339
        sortable_val = to_endian<std::endian::big>(sortable_val);
410
339
        buf->append(reinterpret_cast<const char*>(&sortable_val), sizeof(UnsignedCppType));
411
339
    }
412
413
0
    static void encode_ascending(const void* value, size_t index_size, std::string* buf) {
414
0
        full_encode_ascending(value, buf, /*schema_length=*/0);
415
0
    }
Unexecuted instantiation: _ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
416
417
128
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
418
128
        if (encoded_key->size < sizeof(UnsignedCppType)) {
419
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
420
0
                                                            sizeof(UnsignedCppType),
421
0
                                                            encoded_key->size));
422
0
        }
423
128
        UnsignedCppType sortable_val;
424
128
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
425
128
        sortable_val = to_endian<std::endian::big>(sortable_val);
426
128
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
427
128
                                             << (sizeof(UnsignedCppType) * 8 - 1);
428
128
        sortable_val ^= sign_bit;
429
128
        CppType val = decode_float(sortable_val);
430
128
        std::memcpy(cell_ptr, &val, sizeof(CppType));
431
128
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
432
128
        return Status::OK();
433
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
417
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
418
64
        if (encoded_key->size < sizeof(UnsignedCppType)) {
419
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
420
0
                                                            sizeof(UnsignedCppType),
421
0
                                                            encoded_key->size));
422
0
        }
423
64
        UnsignedCppType sortable_val;
424
64
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
425
64
        sortable_val = to_endian<std::endian::big>(sortable_val);
426
64
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
427
64
                                             << (sizeof(UnsignedCppType) * 8 - 1);
428
64
        sortable_val ^= sign_bit;
429
64
        CppType val = decode_float(sortable_val);
430
64
        std::memcpy(cell_ptr, &val, sizeof(CppType));
431
64
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
432
64
        return Status::OK();
433
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE16decode_ascendingEPNS_5SliceEmPh
Line
Count
Source
417
64
    static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
418
64
        if (encoded_key->size < sizeof(UnsignedCppType)) {
419
0
            return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1",
420
0
                                                            sizeof(UnsignedCppType),
421
0
                                                            encoded_key->size));
422
0
        }
423
64
        UnsignedCppType sortable_val;
424
64
        std::memcpy(&sortable_val, encoded_key->data, sizeof(UnsignedCppType));
425
64
        sortable_val = to_endian<std::endian::big>(sortable_val);
426
64
        constexpr UnsignedCppType sign_bit = UnsignedCppType(1)
427
64
                                             << (sizeof(UnsignedCppType) * 8 - 1);
428
64
        sortable_val ^= sign_bit;
429
64
        CppType val = decode_float(sortable_val);
430
64
        std::memcpy(cell_ptr, &val, sizeof(CppType));
431
64
        encoded_key->remove_prefix(sizeof(UnsignedCppType));
432
64
        return Status::OK();
433
64
    }
434
435
private:
436
636
    static UnsignedCppType float_to_int_bits(CppType value) {
437
636
        if (std::isnan(value)) {
438
49
            if constexpr (std::is_same_v<CppType, float>) {
439
24
                return 0x7FC00000U;
440
25
            } else {
441
25
                return 0x7FF8000000000000ULL;
442
25
            }
443
49
        }
444
445
0
        UnsignedCppType result;
446
636
        std::memcpy(&result, &value, sizeof(CppType));
447
636
        return result;
448
636
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE17float_to_int_bitsEf
Line
Count
Source
436
297
    static UnsignedCppType float_to_int_bits(CppType value) {
437
297
        if (std::isnan(value)) {
438
24
            if constexpr (std::is_same_v<CppType, float>) {
439
24
                return 0x7FC00000U;
440
            } else {
441
                return 0x7FF8000000000000ULL;
442
            }
443
24
        }
444
445
0
        UnsignedCppType result;
446
297
        std::memcpy(&result, &value, sizeof(CppType));
447
297
        return result;
448
297
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE17float_to_int_bitsEd
Line
Count
Source
436
339
    static UnsignedCppType float_to_int_bits(CppType value) {
437
339
        if (std::isnan(value)) {
438
            if constexpr (std::is_same_v<CppType, float>) {
439
                return 0x7FC00000U;
440
25
            } else {
441
25
                return 0x7FF8000000000000ULL;
442
25
            }
443
25
        }
444
445
0
        UnsignedCppType result;
446
339
        std::memcpy(&result, &value, sizeof(CppType));
447
339
        return result;
448
339
    }
449
450
764
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
451
764
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
452
764
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
453
764
        if ((bits & sign_bit) != 0) {
454
212
            return bits ^ (sign_bit - 1);
455
552
        } else {
456
552
            return bits;
457
552
        }
458
764
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE19sortable_float_bitsEj
Line
Count
Source
450
361
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
451
361
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
452
361
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
453
361
        if ((bits & sign_bit) != 0) {
454
106
            return bits ^ (sign_bit - 1);
455
255
        } else {
456
255
            return bits;
457
255
        }
458
361
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE19sortable_float_bitsEm
Line
Count
Source
450
403
    static UnsignedCppType sortable_float_bits(UnsignedCppType bits) {
451
403
        constexpr int32_t shift = sizeof(UnsignedCppType) * 8 - 1;
452
403
        constexpr UnsignedCppType sign_bit = static_cast<UnsignedCppType>(1) << shift;
453
403
        if ((bits & sign_bit) != 0) {
454
106
            return bits ^ (sign_bit - 1);
455
297
        } else {
456
297
            return bits;
457
297
        }
458
403
    }
459
460
128
    static CppType int_bits_to_float(UnsignedCppType bits) {
461
128
        CppType result;
462
128
        std::memcpy(&result, &bits, sizeof(CppType));
463
128
        return result;
464
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE17int_bits_to_floatEj
Line
Count
Source
460
64
    static CppType int_bits_to_float(UnsignedCppType bits) {
461
64
        CppType result;
462
64
        std::memcpy(&result, &bits, sizeof(CppType));
463
64
        return result;
464
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE17int_bits_to_floatEm
Line
Count
Source
460
64
    static CppType int_bits_to_float(UnsignedCppType bits) {
461
64
        CppType result;
462
64
        std::memcpy(&result, &bits, sizeof(CppType));
463
64
        return result;
464
64
    }
465
466
128
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
467
128
        return sortable_float_bits(sortable_bits);
468
128
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE10EE21unsortable_float_bitsEj
Line
Count
Source
466
64
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
467
64
        return sortable_float_bits(sortable_bits);
468
64
    }
_ZN5doris22KeyCoderTraitsForFloatILNS_9FieldTypeE11EE21unsortable_float_bitsEm
Line
Count
Source
466
64
    static UnsignedCppType unsortable_float_bits(UnsignedCppType sortable_bits) {
467
64
        return sortable_float_bits(sortable_bits);
468
64
    }
469
};
470
471
template <>
472
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_FLOAT>
473
        : public KeyCoderTraitsForFloat<FieldType::OLAP_FIELD_TYPE_FLOAT> {};
474
475
template <>
476
class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DOUBLE>
477
        : public KeyCoderTraitsForFloat<FieldType::OLAP_FIELD_TYPE_DOUBLE> {};
478
479
// X-macro listing every (FieldType, PrimitiveType) pair that goes through KeyCoder
480
// as a non-string scalar key. Strings are handled separately because they need
481
// length / padding logic outside KeyCoder. Each entry: M(FT_suffix, PT_suffix).
482
#define DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(M) \
483
2.85k
    M(OLAP_FIELD_TYPE_BOOL, TYPE_BOOLEAN)                 \
484
151k
    M(OLAP_FIELD_TYPE_TINYINT, TYPE_TINYINT)              \
485
151k
    M(OLAP_FIELD_TYPE_SMALLINT, TYPE_SMALLINT)            \
486
576k
    M(OLAP_FIELD_TYPE_INT, TYPE_INT)                      \
487
576k
    M(OLAP_FIELD_TYPE_BIGINT, TYPE_BIGINT)                \
488
30.9k
    M(OLAP_FIELD_TYPE_LARGEINT, TYPE_LARGEINT)            \
489
13.4k
    M(OLAP_FIELD_TYPE_FLOAT, TYPE_FLOAT)                  \
490
23
    M(OLAP_FIELD_TYPE_DOUBLE, TYPE_DOUBLE)                \
491
137
    M(OLAP_FIELD_TYPE_DECIMAL, TYPE_DECIMALV2)            \
492
444
    M(OLAP_FIELD_TYPE_DECIMAL32, TYPE_DECIMAL32)          \
493
444
    M(OLAP_FIELD_TYPE_DECIMAL64, TYPE_DECIMAL64)          \
494
1.34k
    M(OLAP_FIELD_TYPE_DECIMAL128I, TYPE_DECIMAL128I)      \
495
1.34k
    M(OLAP_FIELD_TYPE_DECIMAL256, TYPE_DECIMAL256)        \
496
16.5k
    M(OLAP_FIELD_TYPE_DATE, TYPE_DATE)                    \
497
16.5k
    M(OLAP_FIELD_TYPE_DATETIME, TYPE_DATETIME)            \
498
308k
    M(OLAP_FIELD_TYPE_DATEV2, TYPE_DATEV2)                \
499
308k
    M(OLAP_FIELD_TYPE_DATETIMEV2, TYPE_DATETIMEV2)        \
500
7.96k
    M(OLAP_FIELD_TYPE_TIMESTAMPTZ, TYPE_TIMESTAMPTZ)      \
501
7.96k
    M(OLAP_FIELD_TYPE_IPV4, TYPE_IPV4)                    \
502
267
    M(OLAP_FIELD_TYPE_IPV6, TYPE_IPV6)
503
504
// True for exactly the PrimitiveTypes listed in
505
// DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES. Strings (CHAR/VARCHAR/STRING/
506
// VARBINARY) have their own short-key code path in row_cursor.cpp that calls
507
// storage_field->full_encode_ascending directly, and nested/aggregate types
508
// (ARRAY/MAP/STRUCT/VARIANT/HLL/BITMAP/JSONB/QUANTILE_STATE/AGG_STATE) are not
509
// key-encodable at all -- both groups must never reach the helpers below.
510
0
constexpr bool is_key_encodable_non_string_type(PrimitiveType pt) {
511
0
    switch (pt) {
512
0
#define DORIS_KEY_ENCODABLE_CASE(FT, PT) \
513
0
    case PrimitiveType::PT:              \
514
0
        return true;
515
0
        DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(DORIS_KEY_ENCODABLE_CASE)
516
0
#undef DORIS_KEY_ENCODABLE_CASE
517
0
    default:
518
0
        return false;
519
0
    }
520
0
}
521
522
// Convert a Field value to its storage representation (via PrimitiveTypeConvertor)
523
// and full-encode it as a byte-comparable ascending key via KeyCoder.
524
template <PrimitiveType PT>
525
1.12M
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
1.12M
    static_assert(is_key_encodable_non_string_type(PT),
527
1.12M
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
1.12M
                  "strings have their own path in RowCursor that calls "
529
1.12M
                  "storage_field->full_encode_ascending directly, and nested / "
530
1.12M
                  "aggregate types are not key-encodable");
531
1.12M
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
1.12M
    coder->full_encode_ascending(&v, buf);
533
1.12M
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE2EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
2.85k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
2.85k
    static_assert(is_key_encodable_non_string_type(PT),
527
2.85k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
2.85k
                  "strings have their own path in RowCursor that calls "
529
2.85k
                  "storage_field->full_encode_ascending directly, and nested / "
530
2.85k
                  "aggregate types are not key-encodable");
531
2.85k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
2.85k
    coder->full_encode_ascending(&v, buf);
533
2.85k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE3EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
151k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
151k
    static_assert(is_key_encodable_non_string_type(PT),
527
151k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
151k
                  "strings have their own path in RowCursor that calls "
529
151k
                  "storage_field->full_encode_ascending directly, and nested / "
530
151k
                  "aggregate types are not key-encodable");
531
151k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
151k
    coder->full_encode_ascending(&v, buf);
533
151k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE4EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
10.4k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
10.4k
    static_assert(is_key_encodable_non_string_type(PT),
527
10.4k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
10.4k
                  "strings have their own path in RowCursor that calls "
529
10.4k
                  "storage_field->full_encode_ascending directly, and nested / "
530
10.4k
                  "aggregate types are not key-encodable");
531
10.4k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
10.4k
    coder->full_encode_ascending(&v, buf);
533
10.4k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE5EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
575k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
575k
    static_assert(is_key_encodable_non_string_type(PT),
527
575k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
575k
                  "strings have their own path in RowCursor that calls "
529
575k
                  "storage_field->full_encode_ascending directly, and nested / "
530
575k
                  "aggregate types are not key-encodable");
531
575k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
575k
    coder->full_encode_ascending(&v, buf);
533
575k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE6EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
30.9k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
30.9k
    static_assert(is_key_encodable_non_string_type(PT),
527
30.9k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
30.9k
                  "strings have their own path in RowCursor that calls "
529
30.9k
                  "storage_field->full_encode_ascending directly, and nested / "
530
30.9k
                  "aggregate types are not key-encodable");
531
30.9k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
30.9k
    coder->full_encode_ascending(&v, buf);
533
30.9k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE7EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
13.4k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
13.4k
    static_assert(is_key_encodable_non_string_type(PT),
527
13.4k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
13.4k
                  "strings have their own path in RowCursor that calls "
529
13.4k
                  "storage_field->full_encode_ascending directly, and nested / "
530
13.4k
                  "aggregate types are not key-encodable");
531
13.4k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
13.4k
    coder->full_encode_ascending(&v, buf);
533
13.4k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE8EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
28
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
28
    static_assert(is_key_encodable_non_string_type(PT),
527
28
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
28
                  "strings have their own path in RowCursor that calls "
529
28
                  "storage_field->full_encode_ascending directly, and nested / "
530
28
                  "aggregate types are not key-encodable");
531
28
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
28
    coder->full_encode_ascending(&v, buf);
533
28
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE9EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
23
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
23
    static_assert(is_key_encodable_non_string_type(PT),
527
23
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
23
                  "strings have their own path in RowCursor that calls "
529
23
                  "storage_field->full_encode_ascending directly, and nested / "
530
23
                  "aggregate types are not key-encodable");
531
23
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
23
    coder->full_encode_ascending(&v, buf);
533
23
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE20EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
140
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
140
    static_assert(is_key_encodable_non_string_type(PT),
527
140
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
140
                  "strings have their own path in RowCursor that calls "
529
140
                  "storage_field->full_encode_ascending directly, and nested / "
530
140
                  "aggregate types are not key-encodable");
531
140
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
140
    coder->full_encode_ascending(&v, buf);
533
140
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE28EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
459
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
459
    static_assert(is_key_encodable_non_string_type(PT),
527
459
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
459
                  "strings have their own path in RowCursor that calls "
529
459
                  "storage_field->full_encode_ascending directly, and nested / "
530
459
                  "aggregate types are not key-encodable");
531
459
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
459
    coder->full_encode_ascending(&v, buf);
533
459
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE29EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
395
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
395
    static_assert(is_key_encodable_non_string_type(PT),
527
395
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
395
                  "strings have their own path in RowCursor that calls "
529
395
                  "storage_field->full_encode_ascending directly, and nested / "
530
395
                  "aggregate types are not key-encodable");
531
395
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
395
    coder->full_encode_ascending(&v, buf);
533
395
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE30EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
1.35k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
1.35k
    static_assert(is_key_encodable_non_string_type(PT),
527
1.35k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
1.35k
                  "strings have their own path in RowCursor that calls "
529
1.35k
                  "storage_field->full_encode_ascending directly, and nested / "
530
1.35k
                  "aggregate types are not key-encodable");
531
1.35k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
1.35k
    coder->full_encode_ascending(&v, buf);
533
1.35k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE35EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
779
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
779
    static_assert(is_key_encodable_non_string_type(PT),
527
779
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
779
                  "strings have their own path in RowCursor that calls "
529
779
                  "storage_field->full_encode_ascending directly, and nested / "
530
779
                  "aggregate types are not key-encodable");
531
779
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
779
    coder->full_encode_ascending(&v, buf);
533
779
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE11EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
16.5k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
16.5k
    static_assert(is_key_encodable_non_string_type(PT),
527
16.5k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
16.5k
                  "strings have their own path in RowCursor that calls "
529
16.5k
                  "storage_field->full_encode_ascending directly, and nested / "
530
16.5k
                  "aggregate types are not key-encodable");
531
16.5k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
16.5k
    coder->full_encode_ascending(&v, buf);
533
16.5k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE12EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
406
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
406
    static_assert(is_key_encodable_non_string_type(PT),
527
406
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
406
                  "strings have their own path in RowCursor that calls "
529
406
                  "storage_field->full_encode_ascending directly, and nested / "
530
406
                  "aggregate types are not key-encodable");
531
406
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
406
    coder->full_encode_ascending(&v, buf);
533
406
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE25EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
308k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
308k
    static_assert(is_key_encodable_non_string_type(PT),
527
308k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
308k
                  "strings have their own path in RowCursor that calls "
529
308k
                  "storage_field->full_encode_ascending directly, and nested / "
530
308k
                  "aggregate types are not key-encodable");
531
308k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
308k
    coder->full_encode_ascending(&v, buf);
533
308k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE26EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
7.37k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
7.37k
    static_assert(is_key_encodable_non_string_type(PT),
527
7.37k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
7.37k
                  "strings have their own path in RowCursor that calls "
529
7.37k
                  "storage_field->full_encode_ascending directly, and nested / "
530
7.37k
                  "aggregate types are not key-encodable");
531
7.37k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
7.37k
    coder->full_encode_ascending(&v, buf);
533
7.37k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE42EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
7.95k
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
7.95k
    static_assert(is_key_encodable_non_string_type(PT),
527
7.95k
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
7.95k
                  "strings have their own path in RowCursor that calls "
529
7.95k
                  "storage_field->full_encode_ascending directly, and nested / "
530
7.95k
                  "aggregate types are not key-encodable");
531
7.95k
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
7.95k
    coder->full_encode_ascending(&v, buf);
533
7.95k
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE36EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
258
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
258
    static_assert(is_key_encodable_non_string_type(PT),
527
258
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
258
                  "strings have their own path in RowCursor that calls "
529
258
                  "storage_field->full_encode_ascending directly, and nested / "
530
258
                  "aggregate types are not key-encodable");
531
258
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
258
    coder->full_encode_ascending(&v, buf);
533
258
}
_ZN5doris24full_encode_field_as_keyILNS_13PrimitiveTypeE37EEEvRKNS_5FieldEPKNS_8KeyCoderEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
525
165
inline void full_encode_field_as_key(const Field& f, const KeyCoder* coder, std::string* buf) {
526
165
    static_assert(is_key_encodable_non_string_type(PT),
527
165
                  "full_encode_field_as_key is for non-string scalar keys only; "
528
165
                  "strings have their own path in RowCursor that calls "
529
165
                  "storage_field->full_encode_ascending directly, and nested / "
530
165
                  "aggregate types are not key-encodable");
531
165
    auto v = PrimitiveTypeConvertor<PT>::to_storage_field_type(f.get<PT>());
532
165
    coder->full_encode_ascending(&v, buf);
533
165
}
534
535
} // namespace doris