Skip to content

Commit

Permalink
[FLINK-18616][table] Add SHOW CURRENT DDLs
Browse files Browse the repository at this point in the history
This closes apache#12934
  • Loading branch information
fsk119 committed Jul 24, 2020
1 parent 2debda2 commit ede4da5
Show file tree
Hide file tree
Showing 30 changed files with 505 additions and 38 deletions.
23 changes: 16 additions & 7 deletions docs/dev/table/hive/hive_dialect.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ execution:

configuration:
table.sql-dialect: hive

{% endhighlight %}

You can also set the dialect after the SQL Client has launched.
Expand Down Expand Up @@ -87,12 +87,21 @@ This section lists the supported DDLs with the Hive dialect. We'll mainly focus
here. You can refer to [Hive doc](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL)
for the semantics of each DDL statement.

### CATALOG

#### Show

{% highlight sql %}
SHOW CURRENT CATALOG;
{% endhighlight %}

### DATABASE

#### Show

{% highlight sql %}
SHOW DATABASES;
SHOW CURRENT DATABASE;
{% endhighlight %}

#### Create
Expand Down Expand Up @@ -157,13 +166,13 @@ CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name
]
[LOCATION fs_path]
[TBLPROPERTIES (property_name=property_value, ...)]

row_format:
: DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]
[NULL DEFINED AS char]
| SERDE serde_name [WITH SERDEPROPERTIES (property_name=property_value, ...)]

file_format:
: SEQUENCEFILE
| TEXTFILE
Expand All @@ -172,10 +181,10 @@ file_format:
| PARQUET
| AVRO
| INPUTFORMAT input_format_classname OUTPUTFORMAT output_format_classname

column_constraint:
: NOT NULL [[ENABLE|DISABLE] [VALIDATE|NOVALIDATE] [RELY|NORELY]]

table_constraint:
: [CONSTRAINT constraint_name] PRIMARY KEY (col_name, ...) [[ENABLE|DISABLE] [VALIDATE|NOVALIDATE] [RELY|NORELY]]
{% endhighlight %}
Expand Down Expand Up @@ -216,9 +225,9 @@ present, the operation will be applied to the corresponding partition instead of

{% highlight sql %}
ALTER TABLE table_name [PARTITION partition_spec] SET SERDE serde_class_name [WITH SERDEPROPERTIES serde_properties];

ALTER TABLE table_name [PARTITION partition_spec] SET SERDEPROPERTIES serde_properties;

serde_properties:
: (property_name = property_value, property_name = property_value, ... )
{% endhighlight %}
Expand Down
22 changes: 15 additions & 7 deletions docs/dev/table/hive/hive_dialect.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ execution:

configuration:
table.sql-dialect: hive

{% endhighlight %}

You can also set the dialect after the SQL Client has launched.
Expand Down Expand Up @@ -87,6 +87,14 @@ This section lists the supported DDLs with the Hive dialect. We'll mainly focus
here. You can refer to [Hive doc](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL)
for the semantics of each DDL statement.

### CATALOG

#### Show

{% highlight sql %}
SHOW CURRENT CATALOG;
{% endhighlight %}

### DATABASE

#### Show
Expand Down Expand Up @@ -157,13 +165,13 @@ CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name
]
[LOCATION fs_path]
[TBLPROPERTIES (property_name=property_value, ...)]

row_format:
: DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]
[NULL DEFINED AS char]
| SERDE serde_name [WITH SERDEPROPERTIES (property_name=property_value, ...)]

file_format:
: SEQUENCEFILE
| TEXTFILE
Expand All @@ -172,10 +180,10 @@ file_format:
| PARQUET
| AVRO
| INPUTFORMAT input_format_classname OUTPUTFORMAT output_format_classname

column_constraint:
: NOT NULL [[ENABLE|DISABLE] [VALIDATE|NOVALIDATE] [RELY|NORELY]]

table_constraint:
: [CONSTRAINT constraint_name] PRIMARY KEY (col_name, ...) [[ENABLE|DISABLE] [VALIDATE|NOVALIDATE] [RELY|NORELY]]
{% endhighlight %}
Expand Down Expand Up @@ -216,9 +224,9 @@ present, the operation will be applied to the corresponding partition instead of

{% highlight sql %}
ALTER TABLE table_name [PARTITION partition_spec] SET SERDE serde_class_name [WITH SERDEPROPERTIES serde_properties];

ALTER TABLE table_name [PARTITION partition_spec] SET SERDEPROPERTIES serde_properties;

serde_properties:
: (property_name = property_value, property_name = property_value, ... )
{% endhighlight %}
Expand Down
40 changes: 37 additions & 3 deletions docs/dev/table/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ 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.
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 show current catalog and 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 CURRENT CATALOG
- SHOW DATABASES
- SHOW TABLES
- SHOW CURRENT DATABASE
- SHOW TABLES
- SHOW VIEWS
- SHOW FUNCTIONS

Expand All @@ -55,6 +57,14 @@ tEnv.executeSql("SHOW CATALOGS").print();
// | default_catalog |
// +-----------------+

// show current catalog
tEnv.executeSql("SHOW CURRENT CATALOG").print();
// +----------------------+
// | current catalog name |
// +----------------------+
// | default_catalog |
// +----------------------+

// show databases
tEnv.executeSql("SHOW DATABASES").print();
// +------------------+
Expand All @@ -63,6 +73,14 @@ tEnv.executeSql("SHOW DATABASES").print();
// | default_database |
// +------------------+

