DESCRIBE 语句

DESCRIBE 语句用于描述表或视图的 schema,或catalog 的元数据,或 Flink 集群上的指定作业。

执行 DESCRIBE 语句

Java

可以使用 TableEnvironmentexecuteSql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,executeSql() 方法会返回所有对象,否则会抛出异常。

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

Scala

可以使用 TableEnvironmentexecuteSql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,executeSql() 方法会返回所有对象,否则会抛出异常。

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

Python

可以使用 TableEnvironmentexecute_sql() 方法执行 DESCRIBE 语句。如果 DESCRIBE 操作执行成功,execute_sql() 方法会返回所有对象,否则会抛出异常。

以下示例展示了如何在 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 comment 'this is primary key'," +
  6. " product VARCHAR(32)," +
  7. " amount INT," +
  8. " ts TIMESTAMP(3) comment 'notice: watermark'," +
  9. " ptime AS PROCTIME() comment 'this is a computed column'," +
  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();
  17. // 注册名为 “cat2” 的 catalog
  18. tableEnv.executeSql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')");
  19. // 打印元数据
  20. tableEnv.executeSql("DESCRIBE CATALOG cat2").print();
  21. // 打印完整的元数据
  22. tableEnv.executeSql("DESC CATALOG EXTENDED cat2").print();

