Flink基础(三十二):FLINK-SQL语法(八)DDL(四)DESCRIBE 语句
DESCRIBE 语句用来描述一张表或者视图的 Schema。
执行 DESCRIBE 语句
DESCRIBE 语句可以通过 TableEnvironment
的 executeSql()
执行,也可以在 SQL CLI 中执行 DROP 语句。 若 DESCRIBE 操作执行成功,executeSql() 方法返回该表的 Schema,否则会抛出异常。
以下的例子展示了如何在 TableEnvironment 和 SQL CLI 中执行一个 DESCRIBE 语句。
val settings = EnvironmentSettings.newInstance()... val tableEnv = TableEnvironment.create(settings) // register a table named "Orders" tableEnv.executeSql( "CREATE TABLE Orders (" + " `user` BIGINT NOT NULl," + " product VARCHAR(32)," + " amount INT," + " ts TIMESTAMP(3)," + " ptime AS PROCTIME()," + " PRIMARY KEY(`user`) NOT ENFORCED," + " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" + ") with (...)") // print the schema tableEnv.executeSql("DESCRIBE Orders").print()
Flink SQL> CREATE TABLE Orders ( > `user` BIGINT NOT NULl, > product VARCHAR(32), > amount INT, > ts TIMESTAMP(3), > ptime AS PROCTIME(), > PRIMARY KEY(`user`) NOT ENFORCED, > WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS > ) with ( > ... > ); [INFO] Table has been created. Flink SQL> DESCRIBE Orders;
+---------+----------------------------------+-------+-----------+-----------------+----------------------------+
| name | type | null | key | computed column | watermark |
+---------+----------------------------------+-------+-----------+-----------------+----------------------------+
| user | BIGINT | false | PRI(user) | | |
| product | VARCHAR(32) | true | | | |
| amount | INT | true | | | |
| ts | TIMESTAMP(3) *ROWTIME* | true | | | `ts` - INTERVAL '1' SECOND |
| ptime | TIMESTAMP(3) NOT NULL *PROCTIME* | false | | PROCTIME() | |
+---------+----------------------------------+-------+-----------+-----------------+----------------------------+
5 rows in set
root
|-- user: BIGINT NOT NULL
|-- product: VARCHAR(32)
|-- amount: INT
|-- ts: TIMESTAMP(3) *ROWTIME*
|-- ptime: TIMESTAMP(3) NOT NULL *PROCTIME* AS PROCTIME()
|-- WATERMARK FOR ts AS `ts` - INTERVAL '1' SECOND
|-- CONSTRAINT PK_3599338 PRIMARY KEY (user)
语法
DESCRIBE [catalog_name.][db_name.]table_name
本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/14053384.html