Coverage Report

Created: 2026-04-13 08:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/table_function/vjson_each.h
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
#pragma once
19
20
#include <cstddef>
21
22
#include "common/status.h"
23
#include "core/data_type/data_type.h"
24
#include "exprs/table_function/table_function.h"
25
26
namespace doris {
27
class Block;
28
29
// json_each('{"a":"foo","b":123}') →
30
// | key | value        |
31
// | a   | "foo" (JSON) |
32
// | b   | 123   (JSON) |
33
//
34
// json_each_text('{"a":"foo","b":123}') →
35
// | key | value   |
36
// | a   | foo     |  ← string unquoted
37
// | b   | 123     |  ← number as text
38
//
39
// TEXT_MODE=false → json_each  (value column type: JSONB binary)
40
// TEXT_MODE=true  → json_each_text (value column type: plain STRING)
41
template <bool TEXT_MODE>
42
class VJsonEachTableFunction : public TableFunction {
43
    ENABLE_FACTORY_CREATOR(VJsonEachTableFunction);
44
45
public:
46
    VJsonEachTableFunction();
47
48
263
    ~VJsonEachTableFunction() override = default;
_ZN5doris22VJsonEachTableFunctionILb0EED2Ev
Line
Count
Source
48
159
    ~VJsonEachTableFunction() override = default;
_ZN5doris22VJsonEachTableFunctionILb1EED2Ev
Line
Count
Source
48
104
    ~VJsonEachTableFunction() override = default;
49
50
    Status process_init(Block* block, RuntimeState* state) override;
51
    void process_row(size_t row_idx) override;
52
    void process_close() override;
53
    void get_same_many_values(MutableColumnPtr& column, int length) override;
54
    int get_value(MutableColumnPtr& column, int max_step) override;
55
56
#ifdef BE_TEST
57
    const ColumnPtr& test_json_column() const { return _json_column; }
58
    const MutableColumnPtr& test_kv_pairs_first() const { return _kv_pairs.first; }
59
    const MutableColumnPtr& test_kv_pairs_second() const { return _kv_pairs.second; }
60
#endif
61
62
private:
63
    ColumnPtr _json_column;
64
    // _kv_pairs.first  : ColumnNullable<ColumnString>  key (always plain text)
65
    // _kv_pairs.second : ColumnNullable<ColumnString>  value (JSONB bytes or plain text)
66
    std::pair<MutableColumnPtr, MutableColumnPtr> _kv_pairs;
67
};
68
69
using VJsonEachTableFn = VJsonEachTableFunction<false>;
70
using VJsonEachTextTableFn = VJsonEachTableFunction<true>;
71
72
} // namespace doris