RocMarshal commented on a change in pull request #18386:
URL: https://github.com/apache/flink/pull/18386#discussion_r834355076
##########
File path: docs/content.zh/docs/dev/table/sql/show.md
##########
@@ -504,10 +504,68 @@ SHOW CURRENT CATALOG
## SHOW DATABASES
```sql
-SHOW DATABASES
+SHOW DATABASES [ ( FROM | IN ) catalog_name ] [ [NOT] LIKE regex_pattern ]
```
-展示当前 catalog 中所有的 database。
+展示指定 catalog (可选) 下的所有 database. 如果不指定 catalog 那将返回当前 catalog 下的所有 database.
另外, 语句的执行结果可通过模式匹配进行过滤.
+
+**LIKE**
+
+根据可选的 `LIKE` 语句展示给定表中与 `<sql_like_pattern>` 是否模糊相似的所有 database。
+
+`LIKE` 子句中 sql 正则式的语法与 `MySQL` 方言中的语法相同。
+
+### SHOW DATABASES EXAMPLES
+
+假设我们有一个名为 `catalog1` (当前 catalog) 的 catalog,其中包含如下的 database:
+* db_1
+* my_db_2
+
+- 展示指定 catalog 下所有的 database .
+
+```sql
+show databases from catalog1;
+-- show databases from catalog1;
+-- show databases in catalog1;
+-- show databases;
++------------+
+| table name |
++------------+
+| db_1 |
+| my_db_2 |
++------------+
+2 rows in set
+```
+
+- 展示指定 catalog 下所有与给定模式匹配的 database .
Review comment:
```suggestion
- 展示指定 catalog 下所有与给定模式匹配的 database。
```
##########
File path: docs/content.zh/docs/dev/table/sql/show.md
##########
@@ -504,10 +504,68 @@ SHOW CURRENT CATALOG
## SHOW DATABASES
```sql
-SHOW DATABASES
+SHOW DATABASES [ ( FROM | IN ) catalog_name ] [ [NOT] LIKE regex_pattern ]
```
-展示当前 catalog 中所有的 database。
+展示指定 catalog (可选) 下的所有 database. 如果不指定 catalog 那将返回当前 catalog 下的所有 database.
另外, 语句的执行结果可通过模式匹配进行过滤.
+
+**LIKE**
+
+根据可选的 `LIKE` 语句展示给定表中与 `<sql_like_pattern>` 是否模糊相似的所有 database。
+
+`LIKE` 子句中 sql 正则式的语法与 `MySQL` 方言中的语法相同。
+
+### SHOW DATABASES EXAMPLES
+
+假设我们有一个名为 `catalog1` (当前 catalog) 的 catalog,其中包含如下的 database:
Review comment:
```suggestion
假设我们有一个名为 `catalog1` (当前 catalog) 的 catalog,其中包含如下的 database:
```
##########
File path:
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/dql/SqlShowDatabases.java
##########
@@ -49,8 +70,44 @@ public SqlOperator getOperator() {
return Collections.EMPTY_LIST;
}
+ public String getCatalogName() {
+ return Objects.isNull(this.catalogName) ? null :
catalogName.getSimple();
+ }
+
+ public boolean isNotLike() {
+ return notLike;
+ }
+
+ public String getPreposition() {
+ return preposition;
+ }
+
+ public String getLikeSqlPattern() {
+ return Objects.isNull(this.likeLiteral) ? null :
likeLiteral.getValueAs(String.class);
+ }
+
+ public SqlCharStringLiteral getLikeLiteral() {
+ return likeLiteral;
+ }
+
+ public boolean isWithLike() {
+ return Objects.nonNull(likeLiteral);
+ }
+
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
- writer.keyword("SHOW DATABASES");
+ if (this.preposition == null) {
+ writer.keyword("SHOW DATABASES");
+ } else if (catalogName != null) {
+ writer.keyword("SHOW DATABASES " + this.preposition);
+ catalogName.unparse(writer, leftPrec, rightPrec);
+ }
+ if (likeLiteral != null) {
+ if (notLike) {
+ writer.keyword(String.format("NOT LIKE '%s'",
getLikeSqlPattern()));
Review comment:
Will there be a case that `likeLiteral != null` but `getLikeSqlPattern`
calling returned `null` result ?
I don't think so in my limited read.
##########
File path: docs/content/docs/dev/table/sql/show.md
##########
@@ -504,10 +504,69 @@ Show current catalog.
## SHOW DATABASES
```sql
-SHOW DATABASES
+SHOW DATABASES [ ( FROM | IN ) catalog_name ] [ [NOT] LIKE regex_pattern ]
```
-Show all databases in the current catalog.
+Show all databases for an optionally specified catalog. If no catalog is
specified then the databases are returned from the current catalog.
Additionally, the output of this statement may be filtered by an optional
matching pattern.
+
+**LIKE**
+Show all databases with optional `LIKE` clause, whose name is whether similar
to the `<sql_like_pattern>`.
+
+The syntax of sql pattern in `LIKE` clause is the same as that of `MySQL`
dialect.
+* `%` matches any number of characters, even zero characters, `\%` matches one
`%` character.
+* `_` matches exactly one character, `\_` matches one `_` character.
+
+### SHOW DATABASES EXAMPLES
+
+Assumes that we have a catalog named `catalog1` (current catalog) which has
the following databases:
+* db_1
+* my_db_2
+
+- Shows all databases of the given catalog.
+
+```sql
+show databases from catalog1;
+-- show databases from catalog1;
+-- show databases in catalog1;
+-- show databases;
++------------+
+| table name |
++------------+
+| db_1 |
+| my_db_2 |
++------------+
+2 rows in set
+```
+
+- Shows all database of the given catalog, which are similar to the given sql
pattern.
+
+```sql
+show databases from catalog1 like 'my%';
+-- show databases from catalog1 like 'my%';
+-- show databases in catalog1 like 'my%';
+-- show databases like 'my%';
++------------+
+| table name |
++------------+
+| my_db_2 |
++------------+
+1 row in set
+```
+
+- Shows all databases of the given catalog, which are not similar to the given
sql pattern.
+
+```sql
+show databases from catalog1 like 'my%';
+-- show databases from catalog1 like 'my%';
+-- show databases in catalog1 like 'my%';
+-- show databases like 'my%';
++------------+
+| table name |
++------------+
+| db_1 |
++------------+
+1 row in set
+```
Review comment:
Would you mind adding examples pattern with `_` into english & chinese
pages.
eg. show databases from catalog1 like '_y%';
##########
File path: docs/content.zh/docs/dev/table/sql/show.md
##########
@@ -504,10 +504,68 @@ SHOW CURRENT CATALOG
## SHOW DATABASES
```sql
-SHOW DATABASES
+SHOW DATABASES [ ( FROM | IN ) catalog_name ] [ [NOT] LIKE regex_pattern ]
```
-展示当前 catalog 中所有的 database。
+展示指定 catalog (可选) 下的所有 database. 如果不指定 catalog 那将返回当前 catalog 下的所有 database.
另外, 语句的执行结果可通过模式匹配进行过滤.
+
+**LIKE**
+
+根据可选的 `LIKE` 语句展示给定表中与 `<sql_like_pattern>` 是否模糊相似的所有 database。
+
+`LIKE` 子句中 sql 正则式的语法与 `MySQL` 方言中的语法相同。
+
+### SHOW DATABASES EXAMPLES
+
+假设我们有一个名为 `catalog1` (当前 catalog) 的 catalog,其中包含如下的 database:
+* db_1
+* my_db_2
+
+- 展示指定 catalog 下所有的 database .
+
+```sql
+show databases from catalog1;
+-- show databases from catalog1;
+-- show databases in catalog1;
+-- show databases;
++------------+
+| table name |
++------------+
+| db_1 |
+| my_db_2 |
++------------+
+2 rows in set
+```
+
+- 展示指定 catalog 下所有与给定模式匹配的 database .
+
+```sql
+show databases from catalog1 like 'my%';
+-- show databases from catalog1 like 'my%';
+-- show databases in catalog1 like 'my%';
+-- show databases like 'my%';
++------------+
+| table name |
++------------+
+| my_db_2 |
++------------+
+1 row in set
+```
+
+- 展示指定 catalog 下所有与给定模式不匹配的 database .
Review comment:
```suggestion
- 展示指定 catalog 下所有与给定模式不匹配的 database。
```
##########
File path: docs/content.zh/docs/dev/table/sql/show.md
##########
@@ -504,10 +504,68 @@ SHOW CURRENT CATALOG
## SHOW DATABASES
```sql
-SHOW DATABASES
+SHOW DATABASES [ ( FROM | IN ) catalog_name ] [ [NOT] LIKE regex_pattern ]
```
-展示当前 catalog 中所有的 database。
+展示指定 catalog (可选) 下的所有 database. 如果不指定 catalog 那将返回当前 catalog 下的所有 database.
另外, 语句的执行结果可通过模式匹配进行过滤.
+
+**LIKE**
+
+根据可选的 `LIKE` 语句展示给定表中与 `<sql_like_pattern>` 是否模糊相似的所有 database。
+
+`LIKE` 子句中 sql 正则式的语法与 `MySQL` 方言中的语法相同。
+
+### SHOW DATABASES EXAMPLES
+
+假设我们有一个名为 `catalog1` (当前 catalog) 的 catalog,其中包含如下的 database:
+* db_1
+* my_db_2
+
+- 展示指定 catalog 下所有的 database .
Review comment:
```suggestion
- 展示指定 catalog 下所有的 database。
```
##########
File path:
flink-table/flink-sql-client/src/test/resources/sql/catalog_database.q
##########
@@ -106,6 +122,77 @@ show databases;
2 rows in set
!ok
+show databases in catalog1;
++---------------+
+| database name |
++---------------+
+| db1 |
+| db1_1 |
+| pre_db |
++---------------+
+3 rows in set
+!ok
+
+show databases from catalog1;
++---------------+
+| database name |
++---------------+
+| db1 |
+| db1_1 |
+| pre_db |
++---------------+
+3 rows in set
+!ok
+
+show databases from catalog1 like 'db1';
++---------------+
+| database name |
++---------------+
+| db1 |
++---------------+
+1 rows in set
+!ok
+
+show databases in catalog1 not like 'pre%';
++---------------+
+| database name |
++---------------+
+| db1 |
+| db1_1 |
++---------------+
+2 rows in set
+!ok
+
+show databases in catalog1 like '%db%';
++---------------+
+| database name |
++---------------+
+| db1 |
+| db1_1 |
+| pre_db |
++---------------+
+3 rows in set
+!ok
+
+show databases like 'db%';
++---------------+
+| database name |
++---------------+
+| db1 |
++---------------+
+1 rows in set
+!ok
+
+show databases in catalog1 like 'db%';
++---------------+
+| database name |
++---------------+
+| db1 |
+| db1_1 |
++---------------+
+2 rows in set
+!ok
+
Review comment:
same as mentioned above.
##########
File path:
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/dql/SqlShowDatabases.java
##########
@@ -49,8 +70,44 @@ public SqlOperator getOperator() {
return Collections.EMPTY_LIST;
}
+ public String getCatalogName() {
+ return Objects.isNull(this.catalogName) ? null :
catalogName.getSimple();
+ }
+
+ public boolean isNotLike() {
+ return notLike;
+ }
+
+ public String getPreposition() {
+ return preposition;
+ }
+
+ public String getLikeSqlPattern() {
+ return Objects.isNull(this.likeLiteral) ? null :
likeLiteral.getValueAs(String.class);
+ }
+
+ public SqlCharStringLiteral getLikeLiteral() {
+ return likeLiteral;
+ }
+
+ public boolean isWithLike() {
+ return Objects.nonNull(likeLiteral);
+ }
+
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
- writer.keyword("SHOW DATABASES");
+ if (this.preposition == null) {
+ writer.keyword("SHOW DATABASES");
+ } else if (catalogName != null) {
+ writer.keyword("SHOW DATABASES " + this.preposition);
+ catalogName.unparse(writer, leftPrec, rightPrec);
+ }
+ if (likeLiteral != null) {
Review comment:
Please keep statement in judging not null in unified coding format.
`Objects.nonNull` or `xxx != null`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]