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