wuchong commented on a change in pull request #18361:
URL: https://github.com/apache/flink/pull/18361#discussion_r811544629
##########
File path:
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl
##########
@@ -410,15 +410,54 @@ SqlShowViews SqlShowViews() :
}
/**
-* Parse a "Show Tables" metadata query command.
+* SHOW TABLES FROM [catalog.] database sql call.
*/
SqlShowTables SqlShowTables() :
{
+ SqlIdentifier databaseName;
+ SqlCharStringLiteral likeLiteral = null;
+ String prep = "FROM";
+ boolean notLike = false;
+ SqlParserPos pos;
}
{
<SHOW> <TABLES>
+ [
+ [( <FROM> | <IN> { prep = "IN"; } )]
Review comment:
Should remove the `[ ]`? Otherwise, `SHOW TABLES db1` would be valid.
##########
File path:
flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java
##########
@@ -189,6 +189,28 @@ public void testShowFunctions() {
@Test
public void testShowTables() {
sql("show tables").ok("SHOW TABLES");
+ sql("show tables not like '%'").ok("SHOW TABLES NOT LIKE '%'");
+
+ sql("show tables from db1").ok("SHOW TABLES FROM `DB1`");
+ sql("show tables in db1").ok("SHOW TABLES IN `DB1`");
+
+ sql("show tables from catalog1.db1").ok("SHOW TABLES FROM
`CATALOG1`.`DB1`");
+ sql("show tables in catalog1.db1").ok("SHOW TABLES IN
`CATALOG1`.`DB1`");
+
+ sql("show tables from db1 like '%'").ok("SHOW TABLES FROM `DB1` LIKE
'%'");
+ sql("show tables in db1 like '%'").ok("SHOW TABLES IN `DB1` LIKE '%'");
+
+ sql("show tables from catalog1.db1 like '%'")
+ .ok("SHOW TABLES FROM `CATALOG1`.`DB1` LIKE '%'");
+ sql("show tables in catalog1.db1 like '%'").ok("SHOW TABLES IN
`CATALOG1`.`DB1` LIKE '%'");
+
+ sql("show tables from db1 not like '%'").ok("SHOW TABLES FROM `DB1`
NOT LIKE '%'");
+ sql("show tables in db1 not like '%'").ok("SHOW TABLES IN `DB1` NOT
LIKE '%'");
+
+ sql("show tables from catalog1.db1 not like '%'")
+ .ok("SHOW TABLES FROM `CATALOG1`.`DB1` NOT LIKE '%'");
+ sql("show tables in catalog1.db1 not like '%'")
+ .ok("SHOW TABLES IN `CATALOG1`.`DB1` NOT LIKE '%'");
Review comment:
Please test invalid statements as well, e.g. `show tables db1`.
##########
File path: docs/content/docs/dev/table/sql/show.md
##########
@@ -222,7 +222,7 @@ tEnv.executeSql("SHOW DATABASES").print()
// create a table
tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)")
// show tables
-tEnv.executeSql("SHOW TABLES").print()
+tEnv.executeSql("SHOW TABLES FROM default_database LIKE 'm%'").print()
Review comment:
Touching this example may confuse users we only support the complex show
tables syntax. Would be better to add an Example section in Show Tables (just
like SHOW COLUMNS EXAMPLES) to list how to use the complex show table syntax.
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ShowTablesOperation.java
##########
@@ -21,8 +21,83 @@
/** Operation to describe a SHOW TABLES statement. */
public class ShowTablesOperation implements ShowOperation {
+ private final String catalogName;
+ private final String databaseName;
+ private final boolean useLike;
+ private final boolean notLike;
+ private final String likePattern;
+ private final String preposition;
+
+ public ShowTablesOperation() {
+ this.catalogName = null;
+ this.databaseName = null;
+ this.likePattern = null;
+ this.useLike = false;
+ this.notLike = false;
+ this.preposition = null;
+ }
+
+ public ShowTablesOperation(String likePattern, boolean useLike, boolean
notLike) {
+ this.catalogName = null;
+ this.databaseName = null;
+ this.likePattern = likePattern;
+ this.useLike = useLike;
+ this.notLike = notLike;
+ this.preposition = null;
+ }
+
+ public ShowTablesOperation(
+ String catalogName,
+ String databaseName,
+ String likePattern,
+ boolean useLike,
+ boolean notLike,
+ String preposition) {
+ this.catalogName = catalogName;
+ this.databaseName = databaseName;
+ this.likePattern = likePattern;
+ this.useLike = useLike;
+ this.notLike = notLike;
Review comment:
Please add some validations such as `likePattern` shouldn't be null when
`useLike` is true.
##########
File path: docs/content/docs/dev/table/sql/show.md
##########
@@ -520,10 +520,17 @@ Show current database.
## SHOW TABLES
```sql
-SHOW TABLES
+SHOW TABLES [ ( FROM | IN ) [catalog_name.]database_name ] [ [NOT] LIKE
regex_pattern ]
Review comment:
```suggestion
SHOW TABLES [ ( FROM | IN ) [catalog_name.]database_name ] [ [NOT] LIKE
<sql_like_pattern> ]
```
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java
##########
@@ -906,7 +906,29 @@ private Operation
convertShowCurrentDatabase(SqlShowCurrentDatabase sqlShowCurre
/** Convert SHOW TABLES statement. */
private Operation convertShowTables(SqlShowTables sqlShowTables) {
- return new ShowTablesOperation();
+ if (sqlShowTables.getPreposition() == null) {
+ return new ShowTablesOperation(
+ sqlShowTables.getLikeSqlPattern(),
+ sqlShowTables.isWithLike(),
+ sqlShowTables.isNotLike());
+ }
+ String[] fullDatabaseName = sqlShowTables.fullDatabaseName();
+ if (fullDatabaseName.length > 2) {
+ throw new ValidationException("show tables from/in identifier
format error");
Review comment:
Please also add the wrong database identifier in the error message to
help users locate problems.
##########
File path:
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl
##########
@@ -410,15 +410,54 @@ SqlShowViews SqlShowViews() :
}
/**
-* Parse a "Show Tables" metadata query command.
+* SHOW TABLES FROM [catalog.] database sql call.
*/
SqlShowTables SqlShowTables() :
{
+ SqlIdentifier databaseName;
+ SqlCharStringLiteral likeLiteral = null;
+ String prep = "FROM";
+ boolean notLike = false;
+ SqlParserPos pos;
}
{
<SHOW> <TABLES>
+ [
+ [( <FROM> | <IN> { prep = "IN"; } )]
+ { pos = getPos(); }
+ databaseName = CompoundIdentifier()
+ [
+ [
+ <NOT>
+ {
+ notLike = true;
+ }
+ ]
+ <LIKE> <QUOTED_STRING>
+ {
+ String likeCondition = SqlParserUtil.parseString(token.image);
+ likeLiteral = SqlLiteral.createCharString(likeCondition,
getPos());
+ }
+ ]
+ {
+ return new SqlShowTables(pos, prep, databaseName, notLike,
likeLiteral);
+ }
Review comment:
It seems this part is redundant with the following NOT LIKE parser,
could you combine them?
--
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]