Skip to content

Commit

Permalink
[fix](session) fix select * from variables system table
Browse files Browse the repository at this point in the history
Signed-off-by: nextdreamblue <zxw520blue1@163.com>
  • Loading branch information
nextdreamblue committed May 8, 2024
1 parent a22b4f4 commit 5a1ff28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
28 changes: 26 additions & 2 deletions be/src/exec/schema_scanner/schema_variables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ std::vector<SchemaScanner::ColumnDesc> SchemaVariablesScanner::_s_vars_columns =
// name, type, size
{"VARIABLE_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
{"VARIABLE_VALUE", TYPE_VARCHAR, sizeof(StringRef), false},
{"DEFAULT_VALUE", TYPE_VARCHAR, sizeof(StringRef), false},
{"CHANGED", TYPE_VARCHAR, sizeof(StringRef), false}
};

SchemaVariablesScanner::SchemaVariablesScanner(TVarType::type type)
Expand Down Expand Up @@ -94,7 +96,7 @@ Status SchemaVariablesScanner::_fill_block_impl(vectorized::Block* block) {
std::vector<StringRef> strs(row_num);
int idx = 0;
for (auto& it : _var_result.variables) {
strs[idx] = StringRef(it.first.c_str(), it.first.size());
strs[idx] = StringRef(it[0].c_str(), it[0].size());
datas[idx] = strs.data() + idx;
++idx;
}
Expand All @@ -105,12 +107,34 @@ Status SchemaVariablesScanner::_fill_block_impl(vectorized::Block* block) {
std::vector<StringRef> strs(row_num);
int idx = 0;
for (auto& it : _var_result.variables) {
strs[idx] = StringRef(it.second.c_str(), it.second.size());
strs[idx] = StringRef(it[1].c_str(), it[1].size());
datas[idx] = strs.data() + idx;
++idx;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas));
}
// default value
{
std::vector<StringRef> strs(row_num);
int idx = 0;
for (auto& it : _var_result.variables) {
strs[idx] = StringRef(it[2].c_str(), it[2].size());
datas[idx] = strs.data() + idx;
++idx;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas));
}
// changed
{
std::vector<StringRef> strs(row_num);
int idx = 0;
for (auto& it : _var_result.variables) {
strs[idx] = StringRef(it[3].c_str(), it[3].size());
datas[idx] = strs.data() + idx;
++idx;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas));
}
return Status::OK();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,18 +946,15 @@ private TColumnDesc getColumnDesc(Column column) {
@Override
public TShowVariableResult showVariables(TShowVariableRequest params) throws TException {
TShowVariableResult result = new TShowVariableResult();
Map<String, String> map = Maps.newHashMap();
result.setVariables(map);
List<List<String>> vars = Lists.newArrayList();
result.setVariables(vars);
// Find connect
ConnectContext ctx = exeEnv.getScheduler().getContext((int) params.getThreadId());
if (ctx == null) {
return result;
}
List<List<String>> rows = VariableMgr.dump(SetType.fromThrift(params.getVarType()), ctx.getSessionVariable(),
null);
for (List<String> row : rows) {
map.put(row.get(0), row.get(1));
}
vars = VariableMgr.dump(SetType.fromThrift(params.getVarType()), ctx.getSessionVariable(), null);
result.setVariables(vars);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct TShowVariableRequest {

// Results of a call to describeTable()
struct TShowVariableResult {
1: required map<string, string> variables
1: required list<list<string>> variables
}

// Valid table file formats
Expand Down

0 comments on commit 5a1ff28

Please sign in to comment.