be/src/information_schema/schema_variables_scanner.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 "information_schema/schema_variables_scanner.h" |
19 | | |
20 | | #include <gen_cpp/Descriptors_types.h> |
21 | | #include <gen_cpp/FrontendService_types.h> |
22 | | #include <string.h> |
23 | | |
24 | | #include <map> |
25 | | #include <string> |
26 | | #include <utility> |
27 | | |
28 | | #include "core/data_type/define_primitive_type.h" |
29 | | #include "core/string_ref.h" |
30 | | #include "information_schema/schema_helper.h" |
31 | | #include "runtime/runtime_profile.h" |
32 | | |
33 | | namespace doris { |
34 | | class RuntimeState; |
35 | | class Block; |
36 | | |
37 | | std::vector<SchemaScanner::ColumnDesc> SchemaVariablesScanner::_s_vars_columns = { |
38 | | // name, type, size |
39 | | {"VARIABLE_NAME", TYPE_VARCHAR, sizeof(StringRef), false}, |
40 | | {"VARIABLE_VALUE", TYPE_VARCHAR, sizeof(StringRef), false}, |
41 | | {"DEFAULT_VALUE", TYPE_VARCHAR, sizeof(StringRef), false}, |
42 | | {"CHANGED", TYPE_VARCHAR, sizeof(StringRef), false}}; |
43 | | |
44 | | SchemaVariablesScanner::SchemaVariablesScanner(TVarType::type type) |
45 | 0 | : SchemaScanner(_s_vars_columns, TSchemaTableType::SCH_VARIABLES), _type(type) {} |
46 | | |
47 | 0 | SchemaVariablesScanner::~SchemaVariablesScanner() {} |
48 | | |
49 | 0 | Status SchemaVariablesScanner::start(RuntimeState* state) { |
50 | 0 | TShowVariableRequest var_params; |
51 | | // Use db to save type |
52 | 0 | if (_param->common_param->db != nullptr) { |
53 | 0 | if (strcmp(_param->common_param->db->c_str(), "GLOBAL") == 0) { |
54 | 0 | var_params.__set_varType(TVarType::GLOBAL); |
55 | 0 | } else { |
56 | 0 | var_params.__set_varType(TVarType::SESSION); |
57 | 0 | } |
58 | 0 | } else { |
59 | 0 | var_params.__set_varType(_type); |
60 | 0 | } |
61 | 0 | var_params.__set_threadId(_param->common_param->thread_id); |
62 | |
|
63 | 0 | if (nullptr != _param->common_param->ip && 0 != _param->common_param->port) { |
64 | 0 | RETURN_IF_ERROR(SchemaHelper::show_variables( |
65 | 0 | *(_param->common_param->ip), _param->common_param->port, var_params, &_var_result)); |
66 | 0 | } else { |
67 | 0 | return Status::InternalError("IP or port doesn't exists"); |
68 | 0 | } |
69 | 0 | return Status::OK(); |
70 | 0 | } |
71 | | |
72 | 0 | Status SchemaVariablesScanner::get_next_block_internal(Block* block, bool* eos) { |
73 | 0 | if (!_is_init) { |
74 | 0 | return Status::InternalError("call this before initial."); |
75 | 0 | } |
76 | 0 | if (nullptr == block || nullptr == eos) { |
77 | 0 | return Status::InternalError("invalid parameter."); |
78 | 0 | } |
79 | | |
80 | 0 | *eos = true; |
81 | 0 | if (_var_result.variables.empty()) { |
82 | 0 | return Status::OK(); |
83 | 0 | } |
84 | 0 | return _fill_block_impl(block); |
85 | 0 | } |
86 | | |
87 | 0 | Status SchemaVariablesScanner::_fill_block_impl(Block* block) { |
88 | 0 | SCOPED_TIMER(_fill_block_timer); |
89 | 0 | auto row_num = _var_result.variables.size(); |
90 | 0 | std::vector<void*> datas(row_num); |
91 | | // variables names |
92 | 0 | { |
93 | 0 | std::vector<StringRef> strs(row_num); |
94 | 0 | int idx = 0; |
95 | 0 | for (auto& it : _var_result.variables) { |
96 | 0 | strs[idx] = StringRef(it[0].c_str(), it[0].size()); |
97 | 0 | datas[idx] = strs.data() + idx; |
98 | 0 | ++idx; |
99 | 0 | } |
100 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas)); |
101 | 0 | } |
102 | | // value |
103 | 0 | { |
104 | 0 | std::vector<StringRef> strs(row_num); |
105 | 0 | int idx = 0; |
106 | 0 | for (auto& it : _var_result.variables) { |
107 | 0 | strs[idx] = StringRef(it[1].c_str(), it[1].size()); |
108 | 0 | datas[idx] = strs.data() + idx; |
109 | 0 | ++idx; |
110 | 0 | } |
111 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas)); |
112 | 0 | } |
113 | | // default value |
114 | 0 | { |
115 | 0 | std::vector<StringRef> strs(row_num); |
116 | 0 | int idx = 0; |
117 | 0 | for (auto& it : _var_result.variables) { |
118 | 0 | strs[idx] = StringRef(it[2].c_str(), it[2].size()); |
119 | 0 | datas[idx] = strs.data() + idx; |
120 | 0 | ++idx; |
121 | 0 | } |
122 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas)); |
123 | 0 | } |
124 | | // changed |
125 | 0 | { |
126 | 0 | std::vector<StringRef> strs(row_num); |
127 | 0 | int idx = 0; |
128 | 0 | for (auto& it : _var_result.variables) { |
129 | 0 | strs[idx] = StringRef(it[3].c_str(), it[3].size()); |
130 | 0 | datas[idx] = strs.data() + idx; |
131 | 0 | ++idx; |
132 | 0 | } |
133 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas)); |
134 | 0 | } |
135 | 0 | return Status::OK(); |
136 | 0 | } |
137 | | |
138 | | } // namespace doris |