Add `JSON` datatype, following features are implemented by this PR: 1. `CREATE` tables with `JSON` type columns 2. `INSERT` values containing `JSON` type value stored in `String`, which is represented as binary format(AKA `JSONB`) at BE 3. `SELECT` JSON columns Detail design refers [DSIP-016: Support JSON type](https://cwiki.apache.org/confluence/display/DORIS/DSIP-016%3A+Support+JSON+type) * add JSONB data storage format type * fix JsonLiteral resolve bug * add DataTypeJson case in data_type_factory * add JSON syntax check in FE * add operators for jsonb_document, currently not support comparison between any JSON type value * add ColumnJson and DataTypeJson * add JsonField to store JsonValue * add JsonValue to convert String JSON to BINARY JSON and JsonLiteral case for vliteral * add push_json for MysqlResultWriter * JSON column need no zone_map_index * Revert "JSON column need no zone_map_index" This reverts commit f71d1ce1ded9dbae44a5d58abcec338816b70d79. * add JSON writer and reader, ignore zone-map for JSON column * add json_to_string for DataTypeJson * add olap_data_convertor for JSON type * add some enum * add OLAP_FIELD_TYPE_JSON type, FieldTypeTraits for it and corresponding cases or functions * fix column_json offsets overflow bug, format code * remove useless TODOs, add CmpType cases for JSON type * add license header * format license * format be codes * resolve rebase master conflicts * fix bugs for CREATE and meta related code * refactor JsonValue constructors, add fe JSON cases and fix some bugs, reformat codes * modification be codes along code review advice * fix rebase conflicts with master * add unit test for json_value and column_json * fix rebase error * rename json to jsonb * fix some data convert bugs, set Mysql type to JSON
49 lines
1.6 KiB
C++
49 lines
1.6 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 <cstring>
|
|
|
|
#include "util/jsonb_error.h"
|
|
|
|
namespace doris {
|
|
|
|
JsonbErrType JsonBinaryValue::from_json_string(const char* s, int length) {
|
|
JsonbErrType error = JsonbErrType::E_NONE;
|
|
if (!parser.parse(s, length)) {
|
|
error = parser.getErrorCode();
|
|
ptr = nullptr;
|
|
len = 0;
|
|
return error;
|
|
}
|
|
ptr = parser.getWriter().getOutput()->getBuffer();
|
|
len = (unsigned)parser.getWriter().getOutput()->getSize();
|
|
DCHECK_LE(len, MAX_LENGTH);
|
|
return error;
|
|
}
|
|
|
|
std::string JsonBinaryValue::to_json_string() const {
|
|
JsonbToJson toStr;
|
|
return toStr.jsonb_to_string(JsonbDocument::createDocument(ptr, len)->getValue());
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, const JsonBinaryValue& json_value) {
|
|
return os << json_value.to_json_string();
|
|
}
|
|
} // namespace doris
|