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