diff --git a/be/src/exec/schema_scanner/schema_views_scanner.cpp b/be/src/exec/schema_scanner/schema_views_scanner.cpp index 5b5f0c1b72933b..46ea42d2e9cdd8 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 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 47b8abff0eb2de..90a9edace2ef97 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 @@ -44,6 +44,7 @@ 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.cluster.ClusterNamespace; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.AuthenticationException; @@ -629,6 +630,9 @@ public TListTableStatusResult listTableStatus(TGetTablesParams params) throws TE status.setRows(table.getCachedRowCount()); status.setDataLength(table.getDataLength()); status.setAvgRowLength(table.getAvgRowLength()); + if (table instanceof View) { + status.setDdlSql(((View) table).getInlineViewDef()); + } tablesResult.add(status); } finally { table.readUnlock(); diff --git a/regression-test/data/external_table_p0/hive/test_information_schema_external.out b/regression-test/data/external_table_p0/hive/test_information_schema_external.out index 199b9e0b12305e..6142e37c2b8905 100644 --- a/regression-test/data/external_table_p0/hive/test_information_schema_external.out +++ b/regression-test/data/external_table_p0/hive/test_information_schema_external.out @@ -127,7 +127,7 @@ test_information_schema_external_hive2 tpch1_parquet orders BASE TABLE hms 0 \N test_information_schema_external_hive2 tpch1_parquet partsupp BASE TABLE hms 0 \N -- !views_1 -- -\N info_schema_ext_db test_view NONE NO root@% DEFINER utf8 \N +internal info_schema_ext_db test_view SELECT `internal`.`info_schema_ext_db`.`ab`.`id` AS `a` FROM `internal`.`info_schema_ext_db`.`ab` NONE NO root@% DEFINER utf8 \N -- !views_2 -- @@ -259,7 +259,7 @@ test_information_schema_external_hive3 tpch1_parquet orders BASE TABLE hms 0 \N test_information_schema_external_hive3 tpch1_parquet partsupp BASE TABLE hms 0 \N -- !views_1 -- -\N info_schema_ext_db test_view NONE NO root@% DEFINER utf8 \N +internal info_schema_ext_db test_view SELECT `internal`.`info_schema_ext_db`.`ab`.`id` AS `a` FROM `internal`.`info_schema_ext_db`.`ab` NONE NO root@% DEFINER utf8 \N -- !views_2 -- 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 a43229a87adead..c3781f091e12a8 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 215a3d5f1c605a..15e812c9eafe2e 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 @@ -200,7 +200,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 976d4a3cb2ad07..606dc0b670a851 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 82c9e3987ce03e..2727a3e6f82fcd 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 @@ -138,7 +141,7 @@ suite("view_p0") { sql "drop view if exists test_view_abc;" sql """DROP TABLE IF EXISTS test_view_table2""" - + sql """ CREATE TABLE test_view_table2 ( c_date varchar(50) @@ -165,3 +168,4 @@ suite("view_p0") { sql """ drop view if exists test_view_table2_view;""" sql """DROP TABLE IF EXISTS test_view_table2""" } +