Skip to content

Commit

Permalink
[FLINK-21579][table-api] Support "SHOW USER FUNCTIONS" statement in T…
Browse files Browse the repository at this point in the history
…able API and SQL Client

This closes apache#15110
  • Loading branch information
yulei0824 committed Mar 15, 2021
1 parent 4751f2e commit 36366f7
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 1,024 deletions.
49 changes: 46 additions & 3 deletions docs/content.zh/docs/dev/table/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.



SHOW 语句用于列出所有的 catalog,或者列出当前 catalog 中所有的 database,或者列出当前 catalog 和当前 database 的所有表或视图,或者列出当前正在使用的 catalog 和 database, 或者列出所有的 function,包括:临时系统 function,系统 function,临时 catalog function,当前 catalog database 中的 catalog function。
SHOW 语句用于列出所有的 catalog,或者列出当前 catalog 中所有的 database,或者列出当前 catalog 和当前 database 的所有表或视图,或者列出当前正在使用的 catalog 和 database, 或者列出当前 catalog 和当前 database 中所有的 function,包括:系统 function 和用户定义的 function,或者仅仅列出当前 catalog 和当前 database 中用户定义的 function。

目前 Flink SQL 支持下列 SHOW 语句:
- SHOW CATALOGS
Expand Down Expand Up @@ -138,6 +138,17 @@ tEnv.executeSql("SHOW FUNCTIONS").print();
// | ... |
// +---------------+

// create a user defined function
tEnv.executeSql("CREATE FUNCTION f1 AS ...");
// show user defined functions
tEnv.executeSql("SHOW USER FUNCTIONS").print();
// +---------------+
// | function name |
// +---------------+
// | f1 |
// | ... |
// +---------------+

```
{{< /tab >}}
{{< tab "Scala" >}}
Expand Down Expand Up @@ -191,6 +202,17 @@ tEnv.executeSql("SHOW FUNCTIONS").print()
// | ... |
// +---------------+

// create a user defined function
tEnv.executeSql("CREATE FUNCTION f1 AS ...")
// show user defined functions
tEnv.executeSql("SHOW USER FUNCTIONS").print()
// +---------------+
// | function name |
// +---------------+
// | f1 |
// | ... |
// +---------------+

```
{{< /tab >}}
{{< tab "Python" >}}
Expand Down Expand Up @@ -244,6 +266,17 @@ table_env.execute_sql("SHOW FUNCTIONS").print()
# | ... |
# +---------------+

# create a user defined function
table_env.execute_sql("CREATE FUNCTION f1 AS ...")
# show user defined functions
table_env.execute_sql("SHOW USER FUNCTIONS").print()
# +---------------+
# | function name |
# +---------------+
# | f1 |
# | ... |
# +---------------+

```
{{< /tab >}}
{{< tab "SQL CLI" >}}
Expand Down Expand Up @@ -272,6 +305,13 @@ mod
sha256
...

Flink SQL> CREATE FUNCTION f1 AS ...;
[INFO] Function has been created.

Flink SQL> SHOW USER FUNCTIONS;
f1
...

```
{{< /tab >}}
{{< /tabs >}}
Expand Down Expand Up @@ -329,7 +369,10 @@ SHOW VIEWS
## SHOW FUNCTIONS

```sql
SHOW FUNCTIONS
SHOW [USER] FUNCTIONS
```

展示所有的 function,包括:临时系统 function, 系统 function, 临时 catalog function,当前 catalog 和 database 中的 catalog function。
展示当前 catalog 和当前 database 中所有的 function,包括:系统 function 和用户定义的 function。

**USER**
仅仅展示当前 catalog 和当前 database 中用户定义的 function。
49 changes: 46 additions & 3 deletions docs/content/docs/dev/table/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ under the License.

# SHOW Statements

SHOW statements are used to list all catalogs, or list all databases in the current catalog, or list all tables/views in the current catalog and the current database, or show current catalog and database, or list all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and the current database.
SHOW statements are used to list all catalogs, or list all databases in the current catalog, or list all tables/views in the current catalog and the current database, or show current catalog and database, or list all functions including system functions and user-defined functions in the current catalog and current database, or list only user-defined functions in the current catalog and current database.

Flink SQL supports the following SHOW statements for now:
- SHOW CATALOGS
Expand Down Expand Up @@ -138,6 +138,17 @@ tEnv.executeSql("SHOW FUNCTIONS").print();
// | ... |
// +---------------+

