Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](session) fix select * from variables system table #34529

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions be/src/exec/schema_scanner/schema_variables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +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)
: SchemaScanner(_s_vars_columns, TSchemaTableType::SCH_VARIABLES), _type(type) {}
Expand Down Expand Up @@ -94,7 +95,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 +106,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 @@ -957,18 +957,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
6 changes: 6 additions & 0 deletions regression-test/data/variable_p0/set_and_unset_variable.out
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ deprecated_enable_local_exchange true true 0
-- !cmd --
show_hidden_columns false false 0

-- !cmd --
show_hidden_columns false false 0

-- !cmd --
0

Expand Down Expand Up @@ -161,6 +164,9 @@ deprecated_enable_local_exchange true true 0
-- !cmd --
show_hidden_columns false false 0

-- !cmd --
show_hidden_columns false false 0

-- !cmd --
read_only true true 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ suite("set_and_unset_variable") {
qt_cmd """show session variables like 'deprecated_enable_local_exchange'"""
qt_cmd """show session variables like 'show_hidden_columns'"""

qt_cmd """select * from information_schema.session_variables where variable_name = 'show_hidden_columns'"""

// test UNSET GLOBAL VARIABLE ALL
qt_cmd """set global runtime_filter_type='BLOOM_FILTER'"""
qt_cmd """set global experimental_enable_agg_state='true'"""
Expand All @@ -84,6 +86,8 @@ suite("set_and_unset_variable") {
qt_cmd """show global variables like 'deprecated_enable_local_exchange'"""
qt_cmd """show global variables like 'show_hidden_columns'"""

qt_cmd """select * from information_schema.global_variables where variable_name = 'show_hidden_columns'"""

// test read_only
qt_cmd """show variables like 'read_only'"""
test {
Expand Down
Loading