DESCRIBE 문
DESCRIBE 문 (Statements)
DESCRIBE 문을 사용해 테이블·뷰의 스키마, 카탈로그·함수의 메타데이터, 또는 Flink 클러스터의 지정된 잡을 설명할 수 있어요.
본문
Run a DESCRIBE statement
DESCRIBE 문은 TableEnvironment의 executeSql() 메서드로 실행할 수 있어요. executeSql() 메서드는 성공적인 DESCRIBE 작업에 대해 객체를 반환하고, 그렇지 않으면 예외를 던져요.
다음 예시는 TableEnvironment에서 DESCRIBE 문을 실행하는 방법을 보여줘요.
Java
TableEnvironment tableEnv = TableEnvironment.create(...);
// register a table named "Orders"
tableEnv.executeSql(
"CREATE TABLE Orders (" +
" `user` BIGINT NOT NULl comment 'this is primary key'," +
" product VARCHAR(32)," +
" amount INT," +
" ts TIMESTAMP(3) comment 'notice: watermark'," +
" ptime AS PROCTIME() comment 'this is a computed column'," +
" PRIMARY KEY(`user`) NOT ENFORCED," +
" WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
") with (...)");
// print the schema
tableEnv.executeSql("DESCRIBE Orders").print();
// print the schema
tableEnv.executeSql("DESC Orders").print();
// register a catalog named "cat2"
tableEnv.executeSql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')");
// print the metadata
tableEnv.executeSql("DESCRIBE CATALOG cat2").print();
// print the complete metadata
tableEnv.executeSql("DESC CATALOG EXTENDED cat2").print();
// register a function named "MySum"
tableEnv.executeSql("CREATE FUNCTION MySum as 'org.example.SumScalarFunction' USING JAR 'file://home/users/mysum-udf.jar';").print();
// print the metadata
tableEnv.executeSql("DESCRIBE FUNCTION MySum").print();
// print the complete metadata
tableEnv.executeSql("DESC FUNCTION EXTENDED MySum").print();
Scala
val tableEnv = TableEnvironment.create(...)
// register a table named "Orders"
tableEnv.executeSql(
"CREATE TABLE Orders (" +
" `user` BIGINT NOT NULl comment 'this is primary key'," +
" product VARCHAR(32)," +
" amount INT," +
" ts TIMESTAMP(3) comment 'notice: watermark'," +
" ptime AS PROCTIME() comment 'this is a computed column'," +
" PRIMARY KEY(`user`) NOT ENFORCED," +
" WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
") with (...)")
// print the schema
tableEnv.executeSql("DESCRIBE Orders").print()
// print the schema
tableEnv.executeSql("DESC Orders").print()
// register a catalog named "cat2"
tableEnv.executeSql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')")
// print the metadata
tableEnv.executeSql("DESCRIBE CATALOG cat2").print()
// print the complete metadata
tableEnv.executeSql("DESC CATALOG EXTENDED cat2").print()
// register a function named "MySum"
tableEnv.executeSql("CREATE FUNCTION MySum as 'org.example.SumScalarFunction' USING JAR 'file://home/users/mysum-udf.jar';").print()
// print the metadata
tableEnv.executeSql("DESCRIBE FUNCTION MySum").print()
// print the complete metadata
tableEnv.executeSql("DESC FUNCTION EXTENDED MySum").print()
Python
table_env = TableEnvironment.create(...)
# register a table named "Orders"
table_env.execute_sql( \
"CREATE TABLE Orders ("
" `user` BIGINT NOT NULl comment 'this is primary key',"
" product VARCHAR(32),"
" amount INT,"
" ts TIMESTAMP(3) comment 'notice: watermark',"
" ptime AS PROCTIME() comment 'this is a computed column',"
" PRIMARY KEY(`user`) NOT ENFORCED,"
" WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS"
") with (...)");
# print the schema
table_env.execute_sql("DESCRIBE Orders").print()
# print the schema
table_env.execute_sql("DESC Orders").print()
# register a catalog named "cat2"
table_env.execute_sql("CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db')")
# print the metadata
table_env.execute_sql("DESCRIBE CATALOG cat2").print()
# print the complete metadata
table_env.execute_sql("DESC CATALOG EXTENDED cat2").print()
// register a function named "MySum"
table_env.execute_sql("CREATE FUNCTION MySum as 'org.example.SumScalarFunction' USING JAR 'file://home/users/mysum-udf.jar';").print()
# print the metadata
table_env.execute_sql("DESCRIBE FUNCTION MySum").print()
# print the complete metadata
table_env.execute_sql("DESC FUNCTION EXTENDED MySum").print()
SQL CLI
Flink SQL> CREATE TABLE Orders (
> `user` BIGINT NOT NULl comment 'this is primary key',
> product VARCHAR(32),
> amount INT,
> ts TIMESTAMP(3) comment 'notice: watermark',
> ptime AS PROCTIME() comment 'this is a computed column',
> PRIMARY KEY(`user`) NOT ENFORCED,
> WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS
> ) with (
> ...
> );
[INFO] Table has been created.
Flink SQL> DESCRIBE Orders;
Flink SQL> DESC Orders;
Flink SQL> CREATE CATALOG cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
[INFO] Execute statement succeeded.
Flink SQL> DESCRIBE CATALOG cat2;
Flink SQL> DESC CATALOG EXTENDED cat2;
Flink SQL> CREATE FUNCTION MySum as 'org.example.SumScalarFunction' USING JAR 'file://home/users/mysum-udf.jar';
Flink SQL> DESCRIBE FUNCTION MySum;
Flink SQL> DESC FUNCTION EXTENDED MySum;
Flink SQL> DESCRIBE JOB '228d70913eab60dda85c5e7f78b5782c';
Flink SQL> DESC JOB '228d70913eab60dda85c5e7f78b5782c';
위 예시의 결과는 다음과 같아요:
# DESCRIBE TABLE Orders
+---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
| name | type | null | key | extras | watermark | comment |
+---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
| user | BIGINT | FALSE | PRI(user) | | | this is primary key |
| product | VARCHAR(32) | TRUE | | | | |
| amount | INT | TRUE | | | | |
| ts | TIMESTAMP(3) *ROWTIME* | TRUE | | | `ts` - INTERVAL '1' SECOND | notice: watermark |
| ptime | TIMESTAMP_LTZ(3) *PROCTIME* | FALSE | | AS PROCTIME() | | this is a computed column |
+---------+-----------------------------+-------+-----------+---------------+----------------------------+---------------------------+
5 rows in set
# DESCRIBE CATALOG cat2
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
# DESCRIBE CATALOG EXTENDED cat2
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db |
+-------------------------+-------------------+
4 rows in set
# DESCRIBE FUNCTION MySum
+-------------------+---------------------------------------------------------------------+
| info name | info value |
+-------------------+---------------------------------------------------------------------+
| system function | false |
| temporary | false |
| class name | org.example.SumScalarFunction |
| function language | JAVA |
| resource uris | ResourceUri{resourceType=JAR, uri='file:/home/users/mysum-udf.jar'} |
+-------------------+---------------------------------------------------------------------+
5 rows in set
# DESCRIBE FUNCTION EXTENDED MySum
+-------------------+---------------------------------------------------------------------+
| info name | info value |
+-------------------+---------------------------------------------------------------------+
| system function | false |
| temporary | false |
| class name | org.example.SumScalarFunction |
| function language | JAVA |
| resource uris | ResourceUri{resourceType=JAR, uri='file:/home/users/mysum-udf.jar'} |
| kind | SCALAR |
| requirements | [] |
| deterministic | true |
| constant folding | true |
| signature | MySum(<INTEGER NOT NULL>, <INTEGER NOT NULL>) |
+-------------------+---------------------------------------------------------------------+
10 rows in set
DESCRIBE JOB의 결과:
# DESCRIBE JOB '228d70913eab60dda85c5e7f78b5782c'
+----------------------------------+----------+---------+-------------------------+
| job id | job name | status | start time |
+----------------------------------+----------+---------+-------------------------+
| 228d70913eab60dda85c5e7f78b5782c | myjob | RUNNING | 2023-02-11T05:03:51.523 |
+----------------------------------+----------+---------+-------------------------+
1 row in set
Syntax
DESCRIBE TABLE
{ DESCRIBE | DESC } [catalog_name.][db_name.]table_name
DESCRIBE CATALOG
{ DESCRIBE | DESC } CATALOG [EXTENDED] catalog_name
DESCRIBE FUNCTION
{ DESCRIBE | DESC } FUNCTION [EXTENDED] [catalog_name.][db_name.]function_name
DESCRIBE JOB
{ DESCRIBE | DESC } JOB '<job_id>'
주의: DESCRIBE JOB 문은 SQL CLI 또는 SQL Gateway에서만 작동해요.
DESCRIBE MODEL
{ DESCRIBE | DESC } MODEL [EXTENDED] [catalog_name.][db_name.]model_name