Scala

  1. val tableEnv = TableEnvironment.create(...)
  2. // 注册名为 “Orders” 的表
  3. tableEnv.executeSql(
  4. "CREATE TABLE Orders (" +
  5. " `user` BIGINT NOT NULl comment 'this is primary key'," +
  6. " product VARCHAR(32)," +
  7. " amount INT," +
  8. " ts TIMESTAMP(3) comment 'notice: watermark'," +
  9. " ptime AS PROCTIME() comment 'this is a computed column'," +
  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()
  17. // 注册名为 “cat2” 的 catalog
  18. tableEnv.executeSql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')")
  19. // 打印元数据
  20. tableEnv.executeSql("DESCRIBE CATALOG cat2").print()
  21. // 打印完整的元数据
  22. tableEnv.executeSql("DESC CATALOG EXTENDED cat2").print()

Python

  1. table_env = TableEnvironment.create(...)
  2. # 注册名为 “Orders” 的表
  3. table_env.execute_sql( \
  4. "CREATE TABLE Orders ("
  5. " `user` BIGINT NOT NULl comment 'this is primary key',"
  6. " product VARCHAR(32),"
  7. " amount INT,"
  8. " ts TIMESTAMP(3) comment 'notice: watermark',"
  9. " ptime AS PROCTIME() comment 'this is a computed column',"
  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()
  17. # 注册名为 “cat2” 的 catalog
  18. table_env.execute_sql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')")
  19. # 打印元数据
  20. table_env.execute_sql("DESCRIBE CATALOG cat2").print()
  21. # 打印完整的元数据
  22. table_env.execute_sql("DESC CATALOG EXTENDED cat2").print()

SQL CLI

  1. Flink SQL> CREATE TABLE Orders (
  2. > `user` BIGINT NOT NULl comment 'this is primary key',
  3. > product VARCHAR(32),
  4. > amount INT,
  5. > ts TIMESTAMP(3) comment 'notice: watermark',
  6. > ptime AS PROCTIME() comment 'this is a computed column',
  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;
  15. Flink SQL> CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
  16. [INFO] Execute statement succeeded.
  17. Flink SQL> DESCRIBE CATALOG cat2;
  18. Flink SQL> DESC CATALOG EXTENDED cat2;
  19. Flink SQL> DESCRIBE JOB '228d70913eab60dda85c5e7f78b5782c';
  20. Flink SQL> DESC JOB '228d70913eab60dda85c5e7f78b5782c';

上述示例的结果是:

Java

  1. # DESCRIBE TABLE Orders
  2. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  3. | name | type | null | key | extras | watermark | comment |
  4. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  5. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  6. | product | VARCHAR(32) | TRUE | | | | |
  7. | amount | INT | TRUE | | | | |
  8. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  9. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  10. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  11. 5 rows in set
  12. # DESCRIBE CATALOG cat2
  13. +-----------+-------------------+
  14. | info name | info value |
  15. +-----------+-------------------+
  16. | name | cat2 |
  17. | type | generic_in_memory |
  18. | comment | |
  19. +-----------+-------------------+
  20. 3 rows in set
  21. # DESCRIBE CATALOG EXTENDED cat2
  22. +-------------------------+-------------------+
  23. | info name | info value |
  24. +-------------------------+-------------------+
  25. | name | cat2 |
  26. | type | generic_in_memory |
  27. | comment | |
  28. | option:default-database | db |
  29. +-------------------------+-------------------+
  30. 4 rows in set

Scala

  1. # DESCRIBE TABLE Orders
  2. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  3. | name | type | null | key | extras | watermark | comment |
  4. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  5. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  6. | product | VARCHAR(32) | TRUE | | | | |
  7. | amount | INT | TRUE | | | | |
  8. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  9. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  10. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  11. 5 rows in set
  12. # DESCRIBE CATALOG cat2
  13. +-----------+-------------------+
  14. | info name | info value |
  15. +-----------+-------------------+
  16. | name | cat2 |
  17. | type | generic_in_memory |
  18. | comment | |
  19. +-----------+-------------------+
  20. 3 rows in set
  21. # DESCRIBE CATALOG EXTENDED cat2
  22. +-------------------------+-------------------+
  23. | info name | info value |
  24. +-------------------------+-------------------+
  25. | name | cat2 |
  26. | type | generic_in_memory |
  27. | comment | |
  28. | option:default-database | db |
  29. +-------------------------+-------------------+
  30. 4 rows in set

Python

  1. # DESCRIBE TABLE Orders
  2. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  3. | name | type | null | key | extras | watermark | comment |
  4. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  5. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  6. | product | VARCHAR(32) | TRUE | | | | |
  7. | amount | INT | TRUE | | | | |
  8. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  9. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  10. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  11. 5 rows in set
  12. # DESCRIBE CATALOG cat2
  13. +-----------+-------------------+
  14. | info name | info value |
  15. +-----------+-------------------+
  16. | name | cat2 |
  17. | type | generic_in_memory |
  18. | comment | |
  19. +-----------+-------------------+
  20. 3 rows in set
  21. # DESCRIBE CATALOG EXTENDED cat2
  22. +-------------------------+-------------------+
  23. | info name | info value |
  24. +-------------------------+-------------------+
  25. | name | cat2 |
  26. | type | generic_in_memory |
  27. | comment | |
  28. | option:default-database | db |
  29. +-------------------------+-------------------+
  30. 4 rows in set

SQL CLI

  1. # DESCRIBE TABLE Orders
  2. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  3. | name | type | null | key | extras | watermark | comment |
  4. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  5. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  6. | product | VARCHAR(32) | TRUE | | | | |
  7. | amount | INT | TRUE | | | | |
  8. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  9. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  10. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  11. 5 rows in set
  12. # DESCRIBE CATALOG cat2
  13. +-----------+-------------------+
  14. | info name | info value |
  15. +-----------+-------------------+
  16. | name | cat2 |
  17. | type | generic_in_memory |
  18. | comment | |
  19. +-----------+-------------------+
  20. 3 rows in set
  21. # DESCRIBE CATALOG EXTENDED cat2
  22. +-------------------------+-------------------+
  23. | info name | info value |
  24. +-------------------------+-------------------+
  25. | name | cat2 |
  26. | type | generic_in_memory |
  27. | comment | |
  28. | option:default-database | db |
  29. +-------------------------+-------------------+
  30. 4 rows in set
  31. # DESCRIBE JOB '228d70913eab60dda85c5e7f78b5782c'
  32. +----------------------------------+----------+---------+-------------------------+
  33. | job id | job name | status | start time |
  34. +----------------------------------+----------+---------+-------------------------+
  35. | 228d70913eab60dda85c5e7f78b5782c | myjob | RUNNING | 2023-02-11T05:03:51.523 |
  36. +----------------------------------+----------+---------+-------------------------+
  37. 1 row in set

语法

DESCRIBE TABLE

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

DESCRIBE CATALOG

  1. { DESCRIBE | DESC } CATALOG [EXTENDED] catalog_name

DESCRIBE JOB

  1. { DESCRIBE | DESC } JOB '<job_id>'

Attention DESCRIBE JOB 语句仅适用于 SQL CLI 或者 SQL Gateway.