zoukankan      html  css  js  c++  java
  • Flink基础(三十二):FLINK-SQL语法(八)DDL(四)DESCRIBE 语句

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

    执行 DESCRIBE 语句

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

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

    val settings = EnvironmentSettings.newInstance()...
    val tableEnv = TableEnvironment.create(settings)
    
    // register a table named "Orders"
     tableEnv.executeSql(
            "CREATE TABLE Orders (" +
            " `user` BIGINT NOT NULl," +
            " product VARCHAR(32)," +
            " amount INT," +
            " ts TIMESTAMP(3)," +
            " ptime AS PROCTIME()," +
            " PRIMARY KEY(`user`) NOT ENFORCED," +
            " WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS" +
            ") with (...)")
    
    // print the schema
    tableEnv.executeSql("DESCRIBE Orders").print()
    Flink SQL> CREATE TABLE Orders (
    >  `user` BIGINT NOT NULl,
    >  product VARCHAR(32),
    >  amount INT,
    >  ts TIMESTAMP(3),
    >  ptime AS PROCTIME(),
    >  PRIMARY KEY(`user`) NOT ENFORCED,
    >  WATERMARK FOR ts AS ts - INTERVAL '1' SECONDS
    > ) with (
    >  ...
    > );
    [INFO] Table has been created.
    
    Flink SQL> DESCRIBE Orders;
    +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
    |    name |                             type |  null |       key | computed column |                  watermark |
    +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
    |    user |                           BIGINT | false | PRI(user) |                 |                            |
    | product |                      VARCHAR(32) |  true |           |                 |                            |
    |  amount |                              INT |  true |           |                 |                            |
    |      ts |           TIMESTAMP(3) *ROWTIME* |  true |           |                 | `ts` - INTERVAL '1' SECOND |
    |   ptime | TIMESTAMP(3) NOT NULL *PROCTIME* | false |           |      PROCTIME() |                            |
    +---------+----------------------------------+-------+-----------+-----------------+----------------------------+
    5 rows in set
    root
     |-- user: BIGINT NOT NULL
     |-- product: VARCHAR(32)
     |-- amount: INT
     |-- ts: TIMESTAMP(3) *ROWTIME*
     |-- ptime: TIMESTAMP(3) NOT NULL *PROCTIME* AS PROCTIME()
     |-- WATERMARK FOR ts AS `ts` - INTERVAL '1' SECOND
     |-- CONSTRAINT PK_3599338 PRIMARY KEY (user)

    语法

    DESCRIBE [catalog_name.][db_name.]table_name

    本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/14053384.html

  • 相关阅读:
    yzoj P2344 斯卡布罗集市 题解
    yzoj P2350 逃离洞穴 题解
    yzoj P2349 取数 题解
    JXOI 2017 颜色 题解
    NOIP 2009 最优贸易 题解
    CH 4302 Interval GCD 题解
    CH4301 Can you answer on these queries III 题解
    Luogu2533[AHOI2012]信号塔
    Luogu3320[SDOI2015]寻宝游戏
    Luogu3187[HNOI2007]最小矩形覆盖
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/14053384.html
Copyright © 2011-2022 走看看