This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new f4e92d75f51 [branch-2.1] fix select * from variables system table 
(#34529) (#47660)
f4e92d75f51 is described below

commit f4e92d75f516816c5c3150f3352041840a02439f
Author: wangbo <wan...@selectdb.com>
AuthorDate: Sun Feb 9 14:14:06 2025 +0800

    [branch-2.1] fix select * from variables system table (#34529) (#47660)
    
    pick #34529
    
    Signed-off-by: nextdreamblue <zxw520bl...@163.com>
    Co-authored-by: xueweizhang <zxw520bl...@163.com>
---
 .../schema_scanner/schema_variables_scanner.cpp    |  37 +++++++++++++++++----
 .../apache/doris/service/FrontendServiceImpl.java  |  11 +++---
 gensrc/thrift/FrontendService.thrift               |   2 +-
 .../data/variable_p0/set_and_unset_variable.out    | Bin 2588 -> 2680 bytes
 .../variable_p0/set_and_unset_variable.groovy      |   4 +++
 5 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/be/src/exec/schema_scanner/schema_variables_scanner.cpp 
b/be/src/exec/schema_scanner/schema_variables_scanner.cpp
index 445089b36ab..ad4d5d072cb 100644
--- a/be/src/exec/schema_scanner/schema_variables_scanner.cpp
+++ b/be/src/exec/schema_scanner/schema_variables_scanner.cpp
@@ -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) {}
@@ -91,26 +92,48 @@ Status 
SchemaVariablesScanner::_fill_block_impl(vectorized::Block* block) {
     std::vector<void*> datas(row_num);
     // variables names
     {
-        StringRef strs[row_num];
+        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());
-            datas[idx] = strs + idx;
+            strs[idx] = StringRef(it[0].c_str(), it[0].size());
+            datas[idx] = strs.data() + idx;
             ++idx;
         }
         RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
     }
     // value
     {
-        StringRef strs[row_num];
+        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());
-            datas[idx] = strs + idx;
+            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();
 }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java 
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index 90a9edace2e..5a98b04b0b7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -955,18 +955,15 @@ public class FrontendServiceImpl implements 
FrontendService.Iface {
     @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;
     }
 
diff --git a/gensrc/thrift/FrontendService.thrift 
b/gensrc/thrift/FrontendService.thrift
index 2b753a45ac1..88343f9f32c 100644
--- a/gensrc/thrift/FrontendService.thrift
+++ b/gensrc/thrift/FrontendService.thrift
@@ -107,7 +107,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
diff --git a/regression-test/data/variable_p0/set_and_unset_variable.out 
b/regression-test/data/variable_p0/set_and_unset_variable.out
index 33dd8af7bc1..506542ea754 100644
Binary files a/regression-test/data/variable_p0/set_and_unset_variable.out and 
b/regression-test/data/variable_p0/set_and_unset_variable.out differ
diff --git a/regression-test/suites/variable_p0/set_and_unset_variable.groovy 
b/regression-test/suites/variable_p0/set_and_unset_variable.groovy
index c637d3ae223..0ad043cb96c 100644
--- a/regression-test/suites/variable_p0/set_and_unset_variable.groovy
+++ b/regression-test/suites/variable_p0/set_and_unset_variable.groovy
@@ -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'"""
@@ -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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to