Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee4e7a7

Browse filesBrowse files
committed
[improvement](information_schema)Show view definition in information_schema.views. (apache#45857)
Support show view definition sql in information_schema.views. Issue Number: close #xxx Related PR: #xxx Problem Summary: None
1 parent 20c49c3 commit ee4e7a7
Copy full SHA for ee4e7a7

File tree

Expand file treeCollapse file tree

7 files changed

+39
-18
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+39
-18
lines changed

‎be/src/exec/schema_scanner/schema_views_scanner.cpp

Copy file name to clipboardExpand all lines: be/src/exec/schema_scanner/schema_views_scanner.cpp
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@ Status SchemaViewsScanner::_fill_block_impl(vectorized::Block* block) {
140140
std::vector<void*> datas(tables_num);
141141

142142
// catalog
143-
{ RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, null_datas)); }
143+
{
144+
std::string catalog_name = _db_result.catalogs[_db_index - 1];
145+
StringRef str = StringRef(catalog_name.c_str(), catalog_name.size());
146+
for (int i = 0; i < tables_num; ++i) {
147+
datas[i] = &str;
148+
}
149+
RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
150+
}
144151
// schema
145152
{
146153
std::string db_name = SchemaHelper::extract_db_name(_db_result.dbs[_db_index - 1]);

‎fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java

Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.doris.catalog.TableIf.TableType;
4545
import org.apache.doris.catalog.Tablet;
4646
import org.apache.doris.catalog.TabletMeta;
47+
import org.apache.doris.catalog.View;
4748
import org.apache.doris.cluster.ClusterNamespace;
4849
import org.apache.doris.common.AnalysisException;
4950
import org.apache.doris.common.AuthenticationException;
@@ -629,6 +630,9 @@ public TListTableStatusResult listTableStatus(TGetTablesParams params) throws TE
629630
status.setRows(table.getCachedRowCount());
630631
status.setDataLength(table.getDataLength());
631632
status.setAvgRowLength(table.getAvgRowLength());
633+
if (table instanceof View) {
634+
status.setDdlSql(((View) table).getInlineViewDef());
635+
}
632636
tablesResult.add(status);
633637
} finally {
634638
table.readUnlock();

‎regression-test/data/external_table_p0/hive/test_information_schema_external.out

Copy file name to clipboardExpand all lines: regression-test/data/external_table_p0/hive/test_information_schema_external.out
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ test_information_schema_external_hive2 tpch1_parquet orders BASE TABLE hms 0 \N
127127
test_information_schema_external_hive2 tpch1_parquet partsupp BASE TABLE hms 0 \N
128128

129129
-- !views_1 --
130-
\N info_schema_ext_db test_view NONE NO root@% DEFINER utf8 \N
130+
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
131131

132132
-- !views_2 --
133133

@@ -259,7 +259,7 @@ test_information_schema_external_hive3 tpch1_parquet orders BASE TABLE hms 0 \N
259259
test_information_schema_external_hive3 tpch1_parquet partsupp BASE TABLE hms 0 \N
260260

261261
-- !views_1 --
262-
\N info_schema_ext_db test_view NONE NO root@% DEFINER utf8 \N
262+
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
263263

264264
-- !views_2 --
265265

‎regression-test/data/nereids_p0/system/test_query_sys_tables.out

Copy file name to clipboardExpand all lines: regression-test/data/nereids_p0/system/test_query_sys_tables.out
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ wait_timeout 31000
3939
'nereids_test_sys_tables'@'%' SELECT NO
4040

4141
-- !views --
42-
test_view
42+
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`
4343

‎regression-test/data/query_p0/system/test_query_sys_tables.out

Copy file name to clipboardExpand all lines: regression-test/data/query_p0/system/test_query_sys_tables.out
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ wait_timeout 31000
200200
'original_test_sys_tables'@'%' SELECT NO
201201

202202
-- !views --
203-
test_view
203+
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`
204204

205205
-- !sql --
206206

‎regression-test/data/view_p0/view_p0.out

Copy file name to clipboardExpand all lines: regression-test/data/view_p0/view_p0.out
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
-- !sql --
99
1
1010

11+
-- !information_schema1 --
12+
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
13+
14+
-- !information_schema2 --
15+
internal regression_test_view_p0 test_view select 1,to_base64(AES_ENCRYPT('doris','doris')) NONE NO root@% DEFINER utf8 \N
16+
1117
-- !sql --
1218
1 2023-08-01 DORID_FIELD1 DORID_FIELD2 ["cat", "dog"] cat
1319
1 2023-08-01 DORID_FIELD1 DORID_FIELD2 ["cat", "dog"] dog

‎regression-test/suites/view_p0/view_p0.groovy

Copy file name to clipboardExpand all lines: regression-test/suites/view_p0/view_p0.groovy
+17-13Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,30 @@ suite("view_p0") {
2121
create view test_view as select 1,to_base64(AES_ENCRYPT('doris','doris'));
2222
"""
2323
qt_sql "select * from test_view;"
24-
24+
2525
sql """DROP TABLE IF EXISTS test_view_table"""
26-
26+
2727
sql """
2828
create table test_view_table (id int) distributed by hash(id) properties('replication_num'='1');
2929
"""
30-
30+
3131
sql """insert into test_view_table values(1);"""
32-
32+
3333
sql """DROP VIEW IF EXISTS test_varchar_view"""
34-
34+
3535
sql """
3636
create view test_varchar_view (id) as SELECT GROUP_CONCAT(cast( id as varchar)) from test_view_table;
3737
"""
38-
38+
3939
qt_sql "select * from test_varchar_view;"
4040
qt_sql "select cast( id as varchar(65533)) from test_view_table;"
41-
41+
42+
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;"
43+
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;"
44+
4245
// array view
4346
sql """DROP TABLE IF EXISTS test_array_tbl_1"""
44-
47+
4548
sql """
4649
CREATE TABLE `test_array_tbl_1` (
4750
`id` int(11) NULL COMMENT "",
@@ -60,7 +63,7 @@ suite("view_p0") {
6063
"storage_format" = "V2"
6164
);
6265
"""
63-
66+
6467
sql """DROP TABLE IF EXISTS test_array_tbl_2"""
6568
sql """
6669
CREATE TABLE `test_array_tbl_2` (
@@ -81,11 +84,11 @@ suite("view_p0") {
8184
);
8285
"""
8386
sql """INSERT into test_array_tbl_1 values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
84-
87+
8588
sql """INSERT into test_array_tbl_2 values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
86-
89+
8790
sql """DROP VIEW IF EXISTS test_element_at_view"""
88-
91+
8992
sql """
9093
CREATE VIEW test_element_at_view AS
9194
SELECT id, dm, pn, field3, ms, ek[sm] AS ek
@@ -138,7 +141,7 @@ suite("view_p0") {
138141
sql "drop view if exists test_view_abc;"
139142

140143
sql """DROP TABLE IF EXISTS test_view_table2"""
141-
144+
142145
sql """
143146
CREATE TABLE test_view_table2 (
144147
c_date varchar(50)
@@ -165,3 +168,4 @@ suite("view_p0") {
165168
sql """ drop view if exists test_view_table2_view;"""
166169
sql """DROP TABLE IF EXISTS test_view_table2"""
167170
}
171+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.