be/src/exprs/function/function_to_json.cpp
Line | Count | Source |
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 "core/data_type/data_type_jsonb.h" |
19 | | #include "exprs/function/simple_function_factory.h" |
20 | | |
21 | | namespace doris { |
22 | | #include "common/compile_check_begin.h" |
23 | | |
24 | | class FunctionToJson : public IFunction { |
25 | | public: |
26 | | static constexpr auto name = "to_json"; |
27 | | |
28 | 514 | static FunctionPtr create() { return std::make_shared<FunctionToJson>(); } |
29 | | using NullMapType = PaddedPODArray<UInt8>; |
30 | | |
31 | 1 | String get_name() const override { return name; } |
32 | | |
33 | 506 | bool is_variadic() const override { return false; } |
34 | | |
35 | 505 | size_t get_number_of_arguments() const override { return 1; } |
36 | | |
37 | 505 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
38 | 505 | return std::make_shared<DataTypeJsonb>(); |
39 | 505 | } |
40 | | |
41 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
42 | 531 | uint32_t result, size_t input_rows_count) const override { |
43 | 531 | auto to_column = ColumnString::create(); |
44 | 531 | auto from_type_serde = block.get_by_position(arguments[0]).type->get_serde(); |
45 | 531 | auto from_column = block.get_by_position(arguments[0]).column; |
46 | 531 | RETURN_IF_ERROR( |
47 | 531 | from_type_serde->serialize_column_to_jsonb_vector(*from_column, *to_column)); |
48 | 531 | block.get_by_position(result).column = std::move(to_column); |
49 | 531 | return Status::OK(); |
50 | 531 | } |
51 | | }; |
52 | | |
53 | 8 | void register_function_to_json(SimpleFunctionFactory& factory) { |
54 | 8 | factory.register_function<FunctionToJson>(); |
55 | 8 | } |
56 | | |
57 | | } // namespace doris |