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。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM