Skip to content

Commit

Permalink
[FLINK-24939][table] Support SHOW CREATE CATALOG syntax
Browse files Browse the repository at this point in the history
This closes apache#24555
  • Loading branch information
liyubin117 authored Apr 7, 2024
1 parent 0b7f0fd commit 2747a58
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 10 deletions.
89 changes: 89 additions & 0 deletions docs/content.zh/docs/dev/table/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SHOW CREATE 语句用于打印给定对象的创建 DDL 语句。当前的 SHOW
目前 Flink SQL 支持下列 SHOW 语句:
- SHOW CATALOGS
- SHOW CURRENT CATALOG
- SHOW CREATE CATALOG
- SHOW DATABASES
- SHOW CURRENT DATABASE
- SHOW TABLES
Expand Down Expand Up @@ -102,6 +103,22 @@ tEnv.executeSql("SHOW CURRENT CATALOG").print();
// | default_catalog |
// +----------------------+

// create a catalog
tEnv.executeSql("CREATE CATALOG cat2 WITH (...)");

// show create catalog
tEnv.executeSql("SHOW CREATE CATALOG cat2").print();
// +---------------------------------------------------------------------------------------------+
// | result |
// +---------------------------------------------------------------------------------------------+
// | CREATE CATALOG `cat2` WITH (
// 'default-database' = 'db',
// 'type' = 'generic_in_memory'
// )
// |
// +---------------------------------------------------------------------------------------------+
// 1 row in set

// show databases
tEnv.executeSql("SHOW DATABASES").print();
// +------------------+
Expand Down Expand Up @@ -214,6 +231,22 @@ tEnv.executeSql("SHOW CATALOGS").print()
// | default_catalog |
// +-----------------+

// create a catalog
tEnv.executeSql("CREATE CATALOG cat2 WITH (...)")

// show create catalog
tEnv.executeSql("SHOW CREATE CATALOG cat2").print()
// +---------------------------------------------------------------------------------------------+
// | result |
// +---------------------------------------------------------------------------------------------+
// | CREATE CATALOG `cat2` WITH (
// 'default-database' = 'db',
// 'type' = 'generic_in_memory'
// )
// |
// +---------------------------------------------------------------------------------------------+
// 1 row in set

// show databases
tEnv.executeSql("SHOW DATABASES").print()
// +------------------+
Expand Down Expand Up @@ -316,6 +349,22 @@ table_env.execute_sql("SHOW CATALOGS").print()
# | default_catalog |
# +-----------------+

# create a catalog
table_env.execute_sql("CREATE CATALOG cat2 WITH (...)")

# show create catalog
table_env.execute_sql("SHOW CREATE CATALOG cat2").print()
# +---------------------------------------------------------------------------------------------+
# | result |
# +---------------------------------------------------------------------------------------------+
# | CREATE CATALOG `cat2` WITH (
# 'default-database' = 'db',
# 'type' = 'generic_in_memory'
# )
# |
# +---------------------------------------------------------------------------------------------+
# 1 row in set

# show databases
table_env.execute_sql("SHOW DATABASES").print()
# +------------------+
Expand Down Expand Up @@ -411,6 +460,14 @@ table_env.execute_sql("SHOW FULL MODULES").print()
Flink SQL> SHOW CATALOGS;
default_catalog

Flink SQL> CREATE CATALOG cat2 WITH (...);
[INFO] Execute statement succeeded.

Flink SQL> SHOW CREATE CATALOG cat2;
CREATE CATALOG `cat2` WITH (
...
)

Flink SQL> SHOW DATABASES;
default_database

Expand Down Expand Up @@ -504,6 +561,38 @@ SHOW CURRENT CATALOG

显示当前正在使用的 catalog。

## SHOW CREATE CATALOG

```sql
SHOW CREATE CATALOG catalog_name
```

展示一个现有 catalog 的创建语句。

该语句的输出内容包括 catalog 的名称和相关属性,使您可以直观地了解相应 catalog 的元数据。

假设 `cat2` 是按如下方式创建的:
```sql
create catalog cat2 WITH (
'type'='generic_in_memory',
'default-database'='db'
);
```
展示 catalog 创建语句。
```sql
show create catalog cat2;
+---------------------------------------------------------------------------------------------+
| result |
+---------------------------------------------------------------------------------------------+
| CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
|
+---------------------------------------------------------------------------------------------+
1 row in set
```

## SHOW DATABASES

