DESCRIBE 语句

DESCRIBE 语句用来描述一张表或者视图的 Schema。

执行 DESCRIBE 语句

DESCRIBE 语句可以通过 TableEnvironmentexecuteSql() 执行。 若 DESCRIBE 操作执行成功,executeSql() 方法返回该表的 Schema,否则会抛出异常。

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

DESCRIBE 语句可以通过 TableEnvironmentexecute_sql() 执行。 若 DESCRIBE 操作执行成功,execute_sql() 方法返回该表的 Schema,否则会抛出异常。

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

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

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

  1. EnvironmentSettings settings = EnvironmentSettings.newInstance()...
  2. TableEnvironment tableEnv = TableEnvironment.create(settings);
  3. // register a table named "Orders"
  4. tableEnv.executeSql(
  5. "CREATE TABLE Orders (" +
  6. " `user` BIGINT NOT NULl," +
  7. " product VARCHAR(32)," +
  8. " amount INT," +
  9. " ts TIMESTAMP(3)," +
  10. " ptime AS PROCTIME()," +
  11. " PRIMARY KEY(`user`) NOT ENFORCED," +
  12. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
  13. ") with (...)");
  14. // print the schema
  15. tableEnv.executeSql("DESCRIBE Orders").print();
  1. val settings = EnvironmentSettings.newInstance()...
  2. val tableEnv = TableEnvironment.create(settings)
  3. // register a table named "Orders"
  4. tableEnv.executeSql(
  5. "CREATE TABLE Orders (" +
  6. " `user` BIGINT NOT NULl," +
  7. " product VARCHAR(32)," +
  8. " amount INT," +
  9. " ts TIMESTAMP(3)," +
  10. " ptime AS PROCTIME()," +
  11. " PRIMARY KEY(`user`) NOT ENFORCED," +
  12. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
  13. ") with (...)")
  14. // print the schema
  15. tableEnv.executeSql("DESCRIBE Orders").print()
  1. settings = EnvironmentSettings.new_instance()...
  2. table_env = StreamTableEnvironment.create(env, settings)
  3. # register a table named "Orders"
  4. table_env.execute_sql( \
  5. "CREATE TABLE Orders ("
  6. " `user` BIGINT NOT NULl,"
  7. " product VARCHAR(32),"
  8. " amount INT,"
  9. " ts TIMESTAMP(3),"
  10. " ptime AS PROCTIME(),"
  11. " PRIMARY KEY(`user`) NOT ENFORCED,"
  12. " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS"
  13. ") with (...)");
  14. # print the schema
  15. table_env.execute_sql("DESCRIBE Orders").print()
  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;

上述例子执行的结果为:

  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
  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
  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
  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 [catalog_name.][db_name.]table_name