DESCRIBE 语句

DESCRIBE 语句用于描述表或视图的 schema。

执行 DESCRIBE 语句

Java

可以使用 TableEnvironmentexecuteSql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,executeSql() 方法会返回给定表的 schema,否则会抛出异常。

以下示例展示了如何在 TableEnvironment 中执行一条 DESCRIBE 语句。

Scala

可以使用 TableEnvironmentexecuteSql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,executeSql() 方法会返回给定表的 schema,否则会抛出异常。

以下示例展示了如何在 TableEnvironment 中执行一条 DESCRIBE 语句。

Python

可以使用 TableEnvironmentexecute_sql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,execute_sql() 方法会返回给定表的 schema,否则会抛出异常。

以下示例展示了如何在 TableEnvironment 中执行一条 DESCRIBE 语句。

SQL CLI

DESCRIBE 语句可以在 SQL CLI 中执行。

以下示例展示了如何在 SQL CLI 中执行一条 DESCRIBE 语句。

Java

  1. TableEnvironment tableEnv = TableEnvironment.create(...);
  2. // 注册名为 “Orders” 的表
  3. tableEnv.executeSql(
  4. "CREATE TABLE Orders (" +
  5. " `user` BIGINT NOT NULl," +
  6. " product VARCHAR(32)," +
  7. " amount INT," +
  8. " ts TIMESTAMP(3)," +
  9. " ptime AS PROCTIME()," +
  10. " PRIMARY KEY(`user`) NOT ENFORCED," +
  11. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
  12. ") with (...)");
  13. // 打印 schema
  14. tableEnv.executeSql("DESCRIBE Orders").print();
  15. // 打印 schema
  16. tableEnv.executeSql("DESC Orders").print();

Scala

  1. val tableEnv = TableEnvironment.create(...)
  2. // 注册名为 “Orders” 的表
  3. tableEnv.executeSql(
  4. "CREATE TABLE Orders (" +
  5. " `user` BIGINT NOT NULl," +
  6. " product VARCHAR(32)," +
  7. " amount INT," +
  8. " ts TIMESTAMP(3)," +
  9. " ptime AS PROCTIME()," +
  10. " PRIMARY KEY(`user`) NOT ENFORCED," +
  11. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
  12. ") with (...)")
  13. // 打印 schema
  14. tableEnv.executeSql("DESCRIBE Orders").print()
  15. // 打印 schema
  16. tableEnv.executeSql("DESC Orders").print()

Python

  1. table_env = TableEnvironment.create(...)
  2. # 注册名为 “Orders” 的表
  3. table_env.execute_sql( \
  4. "CREATE TABLE Orders ("
  5. " `user` BIGINT NOT NULl,"
  6. " product VARCHAR(32),"
  7. " amount INT,"
  8. " ts TIMESTAMP(3),"
  9. " ptime AS PROCTIME(),"
  10. " PRIMARY KEY(`user`) NOT ENFORCED,"
  11. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS"
  12. ") with (...)");
  13. # 打印 schema
  14. table_env.execute_sql("DESCRIBE Orders").print()
  15. # 打印 schema
  16. table_env.execute_sql("DESC Orders").print()

SQL CLI

  1. Flink SQL> CREATE TABLE Orders (
  2. > `user` BIGINT NOT NULl,
  3. > product VARCHAR(32),
  4. > amount INT,
  5. > ts TIMESTAMP(3),
  6. > ptime AS PROCTIME(),
  7. > PRIMARY KEY(`user`) NOT ENFORCED,
  8. > WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS
  9. > ) with (
  10. > ...
  11. > );
  12. [INFO] Table has been created.
  13. Flink SQL> DESCRIBE Orders;
  14. Flink SQL> DESC Orders;

上述示例的结果是:

Java

  1. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  2. | name | type | null | key | computed column | watermark |
  3. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  4. | user | BIGINT | false | PRI(user) | | |
  5. | product | VARCHAR(32) | true | | | |
  6. | amount | INT | true | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | true | | | `ts` - INTERVAL '1' SECOND |
  8. | ptime | TIMESTAMP(3) NOT NULL *PROCTIME* | false | | PROCTIME() | |
  9. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  10. 5 rows in set

Scala

  1. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  2. | name | type | null | key | computed column | watermark |
  3. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  4. | user | BIGINT | false | PRI(user) | | |
  5. | product | VARCHAR(32) | true | | | |
  6. | amount | INT | true | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | true | | | `ts` - INTERVAL '1' SECOND |
  8. | ptime | TIMESTAMP(3) NOT NULL *PROCTIME* | false | | PROCTIME() | |
  9. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  10. 5 rows in set

Python

  1. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  2. | name | type | null | key | computed column | watermark |
  3. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  4. | user | BIGINT | false | PRI(user) | | |
  5. | product | VARCHAR(32) | true | | | |
  6. | amount | INT | true | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | true | | | `ts` - INTERVAL '1' SECOND |
  8. | ptime | TIMESTAMP(3) NOT NULL *PROCTIME* | false | | PROCTIME() | |
  9. +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
  10. 5 rows in set

SQL CLI

  1. root
  2. |-- user: BIGINT NOT NULL
  3. |-- product: VARCHAR(32)
  4. |-- amount: INT
  5. |-- ts: TIMESTAMP(3) *ROWTIME*
  6. |-- ptime: TIMESTAMP(3) NOT NULL *PROCTIME* AS PROCTIME()
  7. |-- WATERMARK FOR ts AS `ts` - INTERVAL '1' SECOND
  8. |-- CONSTRAINT PK_3599338 PRIMARY KEY (user)

语法

  1. { DESCRIBE | DESC } [catalog_name.][db_name.]table_name