// show current database
tEnv.executeSql("SHOW CURRENT DATABASE").print();
// +-----------------------+
// | current database name |
// +-----------------------+
// | default_database |
// +-----------------------+

// create a table
tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)");
// show tables
Expand Down Expand Up @@ -244,6 +262,14 @@ SHOW CATALOGS

Show all catalogs.

## SHOW CURRENT CATALOG

{% highlight sql %}
SHOW CURRENT CATALOG
{% endhighlight %}

Show current catalog.

## SHOW DATABASES

{% highlight sql %}
Expand All @@ -252,6 +278,14 @@ SHOW DATABASES

Show all databases in the current catalog.

## SHOW CURRENT DATABASE

{% highlight sql %}
SHOW CURRENT DATABASE
{% endhighlight %}

Show current database.

## SHOW TABLES

{% highlight sql %}
Expand All @@ -274,4 +308,4 @@ Show all views in the current catalog and the current database.
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.
Show all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and current database.
40 changes: 37 additions & 3 deletions docs/dev/table/sql/show.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ 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。
SHOW 语句用于列出所有的 catalog,或者列出当前 catalog 中所有的 database,或者列出当前 catalog 和当前 database 的所有表或视图,或者列出当前正在使用的 catalog 和 database, 或者列出所有的 function,包括:临时系统 function,系统 function,临时 catalog function,当前 catalog 和 database 中的 catalog function。

目前 Flink SQL 支持下列 SHOW 语句:
- SHOW CATALOGS
- SHOW CURRENT CATALOG
- SHOW DATABASES
- SHOW TABLES
- SHOW CURRENT DATABASE
- SHOW TABLES
- SHOW VIEWS
- SHOW FUNCTIONS

Expand All @@ -55,6 +57,14 @@ tEnv.executeSql("SHOW CATALOGS").print();
// | default_catalog |
// +-----------------+

// show current catalog
tEnv.executeSql("SHOW CURRENT CATALOG").print();
// +----------------------+
// | current catalog name |
// +----------------------+
// | default_catalog |
// +----------------------+

// show databases
tEnv.executeSql("SHOW DATABASES").print();
// +------------------+
Expand All @@ -63,6 +73,14 @@ tEnv.executeSql("SHOW DATABASES").print();
// | default_database |
// +------------------+

// show current database
tEnv.executeSql("SHOW CURRENT DATABASE").print();
// +-----------------------+
// | current database name |
// +-----------------------+
// | default_database |
// +-----------------------+

// create a table
tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)");
// show tables
Expand Down Expand Up @@ -244,6 +262,14 @@ SHOW CATALOGS

展示所有的 catalog。

## SHOW CURRENT CATALOG

{% highlight sql %}
SHOW CURRENT CATALOG
{% endhighlight %}

显示当前正在使用的 catalog。

## SHOW DATABASES

{% highlight sql %}
Expand All @@ -252,6 +278,14 @@ SHOW DATABASES

展示当前 catalog 中所有的 database。

## SHOW CURRENT DATABASE

{% highlight sql %}
SHOW CURRENT DATABASE
{% endhighlight %}

显示当前正在使用的 database。

## SHOW TABLES

{% highlight sql %}
Expand All @@ -274,4 +308,4 @@ SHOW VIEWS
SHOW FUNCTIONS
{% endhighlight %}

展示所有的 function,包括:临时系统 function, 系统 function, 临时 catalog function,当前 catalog 和 database 中的 catalog function。
展示所有的 function,包括:临时系统 function, 系统 function, 临时 catalog function,当前 catalog 和 database 中的 catalog function。
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ public void testCatalog() {
List<Row> databases = Lists.newArrayList(tableEnv.executeSql("show databases").collect());
assertEquals(1, databases.size());
assertEquals(DEFAULT_BUILTIN_DATABASE, databases.get(0).toString());
String catalogName = tableEnv.executeSql("show current catalog").collect().next().toString();
assertEquals(DEFAULT_BUILTIN_CATALOG, catalogName);
String databaseName = tableEnv.executeSql("show current database").collect().next().toString();
assertEquals(DEFAULT_BUILTIN_DATABASE, databaseName);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,15 @@ private void callCommand(SqlCommandCall cmdCall) {
case SHOW_CATALOGS:
callShowCatalogs();
break;
case SHOW_CURRENT_CATALOG:
callShowCurrentCatalog();
break;
case SHOW_DATABASES:
callShowDatabases();
break;
case SHOW_CURRENT_DATABASE:
callShowCurrentDatabase();
break;
case SHOW_TABLES:
callShowTables();
break;
Expand Down Expand Up @@ -445,6 +451,18 @@ private void callShowCatalogs() {
terminal.flush();
}

private void callShowCurrentCatalog() {
String currentCatalog;
try {
currentCatalog = executor.executeSql(sessionId, "SHOW CURRENT CATALOG").collect().next().toString();
} catch (SqlExecutionException e) {
printExecutionException(e);
return;
}
terminal.writer().println(currentCatalog);
terminal.flush();
}

private void callShowDatabases() {
final List<String> dbs;
try {
Expand All @@ -461,6 +479,18 @@ private void callShowDatabases() {
terminal.flush();
}

private void callShowCurrentDatabase() {
String currentDatabase;
try {
currentDatabase = executor.executeSql(sessionId, "SHOW CURRENT DATABASE").collect().next().toString();
} catch (SqlExecutionException e) {
printExecutionException(e);
return;
}
terminal.writer().println(currentDatabase);
terminal.flush();
}

private void callShowTables() {
final List<String> tables;
try {
Expand Down
Loading

0 comments on commit ede4da5

Please sign in to comment.