Files
doris/be/src/runtime/jsonb_value.cpp
Kang 8ef6b4d996 [fix](json) fix json int128 overflow (#22917)
* support int128 in jsonb

* fix jsonb int128 write

* fix jsonb to json int128

* fix json functions for int128

* add nereids function jsonb_extract_largeint

* add testcase for json int128

* change docs for json int128

* add nereids function jsonb_extract_largeint

* clang format

* fix check style

* using int128_t = __int128_t for all int128

* use fmt::format_to instead of snprintf digit by digit for int128

* clang format

* delete useless check

* add warn log

* clang format
2023-08-25 11:40:30 +08:00

55 lines
1.9 KiB
C++

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "runtime/jsonb_value.h"
#include <fmt/format.h>
#include <string_view>
#include "util/jsonb_error.h"
#include "util/jsonb_stream.h"
#include "util/jsonb_utils.h"
#include "util/jsonb_writer.h"
namespace doris {
Status JsonBinaryValue::from_json_string(const char* s, int length) {
JsonbErrType error = JsonbErrType::E_NONE;
if (!parser.parse(s, length)) {
error = parser.getErrorCode();
auto msg = fmt::format("json parse error: {} for value: {}", JsonbErrMsg::getErrMsg(error),
std::string_view(s, length));
LOG(WARNING) << msg;
return Status::InvalidArgument(msg);
}
ptr = parser.getWriter().getOutput()->getBuffer();
len = (unsigned)parser.getWriter().getOutput()->getSize();
DCHECK_LE(len, MAX_LENGTH);
return Status::OK();
}
std::string JsonBinaryValue::to_json_string() const {
return JsonbToJson::jsonb_to_json_string(ptr, len);
}
std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value) {
return os << json_value.to_json_string();
}
} // namespace doris