DESCRIBE Statements

DESCRIBE statements are used to describe the schema of a table or a view.

Run a DESCRIBE statement

Java

DESCRIBE statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns the schema of given table for a successful DESCRIBE operation, otherwise will throw an exception.

The following examples show how to run a DESCRIBE statement in TableEnvironment.

Scala

DESCRIBE statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns the schema of given table for a successful DESCRIBE operation, otherwise will throw an exception.

The following examples show how to run a DESCRIBE statement in TableEnvironment.

Python

DESCRIBE statements can be executed with the execute_sql() method of the TableEnvironment. The execute_sql() method returns the schema of given table for a successful DESCRIBE operation, otherwise will throw an exception.

The following examples show how to run a DESCRIBE statement in TableEnvironment.

SQL CLI

DESCRIBE statements can be executed in SQL CLI.

The following examples show how to run a DESCRIBE statement in SQL CLI.

Java

  1. TableEnvironment tableEnv = TableEnvironment.create(...);
  2. // register a table named "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. // print the schema
  14. tableEnv.executeSql("DESCRIBE Orders").print();
  15. // print the schema
  16. tableEnv.executeSql("DESC Orders").print();

Scala

  1. val tableEnv = TableEnvironment.create(...)
  2. // register a table named "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. // print the schema
  14. tableEnv.executeSql("DESCRIBE Orders").print()
  15. // print the schema
  16. tableEnv.executeSql("DESC Orders").print()

Python

  1. table_env = TableEnvironment.create(...)
  2. # register a table named "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. # print the schema
  14. table_env.execute_sql("DESCRIBE Orders").print()
  15. # print the schema
  16. table_env.execute_sql("DESC Orders").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;

The result of the above example is:

Java

  1. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  2. | name | type | null | key | extras | watermark | comment |
  3. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  4. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  5. | product | VARCHAR(32) | TRUE | | | | |
  6. | amount | INT | TRUE | | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  8. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  9. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  10. 5 rows in set

Scala

  1. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  2. | name | type | null | key | extras | watermark | comment |
  3. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  4. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  5. | product | VARCHAR(32) | TRUE | | | | |
  6. | amount | INT | TRUE | | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  8. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  9. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  10. 5 rows in set

Python

  1. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  2. | name | type | null | key | extras | watermark | comment |
  3. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  4. | user | BIGINT | FALSE | PRI(user) | | | this is primary key |
  5. | product | VARCHAR(32) | TRUE | | | | |
  6. | amount | INT | TRUE | | | | |
  7. | ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
  8. | ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
  9. +---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
  10. 5 rows in set

SQL CLI

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

Syntax

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