Coverage Report

Created: 2025-06-03 12:22

/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
#include "util/jsonb_parser_simd.h"
30
31
namespace doris {
32
33
struct JsonBinaryValue {
34
    static const int MAX_LENGTH = (1 << 30);
35
36
    // default nullprt and size 0 for invalid or NULL value
37
    const char* ptr = nullptr;
38
    size_t len = 0;
39
    JsonbParser parser;
40
41
22
    JsonBinaryValue() = default;
42
0
    JsonBinaryValue(char* ptr, size_t len) {
43
0
        static_cast<void>(from_json_string(const_cast<const char*>(ptr), len));
44
0
    }
45
1
    JsonBinaryValue(const std::string& s) {
46
1
        static_cast<void>(from_json_string(s.c_str(), s.length()));
47
1
    }
48
1.20k
    JsonBinaryValue(const char* ptr, int len) { static_cast<void>(from_json_string(ptr, len)); }
49
50
1.21k
    const char* value() const { return ptr; }
51
52
1.21k
    size_t size() const { return len; }
53
54
0
    void replace(const char* ptr, int len) {
55
0
        this->ptr = ptr;
56
0
        this->len = len;
57
0
    }
58
59
0
    bool operator==(const JsonBinaryValue& other) const {
60
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
61
0
    }
62
    // !=
63
0
    bool ne(const JsonBinaryValue& other) const {
64
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
65
0
    }
66
    // <=
67
0
    bool le(const JsonBinaryValue& other) const {
68
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
69
0
    }
70
    // >=
71
0
    bool ge(const JsonBinaryValue& other) const {
72
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
73
0
    }
74
    // <
75
0
    bool lt(const JsonBinaryValue& other) const {
76
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
77
0
    }
78
    // >
79
0
    bool gt(const JsonBinaryValue& other) const {
80
0
        throw Exception(Status::FatalError("comparing between JsonBinaryValue is not supported"));
81
0
    }
82
83
0
    bool operator!=(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
    Status from_json_string(const char* s, size_t len);
104
105
    std::string to_json_string() const;
106
107
    struct HashOfJsonBinaryValue {
108
0
        size_t operator()(const JsonBinaryValue& v) const {
109
0
            return HashUtil::hash(v.ptr, v.len, 0);
110
0
        }
111
    };
112
};
113
114
// This function must be called 'hash_value' to be picked up by boost.
115
0
inline std::size_t hash_value(const JsonBinaryValue& v) {
116
0
    return HashUtil::hash(v.ptr, v.len, 0);
117
0
}
118
119
std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value);
120
121
std::size_t operator-(const JsonBinaryValue& v1, const JsonBinaryValue& v2);
122
123
} // namespace doris
124
125
#endif