Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@
"org.apache.flink.sql.parser.dql.SqlRichExplain"
"org.apache.flink.sql.parser.dql.SqlLoadModule"
"org.apache.flink.sql.parser.dql.SqlShowCatalogs"
"org.apache.flink.sql.parser.dql.SqlShowColumns"
"org.apache.flink.sql.parser.dql.SqlShowCreate"
"org.apache.flink.sql.parser.dql.SqlShowCreateTable"
"org.apache.flink.sql.parser.dql.SqlShowCreateView"
"org.apache.flink.sql.parser.dql.SqlShowCurrentCatalog"
"org.apache.flink.sql.parser.dql.SqlShowDatabases"
"org.apache.flink.sql.parser.dql.SqlShowCurrentDatabase"
"org.apache.flink.sql.parser.dql.SqlShowDatabases"
"org.apache.flink.sql.parser.dql.SqlShowFunctions"
"org.apache.flink.sql.parser.dql.SqlShowJars"
"org.apache.flink.sql.parser.dql.SqlShowModules"
"org.apache.flink.sql.parser.dql.SqlShowPartitions"
"org.apache.flink.sql.parser.dql.SqlShowTables"
"org.apache.flink.sql.parser.dql.SqlShowColumns"
"org.apache.flink.sql.parser.dql.SqlShowCreate"
"org.apache.flink.sql.parser.dql.SqlShowCreateTable"
"org.apache.flink.sql.parser.dql.SqlShowCreateView"
"org.apache.flink.sql.parser.dql.SqlShowViews"
"org.apache.flink.sql.parser.dql.SqlRichDescribeTable"
"org.apache.flink.sql.parser.dql.SqlUnloadModule"
Expand Down Expand Up @@ -505,39 +506,40 @@
# Example: SqlShowDatabases(), SqlShowTables().
statementParserMethods: [
"RichSqlInsert()"
"SqlAddJar()"
"SqlAlterDatabase()"
"SqlAlterFunction()"
"SqlAlterTable()"
"SqlAlterView()"
"SqlBeginStatementSet()"
"SqlCompileAndExecutePlan()"
"SqlCompilePlan()"
"SqlDescribeCatalog()"
"SqlDescribeDatabase()"
"SqlEndStatementSet()"
"SqlExecutePlan()"
"SqlExecute()"
"SqlLoadModule()"
"SqlRemoveJar()"
"SqlReset()"
"SqlRichDescribeTable()"
"SqlRichExplain()"
"SqlSet()"
"SqlShowCatalogs()"
"SqlShowColumns()"
"SqlShowCreate()"
"SqlShowCurrentCatalogOrDatabase()"
"SqlDescribeCatalog()"
"SqlUseCatalog()"
"SqlShowDatabases()"
"SqlUseDatabase()"
"SqlAlterDatabase()"
"SqlDescribeDatabase()"
"SqlAlterFunction()"
"SqlShowFunctions()"
"SqlShowTables()"
"SqlShowColumns()"
"SqlShowCreate()"
"SqlRichDescribeTable()"
"SqlAlterTable()"
"SqlAlterView()"
"SqlShowJars()"
"SqlShowModules()"
"SqlShowPartitions()"
"SqlShowTables()"
"SqlShowViews()"
"SqlUnloadModule()"
"SqlUseCatalog()"
"SqlUseDatabase()"
"SqlUseModules()"
"SqlRichExplain()"
"SqlCompileAndExecutePlan()"
"SqlCompilePlan()"
"SqlExecutePlan()"
"SqlExecute()"
"SqlAddJar()"
"SqlRemoveJar()"
"SqlShowJars()"
"SqlSet()"
"SqlReset()"
]

# List of methods for parsing custom literals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,25 @@ SqlDrop SqlDropExtended(Span s, boolean replace) :
}
}

/** SHOW PARTITIONS table_name [PARTITION partition_spec]; */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
/** SHOW PARTITIONS table_name [PARTITION partition_spec]; */
/** SHOW PARTITIONS table_identidier [PARTITION partition_spec]; */

SqlShowPartitions SqlShowPartitions() :
{
SqlParserPos pos;
SqlIdentifier tableIdentifier;
SqlNodeList partSpec = null;
}
{
<SHOW> <PARTITIONS> { pos = getPos(); }
tableIdentifier = CompoundIdentifier()
[
<PARTITION> {
partSpec = new SqlNodeList(getPos());
PartitionSpecCommaList(partSpec);
}
]
{ return new SqlShowPartitions(pos, tableIdentifier, partSpec); }
}

/**
* Parses a load module statement.
* LOAD MODULE module_name [WITH (property_name=property_value, ...)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ void testShowColumns() {
.ok("SHOW COLUMNS IN `CATALOG1`.`DB1`.`TBL` NOT LIKE '%'");
}

@Test
public void testShowPartitions() {
sql("show partitions tbl").ok("SHOW PARTITIONS `TBL`");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test like
show partitions c1.d1.tbl
The SqlToOperationConverterTest.java#testShowPartitions is same.

sql("show partitions tbl partition (p=1)").ok("SHOW PARTITIONS `TBL` PARTITION (`P` = 1)");
}

/**
* Here we override the super method to avoid test error from `describe statement` supported in
* original calcite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.flink.table.operations.ShowFunctionsOperation;
import org.apache.flink.table.operations.ShowFunctionsOperation.FunctionScope;
import org.apache.flink.table.operations.ShowModulesOperation;
import org.apache.flink.table.operations.ShowPartitionsOperation;
import org.apache.flink.table.operations.ShowTablesOperation;
import org.apache.flink.table.operations.SinkModifyOperation;
import org.apache.flink.table.operations.SourceQueryOperation;
Expand Down Expand Up @@ -439,6 +440,22 @@ public void testShowFunctions() {
assertShowFunctions(sql2, sql2, FunctionScope.USER);
}

@Test
public void testShowPartitions() {
Operation operation = parse("show partitions tbl", SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(ShowPartitionsOperation.class);
assertThat(operation.asSummaryString()).isEqualTo("SHOW PARTITIONS builtin.default.tbl");

operation =
parse(
"show partitions tbl partition (dt='2020-04-30 01:02:03')",
SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(ShowPartitionsOperation.class);
assertThat(operation.asSummaryString())
.isEqualTo(
"SHOW PARTITIONS builtin.default.tbl PARTITION (dt=2020-04-30 01:02:03)");
}

@Test
public void testCreateTable() {
final String sql =
Expand Down