/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 | 22 | JsonBinaryValue() : ptr(nullptr), len(0) {} |
46 | 0 | JsonBinaryValue(char* ptr, size_t 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 | 928 | JsonBinaryValue(const char* ptr, int len) { static_cast<void>(from_json_string(ptr, len)); } |
53 | | |
54 | 947 | const char* value() { return ptr; } |
55 | | |
56 | 947 | 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 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
65 | 0 | } |
66 | | // != |
67 | 0 | bool ne(const JsonBinaryValue& other) const { |
68 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
69 | 0 | } |
70 | | // <= |
71 | 0 | bool le(const JsonBinaryValue& other) const { |
72 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
73 | 0 | } |
74 | | // >= |
75 | 0 | bool ge(const JsonBinaryValue& other) const { |
76 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
77 | 0 | } |
78 | | // < |
79 | 0 | bool lt(const JsonBinaryValue& other) const { |
80 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
81 | 0 | } |
82 | | // > |
83 | 0 | bool gt(const JsonBinaryValue& other) const { |
84 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
85 | 0 | } |
86 | | |
87 | 0 | bool operator!=(const JsonBinaryValue& other) const { |
88 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
89 | 0 | } |
90 | | |
91 | 0 | bool operator<=(const JsonBinaryValue& other) const { |
92 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
93 | 0 | } |
94 | | |
95 | 0 | bool operator>=(const JsonBinaryValue& other) const { |
96 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
97 | 0 | } |
98 | | |
99 | 0 | bool operator<(const JsonBinaryValue& other) const { |
100 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
101 | 0 | } |
102 | | |
103 | 0 | bool operator>(const JsonBinaryValue& other) const { |
104 | 0 | throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported")); |
105 | 0 | } |
106 | | |
107 | | Status from_json_string(const char* s, size_t len); |
108 | | |
109 | | std::string to_json_string() const; |
110 | | |
111 | | struct HashOfJsonBinaryValue { |
112 | 0 | size_t operator()(const JsonBinaryValue& v) const { |
113 | 0 | return HashUtil::hash(v.ptr, v.len, 0); |
114 | 0 | } |
115 | | }; |
116 | | }; |
117 | | |
118 | | // This function must be called 'hash_value' to be picked up by boost. |
119 | 0 | inline std::size_t hash_value(const JsonBinaryValue& v) { |
120 | 0 | return HashUtil::hash(v.ptr, v.len, 0); |
121 | 0 | } |
122 | | |
123 | | std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value); |
124 | | |
125 | | std::size_t operator-(const JsonBinaryValue& v1, const JsonBinaryValue& v2); |
126 | | |
127 | | } // namespace doris |
128 | | |
129 | | #endif |