Skip to content

Commit

Permalink
[FLINK-17635][docs][table] Add documentation about view support
Browse files Browse the repository at this point in the history
This closes apache#12502
  • Loading branch information
leonardBang authored Jun 8, 2020
1 parent b8c3033 commit 3952bfa
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 6 deletions.
20 changes: 20 additions & 0 deletions docs/dev/table/sql/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Flink SQL supports the following CREATE statements for now:

- CREATE TABLE
- CREATE DATABASE
- CREATE VIEW
- CREATE FUNCTION

## Run a CREATE statement
Expand Down Expand Up @@ -351,6 +352,25 @@ The key and value of expression `key1=val1` should both be string literal.

{% top %}

## CREATE VIEW
{% highlight sql %}
CREATE [TEMPORARY] VIEW [IF NOT EXISTS] [catalog_name.][db_name.]view_name
[{columnName [, columnName ]* }] [COMMENT view_comment]
AS query_expression
{% endhighlight %}

Create a view with the given query expression. If a view with the same name already exists in the catalog, an exception is thrown.

**TEMPORARY**

Create temporary view that has catalog and database namespaces and overrides views.

**IF NOT EXISTS**

If the view already exists, nothing happens.

{% top %}

## CREATE FUNCTION
{% highlight sql%}
CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION
Expand Down
20 changes: 20 additions & 0 deletions docs/dev/table/sql/create.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE 语句用于向当前或指定的 [Catalog]({{ site.baseurl }}/zh/dev/tab

- CREATE TABLE
- CREATE DATABASE
- CREATE VIEW
- CREATE FUNCTION

## 执行 CREATE 语句
Expand Down Expand Up @@ -344,6 +345,25 @@ CREATE DATABASE [IF NOT EXISTS] [catalog_name.]db_name

{% top %}

## CREATE VIEW
{% highlight sql %}
CREATE [TEMPORARY] VIEW [IF NOT EXISTS] [catalog_name.][db_name.]view_name
[{columnName [, columnName ]* }] [COMMENT view_comment]
AS query_expression
{% endhighlight %}

根据给定的 query 语句创建一个视图。若数据库中已经存在同名视图会抛出异常.

**TEMPORARY**

创建一个有 catalog 和数据库命名空间的临时视图,并覆盖原有的视图。

**IF NOT EXISTS**

若该视图已经存在,则不会进行任何操作。

{% top %}

## CREATE FUNCTION
{% highlight sql%}
CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION
Expand Down
20 changes: 20 additions & 0 deletions docs/dev/table/sql/drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Flink SQL supports the following DROP statements for now:

- DROP TABLE
- DROP DATABASE
- DROP VIEW
- DROP FUNCTION

## Run a DROP statement
Expand Down Expand Up @@ -143,6 +144,25 @@ Dropping a non-empty database triggers an exception. Enabled by default.

Dropping a non-empty database also drops all associated tables and functions.

## DROP VIEW

{% highlight sql %}
DROP [TEMPORARY] VIEW [IF EXISTS] [catalog_name.][db_name.]view_name
{% endhighlight %}

Drop a view that has catalog and database namespaces. If the view to drop does not exist, an exception is thrown.

**TEMPORARY**

Drop temporary view that has catalog and database namespaces.

**IF EXISTS**

If the view does not exist, nothing happens.

**MAINTAIN DEPENDENCIES**
Flink does not maintain dependencies of view by CASCADE/RESTRICT keywords, the current way is producing postpone error message when user tries to use the view under the scenarios like the underlying table of view has been dropped.

## DROP FUNCTION

{% highlight sql%}
Expand Down
20 changes: 20 additions & 0 deletions docs/dev/table/sql/drop.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Flink SQL 目前支持以下 DROP 语句:

- DROP TABLE
- DROP DATABASE
- DROP VIEW
- DROP FUNCTION

## 执行 DROP 语句
Expand Down Expand Up @@ -143,6 +144,25 @@ DROP DATABASE [IF EXISTS] [catalog_name.]db_name [ (RESTRICT | CASCADE) ]

删除一个非空数据库时,把相关联的表与函数一并删除。

## DROP VIEW

{% highlight sql %}
DROP [TEMPORARY] VIEW [IF EXISTS] [catalog_name.][db_name.]view_name
{% endhighlight %}

删除一个有 catalog 和数据库命名空间的视图。若需要删除的视图不存在,则会产生异常。

**TEMPORARY**

删除一个有 catalog 和数据库命名空间的临时视图。

**IF EXISTS**

若视图不存在,则不会进行任何操作。

**依赖管理**
Flink 没有使用 CASCADE / RESTRICT 关键字来维护视图的依赖关系,当前的方案是在用户使用视图时再提示错误信息,比如在视图的底层表已经被删除等场景。

## DROP FUNCTION

{% highlight sql%}
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/table/sql/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ This page describes the SQL language supported in Flink, including Data Definiti
This page lists all the supported statements supported in Flink SQL for now:

- [SELECT (Queries)](queries.html)
- [CREATE TABLE, DATABASE, FUNCTION](create.html)
- [DROP TABLE, DATABASE, FUNCTION](drop.html)
- [CREATE TABLE, DATABASE, VIEW, FUNCTION](create.html)
- [DROP TABLE, DATABASE, VIEW, FUNCTION](drop.html)
- [ALTER TABLE, DATABASE, FUNCTION](alter.html)
- [INSERT](insert.html)
- [SQL HINTS](hints.html)
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/table/sql/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ under the License.
本页面列出了目前 Flink SQL 所支持的所有语句:

- [SELECT (查询)](queries.html)
- [CREATE TABLE, DATABASE, FUNCTION](create.html)
- [DROP TABLE, DATABASE, FUNCTION](drop.html)
- [CREATE TABLE, DATABASE, VIEW, FUNCTION](create.html)
- [DROP TABLE, DATABASE, VIEW, FUNCTION](drop.html)
- [ALTER TABLE, DATABASE, FUNCTION](alter.html)
- [INSERT](insert.html)
- [SQL HINTS](hints.html)
Expand Down
22 changes: 21 additions & 1 deletion docs/dev/table/sql/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ String literals must be enclosed in single quotes (e.g., `SELECT 'Hello World'`)

## Operations

### Show and Use
### Show, Describe, and Use

<div markdown="1">
<table class="table table-bordered">
Expand Down Expand Up @@ -322,9 +322,29 @@ SHOW DATABASES;
<p>Show all tables in the current database in the current catalog</p>
{% highlight sql %}
SHOW TABLES;
{% endhighlight %}
<p>Show all views in the current database in the current catalog</p>
{% highlight sql %}
SHOW VIEWS;
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>Describe</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Describe the schema of the given table.</p>
{% highlight sql %}
DESCRIBE myTable;
{% endhighlight %}
<p>Describe the schema of the given view.</p>
{% highlight sql %}
DESCRIBE myView;
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>Use</strong><br>
Expand Down
22 changes: 21 additions & 1 deletion docs/dev/table/sql/queries.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Flink SQL 对于标识符(表、属性、函数名)有类似于 Java 的词

## 操作符

### Show 与 Use
### Show, Describe 与 Use

<div markdown="1">
<table class="table table-bordered">
Expand Down Expand Up @@ -322,9 +322,29 @@ SHOW DATABASES;
<p>显示当前数据库、Catalog中的所有表</p>
{% highlight sql %}
SHOW TABLES;
{% endhighlight %}
<p>显示当前数据库、Catalog中的所有视图</p>
{% highlight sql %}
SHOW VIEWS;
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>Describe</strong><br>
<span class="label label-primary">批处理</span> <span class="label label-primary">流处理</span>
</td>
<td>
<p>描述给定表的 Schema</p>
{% highlight sql %}
DESCRIBE myTable;
{% endhighlight %}
<p>描述给定视图的 Schema</p>
{% highlight sql %}
DESCRIBE myView;
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>Use</strong><br>
Expand Down

0 comments on commit 3952bfa

Please sign in to comment.