xiaokang commented on code in PR #10322: URL: https://github.com/apache/doris/pull/10322#discussion_r928252341
########## be/src/vec/data_types/data_type_json.cpp: ########## @@ -0,0 +1,132 @@ +// 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 "data_type_json.h" + +#include "gen_cpp/data.pb.h" +#include "vec/columns/column_const.h" +#include "vec/columns/column_json.h" +#include "vec/common/assert_cast.h" +#include "vec/core/field.h" +#include "vec/io/io_helper.h" + +#ifdef __SSE2__ +#include <emmintrin.h> +#endif + +namespace doris::vectorized { + +template <typename Reader> +static inline void read(IColumn& column, Reader&& reader) { + ColumnJson& column_json = assert_cast<ColumnJson&>(column); + ColumnJson::Chars& data = column_json.get_chars(); + ColumnJson::Offsets& offsets = column_json.get_offsets(); + size_t old_chars_size = data.size(); + size_t old_offsets_size = offsets.size(); + try { + reader(data); + data.push_back(0); + offsets.push_back(data.size()); + } catch (...) { + offsets.resize_assume_reserved(old_offsets_size); + data.resize_assume_reserved(old_chars_size); + throw; + } +} + +std::string jsonb_to_string(const StringRef& s) { + doris::JsonbToJson toStr; + doris::JsonbValue* val = doris::JsonbDocument::createDocument(s.data, s.size)->getValue(); + return toStr.json(val); +} + +std::string DataTypeJson::to_string(const IColumn& column, size_t row_num) const { + const StringRef& s = + reinterpret_cast<const ColumnJson&>(*column.convert_to_full_column_if_const().get()) + .get_data_at(row_num); + return jsonb_to_string(s); +} + +void DataTypeJson::to_string(const class doris::vectorized::IColumn& column, size_t row_num, + class doris::vectorized::BufferWritable& ostr) const { + const StringRef& s = Review Comment: call to_string above to avoid duplicated code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
