/root/doris/be/src/runtime/jsonb_value.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 | | #ifndef DORIS_BE_RUNTIME_JSON_VALUE_H |
19 | | #define DORIS_BE_RUNTIME_JSON_VALUE_H |
20 | | |
21 | | #include <glog/logging.h> |
22 | | |
23 | | #include <cstddef> |
24 | | #include <ostream> |
25 | | #include <string> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "util/hash_util.hpp" |
29 | | #ifdef __AVX2__ |
30 | | #include "util/jsonb_parser_simd.h" |
31 | | #else |
32 | | #include "util/jsonb_parser.h" |
33 | | #endif |
34 | | |
35 | | namespace doris { |
36 | | |
37 | | struct JsonBinaryValue { |
38 | | static const int MAX_LENGTH = (1 << 30); |
39 | | |
40 | | // default nullprt and size 0 for invalid or NULL value |
41 | | const char* ptr = nullptr; |
42 | | size_t len = 0; |
43 | | JsonbParser parser; |
44 | | |
45 | 4 | JsonBinaryValue() : ptr(nullptr), len(0) {} |
46 | 0 | JsonBinaryValue(char* ptr, int len) { |
47 | 0 | static_cast<void>(from_json_string(const_cast<const char*>(ptr), len)); |
48 | 0 | } |
49 | 1 | JsonBinaryValue(const std::string& s) { |
50 | 1 | static_cast<void>(from_json_string(s.c_str(), s.length())); |
51 | 1 | } |
52 | 816 | JsonBinaryValue(const char* ptr, int len) { static_cast<void>(from_json_string(ptr, len)); } |
53 | | |
54 | 819 | const char* value() { return ptr; } |
55 | | |
56 | 819 | size_t size() { return len; } |
57 | | |
58 | 0 | void replace(char* ptr, int len) { |
59 | 0 | this->ptr = ptr; |
60 | 0 | this->len = len; |
61 | 0 | } |
62 | | |
63 | 0 | bool operator==(const JsonBinaryValue& other) const { |
64 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
65 | 0 | __builtin_unreachable(); |
66 | 0 | } |
67 | | // != |
68 | 0 | bool ne(const JsonBinaryValue& other) const { |
69 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
70 | 0 | __builtin_unreachable(); |
71 | 0 | } |
72 | | // <= |
73 | 0 | bool le(const JsonBinaryValue& other) const { |
74 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
75 | 0 | __builtin_unreachable(); |
76 | 0 | } |
77 | | // >= |
78 | 0 | bool ge(const JsonBinaryValue& other) const { |
79 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
80 | 0 | __builtin_unreachable(); |
81 | 0 | } |
82 | | // < |
83 | 0 | bool lt(const JsonBinaryValue& other) const { |
84 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
85 | 0 | __builtin_unreachable(); |
86 | 0 | } |
87 | | // > |
88 | 0 | bool gt(const JsonBinaryValue& other) const { |
89 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
90 | 0 | __builtin_unreachable(); |
91 | 0 | } |
92 | | |
93 | 0 | bool operator!=(const JsonBinaryValue& other) const { |
94 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
95 | 0 | __builtin_unreachable(); |
96 | 0 | } |
97 | | |
98 | 0 | bool operator<=(const JsonBinaryValue& other) const { |
99 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
100 | 0 | __builtin_unreachable(); |
101 | 0 | } |
102 | | |
103 | 0 | bool operator>=(const JsonBinaryValue& other) const { |
104 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
105 | 0 | __builtin_unreachable(); |
106 | 0 | } |
107 | | |
108 | 0 | bool operator<(const JsonBinaryValue& other) const { |
109 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
110 | 0 | __builtin_unreachable(); |
111 | 0 | } |
112 | | |
113 | 0 | bool operator>(const JsonBinaryValue& other) const { |
114 | 0 | LOG(FATAL) << "comparing between JsonBinaryValue is not supported"; |
115 | 0 | __builtin_unreachable(); |
116 | 0 | } |
117 | | |
118 | | Status from_json_string(const char* s, int len); |
119 | | |
120 | | std::string to_json_string() const; |
121 | | |
122 | | struct HashOfJsonBinaryValue { |
123 | 0 | size_t operator()(const JsonBinaryValue& v) const { |
124 | 0 | return HashUtil::hash(v.ptr, v.len, 0); |
125 | 0 | } |
126 | | }; |
127 | | }; |
128 | | |
129 | | // This function must be called 'hash_value' to be picked up by boost. |
130 | 0 | inline std::size_t hash_value(const JsonBinaryValue& v) { |
131 | 0 | return HashUtil::hash(v.ptr, v.len, 0); |
132 | 0 | } |
133 | | |
134 | | std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value); |
135 | | |
136 | | std::size_t operator-(const JsonBinaryValue& v1, const JsonBinaryValue& v2); |
137 | | |
138 | | } // namespace doris |
139 | | |
140 | | #endif |