Coverage Report

Created: 2024-11-22 11:49

/root/doris/be/src/runtime/jsonb_value.cpp
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
#include "runtime/jsonb_value.h"
19
20
#include <fmt/format.h>
21
22
#include <string_view>
23
24
#include "util/jsonb_error.h"
25
#include "util/jsonb_stream.h"
26
#include "util/jsonb_utils.h"
27
#include "util/jsonb_writer.h"
28
29
namespace doris {
30
31
933
Status JsonBinaryValue::from_json_string(const char* s, size_t length) {
32
933
    JsonbErrType error = JsonbErrType::E_NONE;
33
933
    if (!parser.parse(s, length)) {
34
2
        error = parser.getErrorCode();
35
2
        auto msg = fmt::format("json parse error: {} for value: {}", JsonbErrMsg::getErrMsg(error),
36
2
                               std::string_view(s, length));
37
2
        VLOG_DEBUG << msg;
38
2
        return Status::InvalidArgument(msg);
39
2
    }
40
41
931
    ptr = parser.getWriter().getOutput()->getBuffer();
42
931
    len = (unsigned)parser.getWriter().getOutput()->getSize();
43
931
    DCHECK_LE(len, MAX_LENGTH);
44
931
    return Status::OK();
45
933
}
46
47
0
std::string JsonBinaryValue::to_json_string() const {
48
0
    return JsonbToJson::jsonb_to_json_string(ptr, len);
49
0
}
50
51
0
std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value) {
52
0
    return os << json_value.to_json_string();
53
0
}
54
} // namespace doris