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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new a88183ee2c8 branch-3.0: [improvement](information_schema)Show view 
definition in information_schema.views. #45857 (#45904)
a88183ee2c8 is described below

commit a88183ee2c83a8aa98008954fa2390ba012d2456
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Dec 25 12:57:38 2024 +0800

    branch-3.0: [improvement](information_schema)Show view definition in 
information_schema.views. #45857 (#45904)
    
    Cherry-picked from #45857
    
    Co-authored-by: James <lijib...@selectdb.com>
---
 .../exec/schema_scanner/schema_views_scanner.cpp   |  9 ++++++-
 .../apache/doris/service/FrontendServiceImpl.java  |  4 +++
 .../nereids_p0/system/test_query_sys_tables.out    |  2 +-
 .../data/query_p0/system/test_query_sys_tables.out |  2 +-
 regression-test/data/view_p0/view_p0.out           |  6 +++++
 regression-test/suites/view_p0/view_p0.groovy      | 30 ++++++++++++----------
 6 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/be/src/exec/schema_scanner/schema_views_scanner.cpp 
b/be/src/exec/schema_scanner/schema_views_scanner.cpp
index f47766ef356..6ba7bf04c8b 100644
--- a/be/src/exec/schema_scanner/schema_views_scanner.cpp
+++ b/be/src/exec/schema_scanner/schema_views_scanner.cpp
@@ -140,7 +140,14 @@ Status 
SchemaViewsScanner::_fill_block_impl(vectorized::Block* block) {
     std::vector<void*> datas(tables_num);
 
     // catalog
-    { RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, null_datas)); }
+    {
+        std::string catalog_name = _db_result.catalogs[_db_index - 1];
+        StringRef str = StringRef(catalog_name.c_str(), catalog_name.size());
+        for (int i = 0; i < tables_num; ++i) {
+            datas[i] = &str;
+        }
+        RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
+    }
     // schema
     {
         std::string db_name = 
SchemaHelper::extract_db_name(_db_result.dbs[_db_index - 1]);
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 1ad8d733dde..8323540f5d1 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
@@ -45,6 +45,7 @@ import org.apache.doris.catalog.TableIf;
 import org.apache.doris.catalog.TableIf.TableType;
 import org.apache.doris.catalog.Tablet;
 import org.apache.doris.catalog.TabletMeta;
+import org.apache.doris.catalog.View;
 import org.apache.doris.cloud.catalog.CloudPartition;
 import org.apache.doris.cloud.catalog.CloudTablet;
 import org.apache.doris.cloud.proto.Cloud.CommitTxnResponse;
@@ -660,6 +661,9 @@ public class FrontendServiceImpl implements 
FrontendService.Iface {
                             status.setDataLength(table.getDataLength());
                             status.setAvgRowLength(table.getAvgRowLength());
                             status.setIndexLength(table.getIndexLength());
+                            if (table instanceof View) {
+                                status.setDdlSql(((View) 
table).getInlineViewDef());
+                            }
                             tablesResult.add(status);
                         } finally {
                             table.readUnlock();
diff --git a/regression-test/data/nereids_p0/system/test_query_sys_tables.out 
b/regression-test/data/nereids_p0/system/test_query_sys_tables.out
index 16b71543a11..829e1670608 100644
--- a/regression-test/data/nereids_p0/system/test_query_sys_tables.out
+++ b/regression-test/data/nereids_p0/system/test_query_sys_tables.out
@@ -39,5 +39,5 @@ wait_timeout  31000
 'nereids_test_sys_tables'@'%'  SELECT  NO
 
 -- !views --
-test_view      
+test_view      SELECT 
`internal`.`test_query_sys_db_4`.`test_query_sys_tb_4`.`ccc` AS `a` FROM 
`internal`.`test_query_sys_db_4`.`test_query_sys_tb_4`
 
diff --git a/regression-test/data/query_p0/system/test_query_sys_tables.out 
b/regression-test/data/query_p0/system/test_query_sys_tables.out
index 0100314ef79..648959e2ce4 100644
--- a/regression-test/data/query_p0/system/test_query_sys_tables.out
+++ b/regression-test/data/query_p0/system/test_query_sys_tables.out
@@ -172,7 +172,7 @@ wait_timeout        31000
 'original_test_sys_tables'@'%' SELECT  NO
 
 -- !views --
-test_view      
+test_view      SELECT 
`internal`.`test_query_sys_db_1`.`test_query_sys_tb_1`.`ccc` AS `a` FROM 
`internal`.`test_query_sys_db_1`.`test_query_sys_tb_1`
 
 -- !sql --
 
diff --git a/regression-test/data/view_p0/view_p0.out 
b/regression-test/data/view_p0/view_p0.out
index 21d23110a91..928c01f1aa6 100644
--- a/regression-test/data/view_p0/view_p0.out
+++ b/regression-test/data/view_p0/view_p0.out
@@ -8,6 +8,12 @@
 -- !sql --
 1
 
+-- !information_schema1 --
+internal       regression_test_view_p0 test_varchar_view       SELECT 
GROUP_CONCAT(cast( `internal`.`regression_test_view_p0`.`test_view_table`.`id` 
as varchar)) AS `id` from 
`internal`.`regression_test_view_p0`.`test_view_table`  NONE    NO      root@%  
DEFINER utf8    \N
+
+-- !information_schema2 --
+internal       regression_test_view_p0 test_view       select 
1,to_base64(AES_ENCRYPT('doris','doris'))        NONE    NO      root@%  
DEFINER utf8    \N
+
 -- !sql --
 1      2023-08-01      DORID_FIELD1    DORID_FIELD2    ["cat", "dog"]  cat
 1      2023-08-01      DORID_FIELD1    DORID_FIELD2    ["cat", "dog"]  dog
diff --git a/regression-test/suites/view_p0/view_p0.groovy 
b/regression-test/suites/view_p0/view_p0.groovy
index 7ee8c9e913c..f69bd808dc6 100644
--- a/regression-test/suites/view_p0/view_p0.groovy
+++ b/regression-test/suites/view_p0/view_p0.groovy
@@ -21,27 +21,30 @@ suite("view_p0") {
         create view test_view as select 
1,to_base64(AES_ENCRYPT('doris','doris')); 
     """
     qt_sql "select * from test_view;"
-    
+
     sql """DROP TABLE IF EXISTS test_view_table"""
-    
+
     sql """ 
         create table test_view_table (id int) distributed by hash(id) 
properties('replication_num'='1');
     """
-    
+
     sql """insert into test_view_table values(1);"""
-    
+
     sql """DROP VIEW IF EXISTS test_varchar_view"""
-    
+
     sql """ 
         create view test_varchar_view (id) as  SELECT GROUP_CONCAT(cast( id as 
varchar)) from test_view_table; 
     """
-    
+
     qt_sql "select * from test_varchar_view;"
     qt_sql "select cast( id as varchar(65533)) from test_view_table;"
-    
+
+    qt_information_schema1 "select * from information_schema.views where 
TABLE_SCHEMA='regression_test_view_p0' and TABLE_NAME='test_varchar_view' order 
by table_catalog, table_schema, table_name;"
+    qt_information_schema2 "select * from information_schema.views where 
TABLE_SCHEMA='regression_test_view_p0' and TABLE_NAME='test_view' order by 
table_catalog, table_schema, table_name;"
+
     // array view
     sql """DROP TABLE IF EXISTS test_array_tbl_1"""
-    
+
     sql """ 
            CREATE TABLE `test_array_tbl_1` (
              `id` int(11) NULL COMMENT "",
@@ -60,7 +63,7 @@ suite("view_p0") {
             "storage_format" = "V2"
             );
     """
-    
+
     sql """DROP TABLE IF EXISTS test_array_tbl_2"""
     sql """ 
            CREATE TABLE `test_array_tbl_2` (
@@ -81,11 +84,11 @@ suite("view_p0") {
             );
     """
     sql """INSERT into test_array_tbl_1 
values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
-    
+
     sql """INSERT into test_array_tbl_2 
values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
-    
+
     sql """DROP VIEW IF EXISTS test_element_at_view"""
-    
+
     sql """ 
         CREATE VIEW test_element_at_view AS
         SELECT id, dm, pn, field3, ms, ek[sm] AS ek
@@ -147,7 +150,7 @@ suite("view_p0") {
     sql "drop view if exists test_view_aes;"
 
     sql """DROP TABLE IF EXISTS test_view_table2"""
-    
+
     sql """ 
         CREATE TABLE test_view_table2 (
             c_date varchar(50)
@@ -172,3 +175,4 @@ suite("view_p0") {
     sql """ drop view if exists test_view_table2_view;"""
     sql """DROP TABLE IF EXISTS test_view_table2"""
 }
+


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

Reply via email to