Flink基础(三十五):FLINK-SQL语法(十一)DDL(七)SHOW 语句

0 简介

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

目前 Flink SQL 支持下列 SHOW 语句:

  • SHOW CATALOGS
  • SHOW DATABASES
  • SHOW TABLES
  • SHOW VIEWS
  • SHOW FUNCTIONS

1 执行 SHOW 语句

可以使用 TableEnvironment 中的 executeSql() 方法执行 SHOW 语句,也可以在 SQL CLI 中执行 SHOW 语句。 若 SHOW 操作执行成功,executeSql() 方法返回所有对象,否则会抛出异常。

以下的例子展示了如何在 TableEnvironment 和 SQL CLI 中执行一个 SHOW 语句。

val env = StreamExecutionEnvironment.getExecutionEnvironment()
val tEnv = StreamTableEnvironment.create(env)

// show catalogs
tEnv.executeSql("SHOW CATALOGS").print()
// +-----------------+
// |    catalog name |
// +-----------------+
// | default_catalog |
// +-----------------+

// show databases
tEnv.executeSql("SHOW DATABASES").print()
// +------------------+
// |    database name |
// +------------------+
// | default_database |
// +------------------+

// create a table
tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)")
// show tables
tEnv.executeSql("SHOW TABLES").print()
// +------------+
// | table name |
// +------------+
// |   my_table |
// +------------+

// create a view
tEnv.executeSql("CREATE VIEW my_view AS ...")
// show views
tEnv.executeSql("SHOW VIEWS").print()
// +-----------+
// | view name |
// +-----------+
// |   my_view |
// +-----------+

// show functions
tEnv.executeSql("SHOW FUNCTIONS").print()
// +---------------+
// | function name |
// +---------------+
// |           mod |
// |        sha256 |
// |           ... |
// +---------------+
Flink SQL> SHOW CATALOGS;
default_catalog

Flink SQL> SHOW DATABASES;
default_database

Flink SQL> CREATE TABLE my_table (...) WITH (...);
[INFO] Table has been created.

Flink SQL> SHOW TABLES;
my_table

Flink SQL> CREATE VIEW my_view AS ...;
[INFO] View has been created.

Flink SQL> SHOW VIEWS;
my_view

Flink SQL> SHOW FUNCTIONS;
mod
sha256
...

SHOW CATALOGS

SHOW CATALOGS

展示所有的 catalog。

SHOW DATABASES

SHOW DATABASES

展示当前 catalog 中所有的 database。

SHOW TABLES

SHOW TABLES

展示当前 catalog 和当前 database 中所有的表。

SHOW VIEWS

SHOW VIEWS

展示当前 catalog 和当前 database 中所有的视图。

SHOW FUNCTIONS

SHOW FUNCTIONS

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

本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/14053441.html

原文地址:https://www.cnblogs.com/qiu-hua/p/14053441.html