This is an automated email from the ASF dual-hosted git repository. twalthr pushed a commit to branch release-1.11 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 77ff1222a3d7ebc19c6f5a3f4cec5080f3d57d57 Author: godfreyhe <[email protected]> AuthorDate: Mon Jun 15 16:30:05 2020 +0800 [FLINK-17599][docs] Add documents for SHOW statement --- docs/dev/table/sql/index.md | 1 + docs/dev/table/sql/index.zh.md | 1 + docs/dev/table/sql/queries.md | 39 ------ docs/dev/table/sql/queries.zh.md | 39 ------ docs/dev/table/sql/show.md | 277 +++++++++++++++++++++++++++++++++++++++ docs/dev/table/sql/show.zh.md | 277 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 556 insertions(+), 78 deletions(-) diff --git a/docs/dev/table/sql/index.md b/docs/dev/table/sql/index.md index db96b1e..63d549c 100644 --- a/docs/dev/table/sql/index.md +++ b/docs/dev/table/sql/index.md @@ -37,6 +37,7 @@ This page lists all the supported statements supported in Flink SQL for now: - [DESCRIBE](describe.html) - [EXPLAIN](explain.html) - [USE](use.html) +- [SHOW](show.html) ## Data Types diff --git a/docs/dev/table/sql/index.zh.md b/docs/dev/table/sql/index.zh.md index f81474b..0def8c2 100644 --- a/docs/dev/table/sql/index.zh.md +++ b/docs/dev/table/sql/index.zh.md @@ -37,6 +37,7 @@ under the License. - [DESCRIBE](describe.html) - [EXPLAIN](explain.html) - [USE](use.html) +- [SHOW](show.html) ## 数据类型 diff --git a/docs/dev/table/sql/queries.md b/docs/dev/table/sql/queries.md index 0040072..df78622 100644 --- a/docs/dev/table/sql/queries.md +++ b/docs/dev/table/sql/queries.md @@ -382,45 +382,6 @@ String literals must be enclosed in single quotes (e.g., `SELECT 'Hello World'`) ## Operations -### Show - -<div markdown="1"> -<table class="table table-bordered"> - <thead> - <tr> - <th class="text-left" style="width: 20%">Operation</th> - <th class="text-center">Description</th> - </tr> - </thead> - <tbody> - <tr> - <td> - <strong>Show</strong><br> - <span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span> - </td> - <td> - <p>Show all catalogs</p> -{% highlight sql %} -SHOW CATALOGS; -{% endhighlight %} - <p>Show all databases in the current catalog</p> -{% highlight sql %} -SHOW DATABASES; -{% endhighlight %} - <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> - </tbody> -</table> -</div> - ### Scan, Projection, and Filter <div markdown="1"> diff --git a/docs/dev/table/sql/queries.zh.md b/docs/dev/table/sql/queries.zh.md index d208380..059e1a3 100644 --- a/docs/dev/table/sql/queries.zh.md +++ b/docs/dev/table/sql/queries.zh.md @@ -380,45 +380,6 @@ Flink SQL 对于标识符(表、属性、函数名)有类似于 Java 的词 ## 操作符 -### Show - -<div markdown="1"> -<table class="table table-bordered"> - <thead> - <tr> - <th class="text-left" style="width: 20%">操作符</th> - <th class="text-center">描述</th> - </tr> - </thead> - <tbody> - <tr> - <td> - <strong>Show</strong><br> - <span class="label label-primary">批处理</span> <span class="label label-primary">流处理</span> - </td> - <td> - <p>显示所有 catalog</p> -{% highlight sql %} -SHOW CATALOGS; -{% endhighlight %} - <p>显示当前 catalog 中所有的数据库</p> -{% highlight sql %} -SHOW DATABASES; -{% endhighlight %} - <p>显示当前数据库、Catalog中的所有表</p> -{% highlight sql %} -SHOW TABLES; -{% endhighlight %} - <p>显示当前数据库、Catalog中的所有视图</p> -{% highlight sql %} -SHOW VIEWS; -{% endhighlight %} - </td> - </tr> - </tbody> -</table> -</div> - ### Scan、Projection 与 Filter <div markdown="1"> diff --git a/docs/dev/table/sql/show.md b/docs/dev/table/sql/show.md new file mode 100644 index 0000000..4c9e241 --- /dev/null +++ b/docs/dev/table/sql/show.md @@ -0,0 +1,277 @@ +--- +title: "SHOW Statements" +nav-parent_id: sql +nav-pos: 10 +--- +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +* This will be replaced by the TOC +{:toc} + +SHOW statements are used to list all catalogs, or list all databases in the current catalog, or list all tables/views in the current catalog and the current database, or list all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and the current database. + +Flink SQL supports the following SHOW statements for now: +- SHOW CATALOGS +- SHOW DATABASES +- SHOW TABLES +- SHOW VIEWS +- SHOW FUNCTIONS + + +## Run a SHOW statement + +SHOW statements can be executed with the `executeSql()` method of the `TableEnvironment`, or executed in [SQL CLI]({{ site.baseurl }}/dev/table/sqlClient.html). The `executeSql()` method returns objects for a successful SHOW operation, otherwise will throw an exception. + +The following examples show how to run a SHOW statement in `TableEnvironment` and in SQL CLI. + +<div class="codetabs" markdown="1"> +<div data-lang="java" markdown="1"> +{% highlight java %} +StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); +StreamTableEnvironment tEnv = StreamTableEnvironment.create(env); + +// show catalogs +tEnv.executeSql("SHOW CATALOGS").print(); +// +-----------------+ +// | catalog name | +// +-----------------+ +// | default_catalog | +// +-----------------+ + +// show databases +tEnv.executeSql("SHOW DATABASES").print(); +// +------------------+ +// | database name | +// +------------------+ +// | default_database | +// +------------------+ + +// create a table +tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)"); +// show tables +tEnv.executeSql("SHOW TABLES").print(); +// +------------+ +// | table name | +// +------------+ +// | my_table | +// +------------+ + +// create a view +tEnv.executeSql("CREATE VIEW my_view AS ..."); +// show views +tEnv.executeSql("SHOW VIEWS").print(); +// +-----------+ +// | view name | +// +-----------+ +// | my_view | +// +-----------+ + +// show functions +tEnv.executeSql("SHOW FUNCTIONS").print(); +// +---------------+ +// | function name | +// +---------------+ +// | mod | +// | sha256 | +// | ... | +// +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="scala" markdown="1"> +{% highlight scala %} +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val tEnv = StreamTableEnvironment.create(env) + +// show catalogs +tEnv.executeSql("SHOW CATALOGS").print() +// +-----------------+ +// | catalog name | +// +-----------------+ +// | default_catalog | +// +-----------------+ + +// show databases +tEnv.executeSql("SHOW DATABASES").print() +// +------------------+ +// | database name | +// +------------------+ +// | default_database | +// +------------------+ + +// create a table +tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)") +// show tables +tEnv.executeSql("SHOW TABLES").print() +// +------------+ +// | table name | +// +------------+ +// | my_table | +// +------------+ + +// create a view +tEnv.executeSql("CREATE VIEW my_view AS ...") +// show views +tEnv.executeSql("SHOW VIEWS").print() +// +-----------+ +// | view name | +// +-----------+ +// | my_view | +// +-----------+ + +// show functions +tEnv.executeSql("SHOW FUNCTIONS").print() +// +---------------+ +// | function name | +// +---------------+ +// | mod | +// | sha256 | +// | ... | +// +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="python" markdown="1"> +{% highlight python %} +settings = EnvironmentSettings.new_instance()... +table_env = StreamTableEnvironment.create(env, settings) + +# show catalogs +table_env.execute_sql("SHOW CATALOGS").print() +# +-----------------+ +# | catalog name | +# +-----------------+ +# | default_catalog | +# +-----------------+ + +# show databases +table_env.execute_sql("SHOW DATABASES").print() +# +------------------+ +# | database name | +# +------------------+ +# | default_database | +# +------------------+ + +# create a table +table_env.execute_sql("CREATE TABLE my_table (...) WITH (...)") +# show tables +table_env.execute_sql("SHOW TABLES").print() +# +------------+ +# | table name | +# +------------+ +# | my_table | +# +------------+ + +# create a view +table_env.execute_sql("CREATE VIEW my_view AS ...") +# show views +table_env.execute_sql("SHOW VIEWS").print() +# +-----------+ +# | view name | +# +-----------+ +# | my_view | +# +-----------+ + +# show functions +table_env.execute_sql("SHOW FUNCTIONS").print() +# +---------------+ +# | function name | +# +---------------+ +# | mod | +# | sha256 | +# | ... | +# +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="SQL CLI" markdown="1"> +{% highlight sql %} + +Flink SQL> SHOW CATALOGS; +default_catalog + +Flink SQL> SHOW DATABASES; +default_database + +Flink SQL> CREATE TABLE my_table (...) WITH (...); +[INFO] Table has been created. + +Flink SQL> SHOW TABLES; +my_table + +Flink SQL> CREATE VIEW my_view AS ...; +[INFO] View has been created. + +Flink SQL> SHOW VIEWS; +my_view + +Flink SQL> SHOW FUNCTIONS; +mod +sha256 +... + +{% endhighlight %} +</div> +</div> + +{% top %} + +## SHOW CATALOGS + +{% highlight sql %} +SHOW CATALOGS +{% endhighlight %} + +Show all catalogs. + +## SHOW DATABASES + +{% highlight sql %} +SHOW DATABASES +{% endhighlight %} + +Show all databases in the current catalog. + +## SHOW TABLES + +{% highlight sql %} +SHOW TABLES +{% endhighlight %} + +Show all tables in the current catalog and the current database. + +## SHOW VIEWS + +{% highlight sql %} +SHOW VIEWS +{% endhighlight %} + +Show all views in the current catalog and the current database. + +## SHOW FUNCTIONS + +{% highlight sql %} +SHOW FUNCTIONS +{% endhighlight %} + +Show all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and current database. \ No newline at end of file diff --git a/docs/dev/table/sql/show.zh.md b/docs/dev/table/sql/show.zh.md new file mode 100644 index 0000000..9f6c648 --- /dev/null +++ b/docs/dev/table/sql/show.zh.md @@ -0,0 +1,277 @@ +--- +title: "SHOW 语句" +nav-parent_id: sql +nav-pos: 10 +--- +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +* This will be replaced by the TOC +{:toc} + +SHOW 语句用于列出所有的 catalog,或者列出当前 catalog 中所有的 database,或者列出当前 catalog 和当前 database 的所有表或视图,或者列出所有的 function,包括:临时系统 function,系统 function,临时 catalog function,当前 catalog 和 database 中的 catalog function。 + +目前 Flink SQL 支持下列 SHOW 语句: +- SHOW CATALOGS +- SHOW DATABASES +- SHOW TABLES +- SHOW VIEWS +- SHOW FUNCTIONS + + +## 执行 SHOW 语句 + +可以使用 `TableEnvironment` 中的 `executeSql()` 方法执行 SHOW 语句,也可以在 [SQL CLI]({{ site.baseurl }}/zh/dev/table/sqlClient.html) 中执行 SHOW 语句。 若 SHOW 操作执行成功,`executeSql()` 方法返回所有对象,否则会抛出异常。 + +以下的例子展示了如何在 `TableEnvironment` 和 SQL CLI 中执行一个 SHOW 语句。 + +<div class="codetabs" markdown="1"> +<div data-lang="java" markdown="1"> +{% highlight java %} +StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); +StreamTableEnvironment tEnv = StreamTableEnvironment.create(env); + +// show catalogs +tEnv.executeSql("SHOW CATALOGS").print(); +// +-----------------+ +// | catalog name | +// +-----------------+ +// | default_catalog | +// +-----------------+ + +// show databases +tEnv.executeSql("SHOW DATABASES").print(); +// +------------------+ +// | database name | +// +------------------+ +// | default_database | +// +------------------+ + +// create a table +tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)"); +// show tables +tEnv.executeSql("SHOW TABLES").print(); +// +------------+ +// | table name | +// +------------+ +// | my_table | +// +------------+ + +// create a view +tEnv.executeSql("CREATE VIEW my_view AS ..."); +// show views +tEnv.executeSql("SHOW VIEWS").print(); +// +-----------+ +// | view name | +// +-----------+ +// | my_view | +// +-----------+ + +// show functions +tEnv.executeSql("SHOW FUNCTIONS").print(); +// +---------------+ +// | function name | +// +---------------+ +// | mod | +// | sha256 | +// | ... | +// +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="scala" markdown="1"> +{% highlight scala %} +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val tEnv = StreamTableEnvironment.create(env) + +// show catalogs +tEnv.executeSql("SHOW CATALOGS").print() +// +-----------------+ +// | catalog name | +// +-----------------+ +// | default_catalog | +// +-----------------+ + +// show databases +tEnv.executeSql("SHOW DATABASES").print() +// +------------------+ +// | database name | +// +------------------+ +// | default_database | +// +------------------+ + +// create a table +tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)") +// show tables +tEnv.executeSql("SHOW TABLES").print() +// +------------+ +// | table name | +// +------------+ +// | my_table | +// +------------+ + +// create a view +tEnv.executeSql("CREATE VIEW my_view AS ...") +// show views +tEnv.executeSql("SHOW VIEWS").print() +// +-----------+ +// | view name | +// +-----------+ +// | my_view | +// +-----------+ + +// show functions +tEnv.executeSql("SHOW FUNCTIONS").print() +// +---------------+ +// | function name | +// +---------------+ +// | mod | +// | sha256 | +// | ... | +// +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="python" markdown="1"> +{% highlight python %} +settings = EnvironmentSettings.new_instance()... +table_env = StreamTableEnvironment.create(env, settings) + +# show catalogs +table_env.execute_sql("SHOW CATALOGS").print() +# +-----------------+ +# | catalog name | +# +-----------------+ +# | default_catalog | +# +-----------------+ + +# show databases +table_env.execute_sql("SHOW DATABASES").print() +# +------------------+ +# | database name | +# +------------------+ +# | default_database | +# +------------------+ + +# create a table +table_env.execute_sql("CREATE TABLE my_table (...) WITH (...)") +# show tables +table_env.execute_sql("SHOW TABLES").print() +# +------------+ +# | table name | +# +------------+ +# | my_table | +# +------------+ + +# create a view +table_env.execute_sql("CREATE VIEW my_view AS ...") +# show views +table_env.execute_sql("SHOW VIEWS").print() +# +-----------+ +# | view name | +# +-----------+ +# | my_view | +# +-----------+ + +# show functions +table_env.execute_sql("SHOW FUNCTIONS").print() +# +---------------+ +# | function name | +# +---------------+ +# | mod | +# | sha256 | +# | ... | +# +---------------+ + +{% endhighlight %} +</div> + +<div data-lang="SQL CLI" markdown="1"> +{% highlight sql %} + +Flink SQL> SHOW CATALOGS; +default_catalog + +Flink SQL> SHOW DATABASES; +default_database + +Flink SQL> CREATE TABLE my_table (...) WITH (...); +[INFO] Table has been created. + +Flink SQL> SHOW TABLES; +my_table + +Flink SQL> CREATE VIEW my_view AS ...; +[INFO] View has been created. + +Flink SQL> SHOW VIEWS; +my_view + +Flink SQL> SHOW FUNCTIONS; +mod +sha256 +... + +{% endhighlight %} +</div> +</div> + +{% top %} + +## SHOW CATALOGS + +{% highlight sql %} +SHOW CATALOGS +{% endhighlight %} + +展示所有的 catalog。 + +## SHOW DATABASES + +{% highlight sql %} +SHOW DATABASES +{% endhighlight %} + +展示当前 catalog 中所有的 database。 + +## SHOW TABLES + +{% highlight sql %} +SHOW TABLES +{% endhighlight %} + +展示当前 catalog 和当前 database 中所有的表。 + +## SHOW VIEWS + +{% highlight sql %} +SHOW VIEWS +{% endhighlight %} + +展示当前 catalog 和当前 database 中所有的视图。 + +## SHOW FUNCTIONS + +{% highlight sql %} +SHOW FUNCTIONS +{% endhighlight %} + +展示所有的 function,包括:临时系统 function, 系统 function, 临时 catalog function,当前 catalog 和 database 中的 catalog function。 \ No newline at end of file
