Coverage Report

Created: 2026-04-11 13:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
23
class FunctionToJson : public IFunction {
24
public:
25
    static constexpr auto name = "to_json";
26
27
499
    static FunctionPtr create() { return std::make_shared<FunctionToJson>(); }
28
    using NullMapType = PaddedPODArray<UInt8>;
29
30
1
    String get_name() const override { return name; }
31
32
491
    bool is_variadic() const override { return false; }
33
34
490
    size_t get_number_of_arguments() const override { return 1; }
35
36
490
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
37
490
        return std::make_shared<DataTypeJsonb>();
38
490
    }
39
40
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
41
518
                        uint32_t result, size_t input_rows_count) const override {
42
518
        auto to_column = ColumnString::create();
43
518
        auto from_type_serde = block.get_by_position(arguments[0]).type->get_serde();
44
518
        auto from_column = block.get_by_position(arguments[0]).column;
45
518
        RETURN_IF_ERROR(
46
518
                from_type_serde->serialize_column_to_jsonb_vector(*from_column, *to_column));
47
518
        block.get_by_position(result).column = std::move(to_column);
48
518
        return Status::OK();
49
518
    }
50
};
51
52
8
void register_function_to_json(SimpleFunctionFactory& factory) {
53
8
    factory.register_function<FunctionToJson>();
54
8
}
55
56
} // namespace doris