Skip to content

Commit

Permalink
[improvement](information_schema)Show view definition in information_…
Browse files Browse the repository at this point in the history
…schema.views. (#45857) (#45930)

backport: #45857
  • Loading branch information
Jibing-Li authored Dec 26, 2024
1 parent 1cf6986 commit 289d621
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
9 changes: 8 additions & 1 deletion be/src/exec/schema_scanner/schema_views_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 --

Expand Down Expand Up @@ -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 --

Original file line number Diff line number Diff line change
Expand Up @@ -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`

Original file line number Diff line number Diff line change
Expand Up @@ -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 --

Expand Down
6 changes: 6 additions & 0 deletions regression-test/data/view_p0/view_p0.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions regression-test/suites/view_p0/view_p0.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 "",
Expand All @@ -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` (
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -165,3 +168,4 @@ suite("view_p0") {
sql """ drop view if exists test_view_table2_view;"""
sql """DROP TABLE IF EXISTS test_view_table2"""
}

0 comments on commit 289d621

Please sign in to comment.