```sql
Expand Down
89 changes: 89 additions & 0 deletions docs/content/docs/dev/table/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SHOW CREATE statements are used to print a DDL statement with which a given obje
Flink SQL supports the following SHOW statements for now:
- SHOW CATALOGS
- SHOW CURRENT CATALOG
- SHOW CREATE CATALOG
- SHOW DATABASES
- SHOW CURRENT DATABASE
- SHOW TABLES
Expand Down Expand Up @@ -102,6 +103,22 @@ tEnv.executeSql("SHOW CURRENT CATALOG").print();
// | default_catalog |
// +----------------------+

// create a catalog
tEnv.executeSql("CREATE CATALOG cat2 WITH (...)");

// show create catalog
tEnv.executeSql("SHOW CREATE CATALOG cat2").print();
// +---------------------------------------------------------------------------------------------+
// | result |
// +---------------------------------------------------------------------------------------------+
// | CREATE CATALOG `cat2` WITH (
// 'default-database' = 'db',
// 'type' = 'generic_in_memory'
// )
// |
// +---------------------------------------------------------------------------------------------+
// 1 row in set

// show databases
tEnv.executeSql("SHOW DATABASES").print();
// +------------------+
Expand Down Expand Up @@ -214,6 +231,22 @@ tEnv.executeSql("SHOW CATALOGS").print()
// | default_catalog |
// +-----------------+

// create a catalog
tEnv.executeSql("CREATE CATALOG cat2 WITH (...)")

// show create catalog
tEnv.executeSql("SHOW CREATE CATALOG cat2").print()
// +---------------------------------------------------------------------------------------------+
// | result |
// +---------------------------------------------------------------------------------------------+
// | CREATE CATALOG `cat2` WITH (
// 'default-database' = 'db',
// 'type' = 'generic_in_memory'
// )
// |
// +---------------------------------------------------------------------------------------------+
// 1 row in set

// show databases
tEnv.executeSql("SHOW DATABASES").print()
// +------------------+
Expand Down Expand Up @@ -316,6 +349,22 @@ table_env.execute_sql("SHOW CATALOGS").print()
# | default_catalog |
# +-----------------+

# create a catalog
table_env.execute_sql("CREATE CATALOG cat2 WITH (...)")

# show create catalog
table_env.execute_sql("SHOW CREATE CATALOG cat2").print()
# +---------------------------------------------------------------------------------------------+
# | result |
# +---------------------------------------------------------------------------------------------+
# | CREATE CATALOG `cat2` WITH (
# 'default-database' = 'db',
# 'type' = 'generic_in_memory'
# )
# |
# +---------------------------------------------------------------------------------------------+
# 1 row in set

# show databases
table_env.execute_sql("SHOW DATABASES").print()
# +------------------+
Expand Down Expand Up @@ -411,6 +460,14 @@ table_env.execute_sql("SHOW FULL MODULES").print()
Flink SQL> SHOW CATALOGS;
default_catalog

Flink SQL> CREATE CATALOG cat2 WITH (...);
[INFO] Execute statement succeeded.

Flink SQL> SHOW CREATE CATALOG cat2;
CREATE CATALOG `cat2` WITH (
...
)

Flink SQL> SHOW DATABASES;
default_database

Expand Down Expand Up @@ -504,6 +561,38 @@ SHOW CURRENT CATALOG

Show current catalog.

## SHOW CREATE CATALOG

```sql
SHOW CREATE CATALOG catalog_name
```

Show creation statement for an existing catalog.

The output includes the catalog's name and relevant properties, which allows you to gain an intuitive understanding of the underlying catalog's metadata.

Assumes that the catalog `cat2` is created as follows:
```sql
create catalog cat2 WITH (
'type'='generic_in_memory',
'default-database'='db'
);
```
Shows the creation statement.
```sql
show create catalog cat2;
+---------------------------------------------------------------------------------------------+
| result |
+---------------------------------------------------------------------------------------------+
| CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
|
+---------------------------------------------------------------------------------------------+
1 row in set
```

## SHOW DATABASES

```sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,24 @@ show tables from db1 like 'p_r%';
+------------+
1 row in set
!ok

# ==========================================================================
# test catalog
# ==========================================================================

create catalog cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
[INFO] Execute statement succeeded.
!info

show create catalog cat2;
+---------------------------------------------------------------------------------------------+
| result |
+---------------------------------------------------------------------------------------------+
| CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
|
+---------------------------------------------------------------------------------------------+
1 row in set
!ok
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,25 @@ show tables from db1 like 'p_r%';
+------------+
1 row in set
!ok

# ==========================================================================
# test catalog
# ==========================================================================

create catalog cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
!output
+--------+
| result |
+--------+
| OK |
+--------+
1 row in set
!ok

show create catalog cat2;
!output
CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
!ok
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"org.apache.flink.sql.parser.dql.SqlShowCreate"
"org.apache.flink.sql.parser.dql.SqlShowCreateTable"
"org.apache.flink.sql.parser.dql.SqlShowCreateView"
"org.apache.flink.sql.parser.dql.SqlShowCreateCatalog"
"org.apache.flink.sql.parser.dql.SqlShowViews"
"org.apache.flink.sql.parser.dql.SqlRichDescribeTable"
"org.apache.flink.sql.parser.dql.SqlUnloadModule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ SqlShowViews SqlShowViews() :
}

/**
* SHOW TABLES FROM [catalog.] database sql call.
* Parses a show tables statement.
* SHOW TABLES [ ( FROM | IN ) [catalog_name.]database_name ] [ [NOT] LIKE pattern ];
*/
SqlShowTables SqlShowTables() :
{
Expand Down Expand Up @@ -653,7 +654,7 @@ SqlShowColumns SqlShowColumns() :
}

/**
* Parse a "Show Create Table" query and "Show Create View" query commands.
* Parse a "Show Create Table" query and "Show Create View" and "Show Create Catalog" query commands.
*/
SqlShowCreate SqlShowCreate() :
{
Expand All @@ -676,6 +677,13 @@ SqlShowCreate SqlShowCreate() :
{
return new SqlShowCreateView(pos, sqlIdentifier);
}
|
<CATALOG>
{ pos = getPos(); }
sqlIdentifier = SimpleIdentifier()
{
return new SqlShowCreateCatalog(pos, sqlIdentifier);
}
)
}

Expand Down
Loading

0 comments on commit 2747a58

Please sign in to comment.