// create a user defined function
tEnv.executeSql("CREATE FUNCTION f1 AS ...");
// show user defined functions
tEnv.executeSql("SHOW USER FUNCTIONS").print();
// +---------------+
// | function name |
// +---------------+
// | f1 |
// | ... |
// +---------------+

```
{{< /tab >}}
{{< tab "Scala" >}}
Expand Down Expand Up @@ -191,6 +202,17 @@ tEnv.executeSql("SHOW FUNCTIONS").print()
// | ... |
// +---------------+

// create a user defined function
tEnv.executeSql("CREATE FUNCTION f1 AS ...")
// show user defined functions
tEnv.executeSql("SHOW USER FUNCTIONS").print()
// +---------------+
// | function name |
// +---------------+
// | f1 |
// | ... |
// +---------------+

```
{{< /tab >}}
{{< tab "Python" >}}
Expand Down Expand Up @@ -244,6 +266,17 @@ table_env.execute_sql("SHOW FUNCTIONS").print()
# | ... |
# +---------------+

# create a user defined function
table_env.execute_sql("CREATE FUNCTION f1 AS ...")
# show user defined functions
table_env.execute_sql("SHOW USER FUNCTIONS").print()
# +---------------+
# | function name |
# +---------------+
# | f1 |
# | ... |
# +---------------+

```
{{< /tab >}}
{{< tab "SQL CLI" >}}
Expand Down Expand Up @@ -272,6 +305,13 @@ mod
sha256
...

Flink SQL> CREATE FUNCTION f1 AS ...;
[INFO] Function has been created.

Flink SQL> SHOW USER FUNCTIONS;
f1
...

```
{{< /tab >}}
{{< /tabs >}}
Expand Down Expand Up @@ -329,7 +369,10 @@ Show all views in the current catalog and the current database.
## SHOW FUNCTIONS

```sql
SHOW FUNCTIONS
SHOW [USER] FUNCTIONS
```

Show all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and current database.
Show all functions including system functions and user-defined functions in the current catalog and current database.

**USER**
Show only user-defined functions in the current catalog and current database.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private void callCommand(SqlCommandCall cmdCall) {
callShowViews();
break;
case SHOW_FUNCTIONS:
callShowFunctions();
callShowFunctions(cmdCall);
break;
case SHOW_MODULES:
callShowModules(cmdCall);
Expand Down Expand Up @@ -568,10 +568,10 @@ private void callShowViews() {
terminal.flush();
}

private void callShowFunctions() {
private void callShowFunctions(SqlCommandCall cmdCall) {
final List<String> functions;
try {
functions = getShowResult("FUNCTIONS");
functions = getShowResult(cmdCall);
} catch (SqlExecutionException e) {
printExecutionException(e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private CliStrings() {
.append(
formatCommand(
SqlCommand.SHOW_FUNCTIONS,
"Shows all user-defined and built-in functions."))
"Shows all user-defined and built-in functions or only user-defined functions. Syntax: 'SHOW [USER] FUNCTIONS;'"))
.append(formatCommand(SqlCommand.SHOW_TABLES, "Shows all registered tables."))
.append(
formatCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private static SqlCommandCall parseBySqlParser(Parser sqlParser, String stmt) {
operands = new String[0];
} else if (operation instanceof ShowFunctionsOperation) {
cmd = SqlCommand.SHOW_FUNCTIONS;
operands = new String[0];
} else if (operation instanceof ShowPartitionsOperation) {
cmd = SqlCommand.SHOW_PARTITIONS;
} else if (operation instanceof CreateCatalogFunctionOperation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ public void testCommands() throws Exception {
// show full modules
TestItem.validSql(
"SHOW FULL MODULES", SqlCommand.SHOW_MODULES, "SHOW FULL MODULES"),
// show functions
TestItem.validSql(
"SHOW FUNCTIONS;", SqlCommand.SHOW_FUNCTIONS, "SHOW FUNCTIONS"),
TestItem.validSql(
" SHOW FUNCTIONS ;",
SqlCommand.SHOW_FUNCTIONS,
"SHOW FUNCTIONS"),
// show user functions
TestItem.validSql(
"SHOW USER FUNCTIONS;",
SqlCommand.SHOW_FUNCTIONS,
"SHOW USER FUNCTIONS"),
TestItem.validSql(
" SHOW USER FUNCTIONS ;",
SqlCommand.SHOW_FUNCTIONS,
"SHOW USER FUNCTIONS"),
// Test create function.
TestItem.invalidSql(
"CREATE FUNCTION ",
Expand Down
Loading

0 comments on commit 36366f7

Please sign in to comment.