/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 "absl/strings/substitute.h" |
31 | | #include "common/status.h" |
32 | | #include "gutil/endian.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 FullEncodeAscendingFunc = void (*)(const void* value, std::string* buf); |
42 | | using EncodeAscendingFunc = void (*)(const void* value, size_t index_size, std::string* buf); |
43 | | using DecodeAscendingFunc = Status (*)(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr); |
44 | | |
45 | | // Order-preserving binary encoding for values of a particular type so that |
46 | | // those values can be compared by memcpy their encoded bytes. |
47 | | // |
48 | | // To obtain instance of this class, use the `get_key_coder(FieldType)` method. |
49 | | class KeyCoder { |
50 | | public: |
51 | | template <typename TraitsType> |
52 | | KeyCoder(TraitsType traits); |
53 | | |
54 | | // encode the provided `value` into `buf`. |
55 | 948k | void full_encode_ascending(const void* value, std::string* buf) const { |
56 | 948k | _full_encode_ascending(value, buf); |
57 | 948k | } |
58 | | |
59 | | // similar to `full_encode_ascending`, but only encode part (the first `index_size` bytes) of the value. |
60 | | // only applicable to string type |
61 | 11.8k | void encode_ascending(const void* value, size_t index_size, std::string* buf) const { |
62 | 11.8k | _encode_ascending(value, index_size, buf); |
63 | 11.8k | } |
64 | | |
65 | | // Only used for test, should delete it in the future |
66 | 19 | Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) const { |
67 | 19 | return _decode_ascending(encoded_key, index_size, cell_ptr); |
68 | 19 | } |
69 | | |
70 | | private: |
71 | | FullEncodeAscendingFunc _full_encode_ascending; |
72 | | EncodeAscendingFunc _encode_ascending; |
73 | | DecodeAscendingFunc _decode_ascending; |
74 | | }; |
75 | | |
76 | | extern const KeyCoder* get_key_coder(FieldType type); |
77 | | |
78 | | template <FieldType field_type, typename Enable = void> |
79 | | class KeyCoderTraits {}; |
80 | | |
81 | | template <FieldType field_type> |
82 | | class KeyCoderTraits< |
83 | | field_type, |
84 | | typename std::enable_if< |
85 | | std::is_integral<typename CppTypeTraits<field_type>::CppType>::value || |
86 | | field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256 || |
87 | | vectorized::IsDecimalNumber<typename CppTypeTraits<field_type>::CppType>>::type> { |
88 | | public: |
89 | | using CppType = typename CppTypeTraits<field_type>::CppType; |
90 | | using UnsignedCppType = typename CppTypeTraits<field_type>::UnsignedCppType; |
91 | | |
92 | | private: |
93 | | // Swap value's endian from/to big endian |
94 | 1.01M | static UnsignedCppType swap_big_endian(UnsignedCppType val) { |
95 | 1.01M | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { |
96 | 1.01M | return BigEndian::FromHost256(val); |
97 | 1.01M | } else { |
98 | 1.01M | switch (sizeof(UnsignedCppType)) { |
99 | 233 | case 1: |
100 | 233 | return val; |
101 | 242 | case 2: |
102 | 242 | return BigEndian::FromHost16(val); |
103 | 958k | case 4: |
104 | 958k | return BigEndian::FromHost32(val); |
105 | 60.3k | case 8: |
106 | 60.3k | return BigEndian::FromHost64(val); |
107 | 207 | case 16: |
108 | 207 | return BigEndian::FromHost128(val); |
109 | 0 | default: |
110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", |
111 | 0 | int(field_type), sizeof(UnsignedCppType))); |
112 | 1.01M | } |
113 | 1.01M | } |
114 | 1.01M | } _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE15swap_big_endianEm Line | Count | Source | 94 | 216 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 216 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 216 | return BigEndian::FromHost256(val); | 97 | 216 | } else { | 98 | 216 | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 216 | case 8: | 106 | 216 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 216 | } | 113 | 216 | } | 114 | 216 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE15swap_big_endianEj Line | Count | Source | 94 | 957k | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 957k | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 957k | return BigEndian::FromHost256(val); | 97 | 957k | } else { | 98 | 957k | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 957k | case 4: | 104 | 957k | return BigEndian::FromHost32(val); | 105 | 0 | case 8: | 106 | 0 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 957k | } | 113 | 957k | } | 114 | 957k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE15swap_big_endianEh Line | Count | Source | 94 | 233 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 233 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 233 | return BigEndian::FromHost256(val); | 97 | 233 | } else { | 98 | 233 | switch (sizeof(UnsignedCppType)) { | 99 | 233 | case 1: | 100 | 233 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 0 | case 8: | 106 | 0 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 233 | } | 113 | 233 | } | 114 | 233 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE15swap_big_endianEt Line | Count | Source | 94 | 242 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 242 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 242 | return BigEndian::FromHost256(val); | 97 | 242 | } else { | 98 | 242 | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 242 | case 2: | 102 | 242 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 0 | case 8: | 106 | 0 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 242 | } | 113 | 242 | } | 114 | 242 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE15swap_big_endianEj Line | Count | Source | 94 | 208 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 208 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 208 | return BigEndian::FromHost256(val); | 97 | 208 | } else { | 98 | 208 | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 208 | case 4: | 104 | 208 | return BigEndian::FromHost32(val); | 105 | 0 | case 8: | 106 | 0 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 208 | } | 113 | 208 | } | 114 | 208 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE15swap_big_endianEm Line | Count | Source | 94 | 59.8k | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 59.8k | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 59.8k | return BigEndian::FromHost256(val); | 97 | 59.8k | } else { | 98 | 59.8k | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 59.8k | case 8: | 106 | 59.8k | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 59.8k | } | 113 | 59.8k | } | 114 | 59.8k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE15swap_big_endianEo Line | Count | Source | 94 | 207 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 207 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 207 | return BigEndian::FromHost256(val); | 97 | 207 | } else { | 98 | 207 | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 0 | case 8: | 106 | 0 | return BigEndian::FromHost64(val); | 107 | 207 | case 16: | 108 | 207 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 207 | } | 113 | 207 | } | 114 | 207 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE15swap_big_endianEm Line | Count | Source | 94 | 210 | static UnsignedCppType swap_big_endian(UnsignedCppType val) { | 95 | 210 | if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) { | 96 | 210 | return BigEndian::FromHost256(val); | 97 | 210 | } else { | 98 | 210 | switch (sizeof(UnsignedCppType)) { | 99 | 0 | case 1: | 100 | 0 | return val; | 101 | 0 | case 2: | 102 | 0 | return BigEndian::FromHost16(val); | 103 | 0 | case 4: | 104 | 0 | return BigEndian::FromHost32(val); | 105 | 210 | case 8: | 106 | 210 | return BigEndian::FromHost64(val); | 107 | 0 | case 16: | 108 | 0 | return BigEndian::FromHost128(val); | 109 | 0 | default: | 110 | 0 | throw Exception(Status::FatalError("Invalid type to big endian, type={}, size={}", | 111 | 0 | int(field_type), sizeof(UnsignedCppType))); | 112 | 210 | } | 113 | 210 | } | 114 | 210 | } |
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 |
115 | | |
116 | | public: |
117 | 1.00M | static void full_encode_ascending(const void* value, std::string* buf) { |
118 | 1.00M | UnsignedCppType unsigned_val; |
119 | 1.00M | memcpy(&unsigned_val, value, sizeof(unsigned_val)); |
120 | | // swap MSB to encode integer |
121 | 1.00M | if (std::is_signed<CppType>::value) { |
122 | 958k | unsigned_val ^= |
123 | 958k | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); |
124 | 958k | } |
125 | | // make it bigendian |
126 | 1.00M | unsigned_val = swap_big_endian(unsigned_val); |
127 | | |
128 | 1.00M | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); |
129 | 1.00M | } _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 213 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 213 | UnsignedCppType unsigned_val; | 119 | 213 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 213 | if (std::is_signed<CppType>::value) { | 122 | 213 | unsigned_val ^= | 123 | 213 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 213 | } | 125 | | // make it bigendian | 126 | 213 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 213 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 213 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 957k | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 957k | UnsignedCppType unsigned_val; | 119 | 957k | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 957k | if (std::is_signed<CppType>::value) { | 122 | 957k | unsigned_val ^= | 123 | 957k | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 957k | } | 125 | | // make it bigendian | 126 | 957k | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 957k | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 957k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 231 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 231 | UnsignedCppType unsigned_val; | 119 | 231 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 231 | if (std::is_signed<CppType>::value) { | 122 | 231 | unsigned_val ^= | 123 | 231 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 231 | } | 125 | | // make it bigendian | 126 | 231 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 231 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 231 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 240 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 240 | UnsignedCppType unsigned_val; | 119 | 240 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 240 | if (std::is_signed<CppType>::value) { | 122 | 240 | unsigned_val ^= | 123 | 240 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 240 | } | 125 | | // make it bigendian | 126 | 240 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 240 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 240 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 206 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 206 | UnsignedCppType unsigned_val; | 119 | 206 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 206 | if (std::is_signed<CppType>::value) { | 122 | 0 | unsigned_val ^= | 123 | 0 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 0 | } | 125 | | // make it bigendian | 126 | 206 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 206 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 206 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 42.7k | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 42.7k | UnsignedCppType unsigned_val; | 119 | 42.7k | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 42.7k | if (std::is_signed<CppType>::value) { | 122 | 0 | unsigned_val ^= | 123 | 0 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 0 | } | 125 | | // make it bigendian | 126 | 42.7k | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 42.7k | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 42.7k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 205 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 205 | UnsignedCppType unsigned_val; | 119 | 205 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 205 | if (std::is_signed<CppType>::value) { | 122 | 205 | unsigned_val ^= | 123 | 205 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 205 | } | 125 | | // make it bigendian | 126 | 205 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 205 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 205 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE21full_encode_ascendingEPKvPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 117 | 208 | static void full_encode_ascending(const void* value, std::string* buf) { | 118 | 208 | UnsignedCppType unsigned_val; | 119 | 208 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); | 120 | | // swap MSB to encode integer | 121 | 208 | if (std::is_signed<CppType>::value) { | 122 | 208 | unsigned_val ^= | 123 | 208 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 124 | 208 | } | 125 | | // make it bigendian | 126 | 208 | unsigned_val = swap_big_endian(unsigned_val); | 127 | | | 128 | 208 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); | 129 | 208 | } |
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 |
130 | | |
131 | 11.6k | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
132 | 11.6k | full_encode_ascending(value, buf); |
133 | 11.6k | } _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 209 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 209 | full_encode_ascending(value, buf); | 133 | 209 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 212 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 212 | full_encode_ascending(value, buf); | 133 | 212 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 10.2k | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 10.2k | full_encode_ascending(value, buf); | 133 | 10.2k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 202 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 202 | full_encode_ascending(value, buf); | 133 | 202 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 203 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 203 | full_encode_ascending(value, buf); | 133 | 203 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 202 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 202 | full_encode_ascending(value, buf); | 133 | 202 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 203 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 203 | full_encode_ascending(value, buf); | 133 | 203 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16encode_ascendingEPKvmPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 131 | 202 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { | 132 | 202 | full_encode_ascending(value, buf); | 133 | 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 |
134 | | |
135 | 17.1k | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. |
137 | | // currently, we reduce the usage of this method. |
138 | 17.1k | if (encoded_key->size < sizeof(UnsignedCppType)) { |
139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", |
140 | 0 | sizeof(UnsignedCppType), encoded_key->size); |
141 | 0 | } |
142 | 17.1k | UnsignedCppType unsigned_val; |
143 | 17.1k | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); |
144 | 17.1k | unsigned_val = swap_big_endian(unsigned_val); |
145 | 17.1k | if (std::is_signed<CppType>::value) { |
146 | 14 | unsigned_val ^= |
147 | 14 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); |
148 | 14 | } |
149 | 17.1k | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); |
150 | 17.1k | encoded_key->remove_prefix(sizeof(UnsignedCppType)); |
151 | 17.1k | return Status::OK(); |
152 | 17.1k | } _ZN5doris14KeyCoderTraitsILNS_9FieldTypeE7EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 3 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 3 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 3 | UnsignedCppType unsigned_val; | 143 | 3 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 3 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 3 | if (std::is_signed<CppType>::value) { | 146 | 3 | unsigned_val ^= | 147 | 3 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 3 | } | 149 | 3 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 3 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 3 | return Status::OK(); | 152 | 3 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE5EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 3 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 3 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 3 | UnsignedCppType unsigned_val; | 143 | 3 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 3 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 3 | if (std::is_signed<CppType>::value) { | 146 | 3 | unsigned_val ^= | 147 | 3 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 3 | } | 149 | 3 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 3 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 3 | return Status::OK(); | 152 | 3 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE1EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 2 | UnsignedCppType unsigned_val; | 143 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 2 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 2 | if (std::is_signed<CppType>::value) { | 146 | 2 | unsigned_val ^= | 147 | 2 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 2 | } | 149 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 2 | return Status::OK(); | 152 | 2 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE3EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 2 | UnsignedCppType unsigned_val; | 143 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 2 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 2 | if (std::is_signed<CppType>::value) { | 146 | 2 | unsigned_val ^= | 147 | 2 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 2 | } | 149 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 2 | return Status::OK(); | 152 | 2 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE6EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 2 | UnsignedCppType unsigned_val; | 143 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 2 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 2 | if (std::is_signed<CppType>::value) { | 146 | 0 | unsigned_val ^= | 147 | 0 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 0 | } | 149 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 2 | return Status::OK(); | 152 | 2 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE8EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 17.1k | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 17.1k | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 17.1k | UnsignedCppType unsigned_val; | 143 | 17.1k | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 17.1k | unsigned_val = swap_big_endian(unsigned_val); | 145 | 17.1k | if (std::is_signed<CppType>::value) { | 146 | 0 | unsigned_val ^= | 147 | 0 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 0 | } | 149 | 17.1k | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 17.1k | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 17.1k | return Status::OK(); | 152 | 17.1k | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE9EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 2 | UnsignedCppType unsigned_val; | 143 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 2 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 2 | if (std::is_signed<CppType>::value) { | 146 | 2 | unsigned_val ^= | 147 | 2 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 2 | } | 149 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 2 | return Status::OK(); | 152 | 2 | } |
_ZN5doris14KeyCoderTraitsILNS_9FieldTypeE15EvE16decode_ascendingEPNS_5SliceEmPh Line | Count | Source | 135 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { | 136 | | // decode_ascending only used in orinal index page, maybe should remove it in the future. | 137 | | // currently, we reduce the usage of this method. | 138 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { | 139 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", | 140 | 0 | sizeof(UnsignedCppType), encoded_key->size); | 141 | 0 | } | 142 | 2 | UnsignedCppType unsigned_val; | 143 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); | 144 | 2 | unsigned_val = swap_big_endian(unsigned_val); | 145 | 2 | if (std::is_signed<CppType>::value) { | 146 | 2 | unsigned_val ^= | 147 | 2 | (static_cast<UnsignedCppType>(1) << (sizeof(UnsignedCppType) * CHAR_BIT - 1)); | 148 | 2 | } | 149 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); | 150 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); | 151 | 2 | return Status::OK(); | 152 | 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 |
153 | | }; |
154 | | |
155 | | template <> |
156 | | class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATE> { |
157 | | public: |
158 | | using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::CppType; |
159 | | using UnsignedCppType = |
160 | | typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>::UnsignedCppType; |
161 | | |
162 | | public: |
163 | 209 | static void full_encode_ascending(const void* value, std::string* buf) { |
164 | 209 | UnsignedCppType unsigned_val; |
165 | 209 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); |
166 | | // make it bigendian |
167 | 209 | unsigned_val = BigEndian::FromHost24(unsigned_val); |
168 | 209 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); |
169 | 209 | } |
170 | | |
171 | 203 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
172 | 203 | full_encode_ascending(value, buf); |
173 | 203 | } |
174 | | |
175 | 2 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
176 | 2 | if (encoded_key->size < sizeof(UnsignedCppType)) { |
177 | 0 | return Status::InvalidArgument("Key too short, need={} vs real={}", |
178 | 0 | sizeof(UnsignedCppType), encoded_key->size); |
179 | 0 | } |
180 | 2 | UnsignedCppType unsigned_val; |
181 | 2 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); |
182 | 2 | unsigned_val = BigEndian::FromHost24(unsigned_val); |
183 | 2 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); |
184 | 2 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); |
185 | 2 | return Status::OK(); |
186 | 2 | } |
187 | | }; |
188 | | |
189 | | template <> |
190 | | class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATEV2> { |
191 | | public: |
192 | | using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::CppType; |
193 | | using UnsignedCppType = |
194 | | typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATEV2>::UnsignedCppType; |
195 | | |
196 | | public: |
197 | 2 | static void full_encode_ascending(const void* value, std::string* buf) { |
198 | 2 | UnsignedCppType unsigned_val; |
199 | 2 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); |
200 | | // make it bigendian |
201 | 2 | unsigned_val = BigEndian::FromHost32(unsigned_val); |
202 | 2 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); |
203 | 2 | } |
204 | | |
205 | 0 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
206 | 0 | full_encode_ascending(value, buf); |
207 | 0 | } |
208 | | |
209 | 0 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
210 | 0 | if (encoded_key->size < sizeof(UnsignedCppType)) { |
211 | 0 | return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1", |
212 | 0 | sizeof(UnsignedCppType), |
213 | 0 | encoded_key->size)); |
214 | 0 | } |
215 | 0 | UnsignedCppType unsigned_val; |
216 | 0 | memcpy(&unsigned_val, encoded_key->data, sizeof(UnsignedCppType)); |
217 | 0 | unsigned_val = BigEndian::FromHost32(unsigned_val); |
218 | 0 | memcpy(cell_ptr, &unsigned_val, sizeof(UnsignedCppType)); |
219 | 0 | encoded_key->remove_prefix(sizeof(UnsignedCppType)); |
220 | 0 | return Status::OK(); |
221 | 0 | } |
222 | | }; |
223 | | |
224 | | template <> |
225 | | class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2> { |
226 | | public: |
227 | | using CppType = typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::CppType; |
228 | | using UnsignedCppType = |
229 | | typename CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>::UnsignedCppType; |
230 | | |
231 | | public: |
232 | 0 | static void full_encode_ascending(const void* value, std::string* buf) { |
233 | 0 | UnsignedCppType unsigned_val; |
234 | 0 | memcpy(&unsigned_val, value, sizeof(unsigned_val)); |
235 | | // make it bigendian |
236 | 0 | unsigned_val = BigEndian::FromHost64(unsigned_val); |
237 | 0 | buf->append((char*)&unsigned_val, sizeof(unsigned_val)); |
238 | 0 | } |
239 | | |
240 | 0 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
241 | 0 | full_encode_ascending(value, buf); |
242 | 0 | } |
243 | | |
244 | 0 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
245 | 0 | if (encoded_key->size < sizeof(UnsignedCppType)) { |
246 | 0 | return Status::InvalidArgument(absl::Substitute("Key too short, need=$0 vs real=$1", |
247 | 0 | sizeof(UnsignedCppType), |
248 | 0 | 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 | throw Exception(Status::FatalError("decode_ascending is not implemented")); |
304 | 0 | } |
305 | | }; |
306 | | |
307 | | template <> |
308 | | class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_VARCHAR> { |
309 | | public: |
310 | 211 | static void full_encode_ascending(const void* value, std::string* buf) { |
311 | 211 | auto slice = reinterpret_cast<const Slice*>(value); |
312 | 211 | buf->append(slice->get_data(), slice->get_size()); |
313 | 211 | } |
314 | | |
315 | 2 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
316 | 2 | const Slice* slice = (const Slice*)value; |
317 | 2 | size_t copy_size = std::min(index_size, slice->size); |
318 | 2 | buf->append(slice->data, copy_size); |
319 | 2 | } |
320 | | |
321 | 0 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
322 | 0 | throw Exception(Status::FatalError("decode_ascending is not implemented")); |
323 | 0 | } |
324 | | }; |
325 | | |
326 | | template <> |
327 | | class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_STRING> { |
328 | | public: |
329 | 884 | static void full_encode_ascending(const void* value, std::string* buf) { |
330 | 884 | auto slice = reinterpret_cast<const Slice*>(value); |
331 | 884 | buf->append(slice->get_data(), slice->get_size()); |
332 | 884 | } |
333 | | |
334 | 0 | static void encode_ascending(const void* value, size_t index_size, std::string* buf) { |
335 | 0 | const Slice* slice = (const Slice*)value; |
336 | 0 | size_t copy_size = std::min(index_size, slice->size); |
337 | 0 | buf->append(slice->data, copy_size); |
338 | 0 | } |
339 | | |
340 | 0 | static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) { |
341 | 0 | throw Exception(Status::FatalError("decode_ascending is not implemented")); |
342 | 0 | } |
343 | | }; |
344 | | |
345 | | } // namespace doris |