This is an automated email from the ASF dual-hosted git repository. zhangliang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new c299eee5147 Split ExplainStatement to ExplainStatement and DescribeStatement (#35686) c299eee5147 is described below commit c299eee51474743230c5666f754a246b69f78230 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Thu Jun 12 18:22:06 2025 +0800 Split ExplainStatement to ExplainStatement and DescribeStatement (#35686) * Split ExplainStatement to ExplainStatement and DescribeStatement * Split ExplainStatement to ExplainStatement and DescribeStatement * Split ExplainStatement to ExplainStatement and DescribeStatement --- .../type/dal/ExplainStatementContext.java | 1 - .../statement/dal/ExplainStatementBinder.java | 2 - .../binder/mysql/MySQLSQLStatementExtractor.java | 6 +- .../statement/type/DorisDALStatementVisitor.java | 122 ++++---- .../statement/type/MySQLDALStatementVisitor.java | 20 +- ...xplainStatement.java => DescribeStatement.java} | 7 +- .../core/statement/dal/ExplainStatement.java | 26 -- .../asserts/statement/dal/DALStatementAssert.java | 77 +++--- ...entAssert.java => DescribeStatementAssert.java} | 38 +-- .../statement/dal/impl/ExplainStatementAssert.java | 21 -- .../cases/parser/jaxb/RootSQLParserTestCases.java | 6 +- ...estCase.java => DescribeStatementTestCase.java} | 24 +- .../statement/dal/ExplainStatementTestCase.java | 8 - .../src/main/resources/case/dal/describe.xml | 57 ++++ .../parser/src/main/resources/case/dal/explain.xml | 306 +++++++++------------ .../main/resources/sql/supported/dal/describe.xml | 28 ++ .../main/resources/sql/supported/dal/explain.xml | 8 - 17 files changed, 356 insertions(+), 401 deletions(-) diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java index 184a8780c0a..27ada3dfeb9 100644 --- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java +++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java @@ -53,7 +53,6 @@ public final class ExplainStatementContext extends CommonSQLStatementContext imp private Collection<SimpleTableSegment> extractTablesFromExplain(final ExplainStatement sqlStatement) { Collection<SimpleTableSegment> result = new LinkedList<>(); - sqlStatement.getTable().ifPresent(result::add); SQLStatement explainableStatement = sqlStatement.getSqlStatement(); TableExtractor extractor = new TableExtractor(); // TODO extract table from declare, execute, createMaterializedView, refreshMaterializedView diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinder.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinder.java index 3e86f255144..3b3259e54f5 100644 --- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinder.java +++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinder.java @@ -42,8 +42,6 @@ public final class ExplainStatementBinder implements SQLStatementBinder<ExplainS private ExplainStatement copy(final ExplainStatement sqlStatement, final SQLStatement boundSQLStatement) { ExplainStatement result = new ExplainStatement(); result.setSqlStatement(boundSQLStatement); - sqlStatement.getTable().ifPresent(result::setTable); - sqlStatement.getColumnWild().ifPresent(result::setColumnWild); SQLStatementCopyUtils.copyAttributes(sqlStatement, result); return result; } diff --git a/infra/binder/dialect/mysql/src/main/java/org/apache/shardingsphere/infra/binder/mysql/MySQLSQLStatementExtractor.java b/infra/binder/dialect/mysql/src/main/java/org/apache/shardingsphere/infra/binder/mysql/MySQLSQLStatementExtractor.java index 011a495f99e..f2be807cfd6 100644 --- a/infra/binder/dialect/mysql/src/main/java/org/apache/shardingsphere/infra/binder/mysql/MySQLSQLStatementExtractor.java +++ b/infra/binder/dialect/mysql/src/main/java/org/apache/shardingsphere/infra/binder/mysql/MySQLSQLStatementExtractor.java @@ -20,9 +20,10 @@ package org.apache.shardingsphere.infra.binder.mysql; import org.apache.shardingsphere.infra.binder.context.extractor.DialectSQLStatementExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DescribeStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.OptimizeTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; import java.util.Collection; import java.util.Collections; @@ -43,6 +44,9 @@ public final class MySQLSQLStatementExtractor implements DialectSQLStatementExtr if (sqlStatement instanceof OptimizeTableStatement) { return ((OptimizeTableStatement) sqlStatement).getTables(); } + if (sqlStatement instanceof DescribeStatement) { + return ((DescribeStatement) sqlStatement).getTable().map(Collections::singletonList).orElse(Collections.emptyList()); + } return Collections.emptyList(); } diff --git a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java index 5d694b8fa59..164bcf80b23 100644 --- a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java +++ b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java @@ -143,86 +143,87 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AnalyzeTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLCacheIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeMasterStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeReplicationSourceToStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLCheckTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLChecksumTableStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DescribeStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.OptimizeTableStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowColumnsStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLCreateResourceGroupStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLDropResourceGroupStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLHelpStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLInstallComponentStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLInstallPluginStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLKillStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLLoadIndexInfoStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.OptimizeTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLRepairTableStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetPersistStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLRestartStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLSetResourceGroupStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShutdownStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLInstallComponentStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLUninstallComponentStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLCacheIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLLoadIndexInfoStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLInstallPluginStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLShowPluginsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLUninstallPluginStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinaryLogsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinlogEventsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeMasterStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeReplicationSourceToStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartReplicaStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartSlaveStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStopSlaveStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowMasterStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowRelayLogEventsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicaStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicasStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveHostsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLCreateResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLDropResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLSetResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.MySQLShowOtherStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCharacterSetStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCollationStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowColumnsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.database.MySQLShowCreateDatabaseStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowCreateEventStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowCreateFunctionStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowCreateProcedureStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowCreateTriggerStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowCreateUserStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.view.MySQLShowCreateViewStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.engine.MySQLShowEngineStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.error.MySQLShowErrorsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.error.MySQLShowWarningsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowCreateEventStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowEventsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowCreateFunctionStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionCodeStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowCreateUserStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowGrantsStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowMasterStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowOpenTablesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.MySQLShowOtherStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLShowPluginsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowPrivilegesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowCreateProcedureStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureCodeStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureStatusStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.process.MySQLShowProcessListStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.profile.MySQLShowProfileStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.profile.MySQLShowProfilesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowRelayLogEventsStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicaStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicasStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveHostsStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowOpenTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowCreateTriggerStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowTriggersStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.variable.MySQLShowVariablesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.error.MySQLShowWarningsStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShutdownStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartReplicaStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartSlaveStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStopSlaveStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLUninstallComponentStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLUninstallPluginStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement; -import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; -import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; -import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.view.MySQLShowCreateViewStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLCheckTableStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLChecksumTableStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLRepairTableStatement; import java.util.Collection; import java.util.Collections; @@ -491,16 +492,17 @@ public final class DorisDALStatementVisitor extends DorisStatementVisitor implem @Override public ASTNode visitExplain(final ExplainContext ctx) { - ExplainStatement result = new ExplainStatement(); - if (null != ctx.tableName()) { - result.setTable((SimpleTableSegment) visit(ctx.tableName())); - if (null != ctx.columnRef()) { - result.setColumnWild((ColumnSegment) visit(ctx.columnRef())); - } else if (null != ctx.textString()) { - result.setColumnWild((ColumnSegment) visit(ctx.textString())); - } - } else { + if (null == ctx.tableName()) { + ExplainStatement result = new ExplainStatement(); getExplainableSQLStatement(ctx).ifPresent(result::setSqlStatement); + return result; + } + DescribeStatement result = new DescribeStatement(); + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + if (null != ctx.columnRef()) { + result.setColumnWild((ColumnSegment) visit(ctx.columnRef())); + } else if (null != ctx.textString()) { + result.setColumnWild((ColumnSegment) visit(ctx.textString())); } return result; } diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java index c53641e46f0..56cc2e1ada5 100644 --- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java +++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java @@ -143,6 +143,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DescribeStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AnalyzeTableStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement; @@ -504,16 +505,17 @@ public final class MySQLDALStatementVisitor extends MySQLStatementVisitor implem @Override public ASTNode visitExplain(final ExplainContext ctx) { - ExplainStatement result = new ExplainStatement(); - if (null != ctx.tableName()) { - result.setTable((SimpleTableSegment) visit(ctx.tableName())); - if (null != ctx.columnRef()) { - result.setColumnWild((ColumnSegment) visit(ctx.columnRef())); - } else if (null != ctx.textString()) { - result.setColumnWild((ColumnSegment) visit(ctx.textString())); - } - } else { + if (null == ctx.tableName()) { + ExplainStatement result = new ExplainStatement(); getExplainableSQLStatement(ctx).ifPresent(result::setSqlStatement); + return result; + } + DescribeStatement result = new DescribeStatement(); + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + if (null != ctx.columnRef()) { + result.setColumnWild((ColumnSegment) visit(ctx.columnRef())); + } else if (null != ctx.textString()) { + result.setColumnWild((ColumnSegment) visit(ctx.textString())); } return result; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/DescribeStatement.java similarity index 87% copy from parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java copy to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/DescribeStatement.java index 9fc0844a8a7..44a1c310042 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/DescribeStatement.java @@ -22,18 +22,15 @@ import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import java.util.Optional; /** - * Explain statement. + * Describe statement. */ @Getter @Setter -public final class ExplainStatement extends AbstractSQLStatement implements DALStatement { - - private SQLStatement sqlStatement; +public final class DescribeStatement extends AbstractSQLStatement implements DALStatement { private SimpleTableSegment table; diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java index 9fc0844a8a7..fbd6f055e7f 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/ExplainStatement.java @@ -19,13 +19,9 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import java.util.Optional; - /** * Explain statement. */ @@ -34,26 +30,4 @@ import java.util.Optional; public final class ExplainStatement extends AbstractSQLStatement implements DALStatement { private SQLStatement sqlStatement; - - private SimpleTableSegment table; - - private ColumnSegment columnWild; - - /** - * Get table. - * - * @return table - */ - public Optional<SimpleTableSegment> getTable() { - return Optional.ofNullable(table); - } - - /** - * Get column segment. - * - * @return column segment - */ - public Optional<ColumnSegment> getColumnWild() { - return Optional.ofNullable(columnWild); - } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java index dcb86ec2c9d..3d4fb29fc27 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java @@ -19,60 +19,61 @@ package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement. import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLCacheIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLCheckTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLChecksumTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLCreateResourceGroupStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLDropResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DescribeStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.EmptyStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLInstallComponentStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLInstallPluginStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLKillStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLLoadIndexInfoStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.OptimizeTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLRepairTableStatement; -import org.apache.shardingsphere.sql.parser.statement.postgresql.dal.PostgreSQLResetParameterStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetPersistStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLRestartStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLSetResourceGroupStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinlogEventsStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCollationStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowColumnsStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowCreateTriggerStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowCreateUserStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowEventsStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionStatusStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowOpenTablesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureCodeStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLKillStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetPersistStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLRestartStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShutdownStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLInstallComponentStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLUninstallComponentStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLCacheIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLLoadIndexInfoStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLInstallPluginStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLUninstallPluginStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinlogEventsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowRelayLogEventsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicaStatusStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicasStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveHostsStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLCreateResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLDropResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLSetResourceGroupStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCollationStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowEventsStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowCreateUserStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureCodeStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureStatusStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowOpenTablesStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowCreateTriggerStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowTriggersStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.variable.MySQLShowVariablesStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShutdownStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLCheckTableStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLChecksumTableStatement; +import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLRepairTableStatement; import org.apache.shardingsphere.sql.parser.statement.oracle.dal.OracleSpoolStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLUninstallComponentStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLUninstallPluginStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement; +import org.apache.shardingsphere.sql.parser.statement.postgresql.dal.PostgreSQLResetParameterStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.AlterResourceGroupStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.BinlogStatementAssert; @@ -82,6 +83,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.d import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.CloneStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.CreateResourceGroupStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.DelimiterStatementAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.DescribeStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.DropResourceGroupStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.EmptyStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.ExplainStatementAssert; @@ -136,6 +138,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.CloneStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.CreateResourceGroupStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DelimiterStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DescribeStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DropResourceGroupStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.EmptyStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ExplainStatementTestCase; @@ -202,6 +205,8 @@ public final class DALStatementAssert { EmptyStatementAssert.assertIs(assertContext, (EmptyStatement) actual, (EmptyStatementTestCase) expected); } else if (actual instanceof ExplainStatement) { ExplainStatementAssert.assertIs(assertContext, (ExplainStatement) actual, (ExplainStatementTestCase) expected); + } else if (actual instanceof DescribeStatement) { + DescribeStatementAssert.assertIs(assertContext, (DescribeStatement) actual, (DescribeStatementTestCase) expected); } else if (actual instanceof ShowDatabasesStatement) { ShowDatabasesStatementAssert.assertIs(assertContext, (ShowDatabasesStatement) actual, (ShowDatabasesStatementTestCase) expected); } else if (actual instanceof ShowTablesStatement) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/DescribeStatementAssert.java similarity index 51% copy from test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java copy to test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/DescribeStatementAssert.java index 3c37adc0ebc..5a20aa1c5f3 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/DescribeStatementAssert.java @@ -19,54 +19,34 @@ package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement. import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DescribeStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.column.ColumnAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.SQLStatementAssert; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ExplainStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DescribeStatementTestCase; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; /** - * Explain statement assert. + * Describe statement assert. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ExplainStatementAssert { +public final class DescribeStatementAssert { /** - * Assert explain statement is correct with expected parser result. + * Assert describe statement is correct with expected parser result. * * @param assertContext assert context * @param actual actual explain statement - * @param expected expected explain statement test case + * @param expected expected describe statement test case */ - public static void assertIs(final SQLCaseAssertContext assertContext, final ExplainStatement actual, final ExplainStatementTestCase expected) { - if (null != expected.getSelectClause()) { - assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); - SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getSelectClause()); - } else if (null != expected.getUpdateClause()) { - assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); - SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getUpdateClause()); - } else if (null != expected.getInsertClause()) { - assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); - SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getInsertClause()); - } else if (null != expected.getDeleteClause()) { - assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); - SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getDeleteClause()); - } else if (null != expected.getCreateTableAsSelectClause()) { - assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); - SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getCreateTableAsSelectClause()); - } else if (actual.getColumnWild().isPresent() && null != expected.getTable()) { + public static void assertIs(final SQLCaseAssertContext assertContext, final DescribeStatement actual, final DescribeStatementTestCase expected) { + if (actual.getColumnWild().isPresent() && null != expected.getTable()) { assertExplainStatementColumnWild(assertContext, actual, expected); - } else { - assertNull(actual.getSqlStatement(), assertContext.getText("Actual statement should not exist.")); } } - private static void assertExplainStatementColumnWild(final SQLCaseAssertContext assertContext, final ExplainStatement actual, final ExplainStatementTestCase expected) { + private static void assertExplainStatementColumnWild(final SQLCaseAssertContext assertContext, final DescribeStatement actual, final DescribeStatementTestCase expected) { if (actual.getTable().isPresent()) { TableAssert.assertIs(assertContext, actual.getTable().get(), expected.getTable()); if (actual.getColumnWild().isPresent()) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java index 3c37adc0ebc..7107e1b67e6 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/impl/ExplainStatementAssert.java @@ -21,14 +21,10 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.column.ColumnAssert; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.SQLStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ExplainStatementTestCase; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; /** * Explain statement assert. @@ -59,23 +55,6 @@ public final class ExplainStatementAssert { } else if (null != expected.getCreateTableAsSelectClause()) { assertNotNull(actual.getSqlStatement(), assertContext.getText("Actual statement should exist.")); SQLStatementAssert.assertIs(assertContext, actual.getSqlStatement(), expected.getCreateTableAsSelectClause()); - } else if (actual.getColumnWild().isPresent() && null != expected.getTable()) { - assertExplainStatementColumnWild(assertContext, actual, expected); - } else { - assertNull(actual.getSqlStatement(), assertContext.getText("Actual statement should not exist.")); - } - } - - private static void assertExplainStatementColumnWild(final SQLCaseAssertContext assertContext, final ExplainStatement actual, final ExplainStatementTestCase expected) { - if (actual.getTable().isPresent()) { - TableAssert.assertIs(assertContext, actual.getTable().get(), expected.getTable()); - if (actual.getColumnWild().isPresent()) { - ColumnAssert.assertIs(assertContext, actual.getColumnWild().get(), expected.getColumn()); - } else { - assertFalse(actual.getColumnWild().isPresent(), assertContext.getText("Actual column wild should not exist.")); - } - } else { - assertFalse(actual.getTable().isPresent(), assertContext.getText("Actual table should not exist.")); } } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java index fc49d4b3959..3fdaec8aad9 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java @@ -31,6 +31,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.CreateLoadableFunctionTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.CreateResourceGroupStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DelimiterStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DescribeStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DropResourceGroupStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.EmptyStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ExplainStatementTestCase; @@ -596,8 +597,11 @@ public final class RootSQLParserTestCases { @XmlElement(name = "use") private final List<UseStatementTestCase> useTestCases = new LinkedList<>(); + @XmlElement(name = "explain") + private final List<ExplainStatementTestCase> explainTestCases = new LinkedList<>(); + @XmlElement(name = "describe") - private final List<ExplainStatementTestCase> describeTestCases = new LinkedList<>(); + private final List<DescribeStatementTestCase> describeTestCases = new LinkedList<>(); @XmlElement(name = "show-databases") private final List<ShowDatabasesStatementTestCase> showDatabasesTestCases = new LinkedList<>(); diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/DescribeStatementTestCase.java similarity index 57% copy from test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java copy to test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/DescribeStatementTestCase.java index c1dd1bc335b..4dc79c7b084 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/DescribeStatementTestCase.java @@ -19,14 +19,9 @@ package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb. import lombok.Getter; import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.column.ExpectedColumn; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedSimpleTable; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateTableStatementTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.DeleteStatementTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.InsertStatementTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.SelectStatementTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.UpdateStatementTestCase; import javax.xml.bind.annotation.XmlElement; @@ -35,22 +30,7 @@ import javax.xml.bind.annotation.XmlElement; */ @Getter @Setter -public final class ExplainStatementTestCase extends SQLParserTestCase { - - @XmlElement(name = "select") - private SelectStatementTestCase selectClause; - - @XmlElement(name = "insert") - private InsertStatementTestCase insertClause; - - @XmlElement(name = "update") - private UpdateStatementTestCase updateClause; - - @XmlElement(name = "delete") - private DeleteStatementTestCase deleteClause; - - @XmlElement(name = "create-table") - private CreateTableStatementTestCase createTableAsSelectClause; +public final class DescribeStatementTestCase extends SQLParserTestCase { @XmlElement(name = "simple-table") private ExpectedSimpleTable table; diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java index c1dd1bc335b..d999229abbf 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/ExplainStatementTestCase.java @@ -19,8 +19,6 @@ package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb. import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.column.ExpectedColumn; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedSimpleTable; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.DeleteStatementTestCase; @@ -51,10 +49,4 @@ public final class ExplainStatementTestCase extends SQLParserTestCase { @XmlElement(name = "create-table") private CreateTableStatementTestCase createTableAsSelectClause; - - @XmlElement(name = "simple-table") - private ExpectedSimpleTable table; - - @XmlElement(name = "column-wild") - private ExpectedColumn column; } diff --git a/test/it/parser/src/main/resources/case/dal/describe.xml b/test/it/parser/src/main/resources/case/dal/describe.xml new file mode 100644 index 00000000000..c17d7cd0f94 --- /dev/null +++ b/test/it/parser/src/main/resources/case/dal/describe.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<sql-parser-test-cases> + <describe sql-case-id="desc_table"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + </describe> + + <describe sql-case-id="desc_table_with_col_name"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + <column-wild name="colName" start-index="15" stop-index="21" /> + </describe> + + <describe sql-case-id="desc_table_with_placeholder"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + <column-wild name="___" start-index="15" stop-index="17" /> + </describe> + + <describe sql-case-id="desc_table_with_wild"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + <column-wild name="u%" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="18" /> + </describe> + + <describe sql-case-id="describe_table"> + <simple-table name="tableName" start-index="9" stop-index="17" /> + </describe> + + <describe sql-case-id="describe_table_with_col_name"> + <simple-table name="tableName" start-index="9" stop-index="17" /> + <column-wild name="colName" start-index="19" stop-index="25" /> + </describe> + + <describe sql-case-id="describe_table_with_placeholder"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + <column-wild name="___" start-index="15" stop-index="17" /> + </describe> + + <describe sql-case-id="describe_table_with_wild"> + <simple-table name="tableName" start-index="5" stop-index="13" /> + <column-wild name="u%" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="18" /> + </describe> +</sql-parser-test-cases> diff --git a/test/it/parser/src/main/resources/case/dal/explain.xml b/test/it/parser/src/main/resources/case/dal/explain.xml index f41ab8f722c..61c3780a44e 100644 --- a/test/it/parser/src/main/resources/case/dal/explain.xml +++ b/test/it/parser/src/main/resources/case/dal/explain.xml @@ -17,7 +17,7 @@ --> <sql-parser-test-cases> - <describe sql-case-id="explain_extended_select"> + <explain sql-case-id="explain_extended_select"> <select> <projections start-index="24" stop-index="49"> <expression-projection text="10 % 7" start-index="24" stop-index="29"> @@ -61,9 +61,9 @@ </expression-projection> </projections> </select> - </describe> + </explain> - <describe sql-case-id="explain_partitions_select"> + <explain sql-case-id="explain_partitions_select"> <select> <projections start-index="26" stop-index="26"> <expression-projection text="1" start-index="26" stop-index="26"> @@ -71,17 +71,17 @@ </expression-projection> </projections> </select> - </describe> + </explain> - <describe sql-case-id="explain_select_constant_without_table"> + <explain sql-case-id="explain_select_constant_without_table"> <select> <projections start-index="15" stop-index="20"> <expression-projection text="1" alias="a" start-index="15" stop-index="20" /> </projections> </select> - </describe> + </explain> - <describe sql-case-id="explain_update_without_condition"> + <explain sql-case-id="explain_update_without_condition"> <update> <table start-index="15" stop-index="21"> <simple-table name="t_order" start-index="15" stop-index="21" /> @@ -95,9 +95,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_insert_without_parameters"> + <explain sql-case-id="explain_insert_without_parameters"> <insert> <table name="t_order" start-index="20" stop-index="26" /> <columns start-index="28" stop-index="54"> @@ -122,9 +122,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_delete_without_sharding_value"> + <explain sql-case-id="explain_delete_without_sharding_value"> <delete> <table name="t_order" start-index="20" stop-index="26" /> <where start-index="28" stop-index="41" literal-stop-index="46"> @@ -142,9 +142,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_select_with_binding_tables"> + <explain sql-case-id="explain_select_with_binding_tables"> <select> <from> <join-table join-type="INNER"> @@ -178,9 +178,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_create_table_as_select"> + <explain sql-case-id="explain_create_table_as_select"> <create-table> <table name="t_order_new" start-index="21" stop-index="31" /> <select> @@ -192,9 +192,9 @@ </projections> </select> </create-table> - </describe> + </explain> - <describe sql-case-id="explain_create_table_as_select_with_explicit_column_names"> + <explain sql-case-id="explain_create_table_as_select_with_explicit_column_names"> <create-table> <table name="t_order_new" start-index="21" stop-index="31" /> <column name="order_id_new" start-index="34" stop-index="45" /> @@ -209,9 +209,9 @@ </projections> </select> </create-table> - </describe> + </explain> - <describe sql-case-id="explain_create_remote_table_as_select"> + <explain sql-case-id="explain_create_remote_table_as_select"> <create-table> <table name="t_order_new" start-index="28" stop-index="38" /> <select> @@ -247,9 +247,9 @@ </projections> </select> </create-table> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze"> + <explain sql-case-id="explain_with_analyze"> <select> <projections start-index="23" stop-index="23"> <shorthand-projection start-index="23" stop-index="23" /> @@ -271,9 +271,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze_format"> + <explain sql-case-id="explain_with_analyze_format"> <select> <projections start-index="37" stop-index="37"> <shorthand-projection start-index="37" stop-index="37" /> @@ -295,15 +295,15 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze_delete"> + <explain sql-case-id="explain_with_analyze_delete"> <delete> <table name="t_order" start-index="28" stop-index="34" /> </delete> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze_delete_condition"> + <explain sql-case-id="explain_with_analyze_delete_condition"> <delete> <table name="t1" start-index="23" stop-index="24" /> <where start-index="54" stop-index="74"> @@ -332,9 +332,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze_update"> + <explain sql-case-id="explain_with_analyze_update"> <update> <table start-index="7" stop-index="13"> <simple-table name="t_order" start-index="23" stop-index="29" /> @@ -348,9 +348,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_with_analyze_insert"> + <explain sql-case-id="explain_with_analyze_insert"> <insert> <table name="t_order" start-index="28" stop-index="34" /> <columns start-index="36" stop-index="45"> @@ -364,47 +364,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="desc_table"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - </describe> - - <describe sql-case-id="desc_table_with_col_name"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - <column-wild name="colName" start-index="15" stop-index="21" /> - </describe> - - <describe sql-case-id="desc_table_with_placeholder"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - <column-wild name="___" start-index="15" stop-index="17" /> - </describe> - - <describe sql-case-id="desc_table_with_wild"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - <column-wild name="u%" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="18" /> - </describe> - - <describe sql-case-id="describe_table"> - <simple-table name="tableName" start-index="9" stop-index="17" /> - </describe> - - <describe sql-case-id="describe_table_with_col_name"> - <simple-table name="tableName" start-index="9" stop-index="17" /> - <column-wild name="colName" start-index="19" stop-index="25" /> - </describe> - - <describe sql-case-id="describe_table_with_placeholder"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - <column-wild name="___" start-index="15" stop-index="17" /> - </describe> - - <describe sql-case-id="describe_table_with_wild"> - <simple-table name="tableName" start-index="5" stop-index="13" /> - <column-wild name="u%" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="18" /> - </describe> - - <describe sql-case-id="explain_table"> + <explain sql-case-id="explain_table"> <select> <order-by> <column-item name="order_id" start-index="31" stop-index="38" /> @@ -420,21 +382,21 @@ <simple-table name="t_order" start-index="8" stop-index="20" /> </from> </select> - </describe> + </explain> - <describe sql-case-id="explain_create_materialized_view_with_data" /> + <explain sql-case-id="explain_create_materialized_view_with_data" /> - <describe sql-case-id="explain_create_materialized_view_with_no_data" /> + <explain sql-case-id="explain_create_materialized_view_with_no_data" /> - <describe sql-case-id="explain_performance"> + <explain sql-case-id="explain_performance"> <select> <projections start-index="27" stop-index="27"> <expression-projection text="1" start-index="27" stop-index="27" /> </projections> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_alias_as_keyword"> + <explain sql-case-id="explain_for_select_alias_as_keyword"> <select> <from> <simple-table name="t_order_item" alias="length" start-index="53" stop-index="71" /> @@ -460,9 +422,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_binding_tables"> + <explain sql-case-id="explain_for_select_with_binding_tables"> <select> <from> <join-table join-type="INNER"> @@ -496,9 +458,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_analyze"> + <explain sql-case-id="explain_for_select_with_analyze"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24" /> @@ -520,9 +482,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_statement"> + <explain sql-case-id="explain_for_select_with_statement"> <select> <projections start-index="53" stop-index="53"> <shorthand-projection start-index="53" stop-index="53" /> @@ -544,9 +506,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_into"> + <explain sql-case-id="explain_for_select_with_into"> <select> <projections start-index="37" stop-index="37"> <shorthand-projection start-index="37" stop-index="37" /> @@ -568,9 +530,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_into_dblink"> + <explain sql-case-id="explain_for_select_with_into_dblink"> <select> <projections start-index="65" stop-index="65"> <shorthand-projection start-index="65" stop-index="65" /> @@ -592,9 +554,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_update_without_condition"> + <explain sql-case-id="explain_for_update_without_condition"> <update> <table start-index="24" stop-index="30"> <simple-table name="t_order" start-index="24" stop-index="30" /> @@ -608,9 +570,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_update"> + <explain sql-case-id="explain_for_update"> <update> <table start-index="8" stop-index="14"> <simple-table name="t_order" start-index="24" stop-index="30" /> @@ -624,9 +586,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_update_with_statement"> + <explain sql-case-id="explain_for_update_with_statement"> <update> <table start-index="37" stop-index="43"> <simple-table name="t_order" start-index="53" stop-index="59" /> @@ -640,9 +602,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_update_with_into"> + <explain sql-case-id="explain_for_update_with_into"> <update> <table start-index="21" stop-index="27"> <simple-table name="t_order" start-index="37" stop-index="43" /> @@ -656,9 +618,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_update_with_into_dblink"> + <explain sql-case-id="explain_for_update_with_into_dblink"> <update> <table start-index="48" stop-index="54"> <simple-table name="t_order" start-index="65" stop-index="71" /> @@ -672,9 +634,9 @@ </assignment> </set> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_insert_without_parameters"> + <explain sql-case-id="explain_for_insert_without_parameters"> <insert> <table name="t_order" start-index="29" stop-index="35" /> <columns start-index="37" stop-index="63"> @@ -699,9 +661,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_for_with_analyze_insert"> + <explain sql-case-id="explain_for_with_analyze_insert"> <insert> <table name="t_order" start-index="29" stop-index="35" /> <columns start-index="37" stop-index="46"> @@ -715,9 +677,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_for_insert_statement"> + <explain sql-case-id="explain_for_insert_statement"> <insert> <table name="t_order" start-index="58" stop-index="64" /> <columns start-index="66" stop-index="75"> @@ -731,9 +693,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_for_insert_into"> + <explain sql-case-id="explain_for_insert_into"> <insert> <table name="t_order" start-index="42" stop-index="48" /> <columns start-index="50" stop-index="59"> @@ -747,9 +709,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_for_insert_into_dblink"> + <explain sql-case-id="explain_for_insert_into_dblink"> <insert> <table name="t_order" start-index="70" stop-index="76" /> <columns start-index="78" stop-index="87"> @@ -763,9 +725,9 @@ </value> </values> </insert> - </describe> + </explain> - <describe sql-case-id="explain_for_delete_without_sharding_value"> + <explain sql-case-id="explain_for_delete_without_sharding_value"> <delete> <table name="t_order" start-index="29" stop-index="35" /> <where start-index="37" stop-index="50" literal-stop-index="55"> @@ -783,15 +745,15 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_for_with_analyze_delete"> + <explain sql-case-id="explain_for_with_analyze_delete"> <delete> <table name="t_order" start-index="29" stop-index="35" /> </delete> - </describe> + </explain> - <describe sql-case-id="explain_for_delete_condition"> + <explain sql-case-id="explain_for_delete_condition"> <delete> <table name="t_order" start-index="29" stop-index="35" /> <where start-index="37" stop-index="55"> @@ -810,9 +772,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_for_delete_statement"> + <explain sql-case-id="explain_for_delete_statement"> <delete> <table name="t_order" start-index="58" stop-index="64" /> <where start-index="66" stop-index="84"> @@ -831,9 +793,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_for_delete_into"> + <explain sql-case-id="explain_for_delete_into"> <delete> <table name="t_order" start-index="42" stop-index="48" /> <where start-index="50" stop-index="68"> @@ -852,9 +814,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_for_delete_into_dblink"> + <explain sql-case-id="explain_for_delete_into_dblink"> <delete> <table name="t_order" start-index="70" stop-index="76" /> <where start-index="78" stop-index="96"> @@ -873,9 +835,9 @@ </expr> </where> </delete> - </describe> + </explain> - <describe sql-case-id="explain_set_statement_id_with_select"> + <explain sql-case-id="explain_set_statement_id_with_select"> <select> <projections start-index="68" stop-index="76"> <column-projection name="last_name" start-index="68" stop-index="76" /> @@ -884,9 +846,9 @@ <simple-table name="employees" start-index="83" stop-index="91" /> </from> </select> - </describe> + </explain> - <describe sql-case-id="explain_set_statement_id_with_into_select1"> + <explain sql-case-id="explain_set_statement_id_with_into_select1"> <select> <projections start-index="109" stop-index="109"> <shorthand-projection start-index="109" stop-index="109" /> @@ -920,9 +882,9 @@ </where> </select> <comment start-index="69" stop-index="93" text="/*+ LEADING(E@SEL$2 D@SEL$2 T@SEL$1) */" /> - </describe> + </explain> - <describe sql-case-id="explain_set_statement_id_with_into_select2"> + <explain sql-case-id="explain_set_statement_id_with_into_select2"> <select> <projections start-index="95" stop-index="95"> <shorthand-projection start-index="95" stop-index="95" /> @@ -956,9 +918,9 @@ </where> </select> <comment start-index="69" stop-index="93" text="/*+ LEADING(v.e v.d t) */" /> - </describe> + </explain> - <describe sql-case-id="explain_set_statement_id_with_into_update"> + <explain sql-case-id="explain_set_statement_id_with_into_update"> <update> <table start-index="76" stop-index="84"> <simple-table name="employees" start-index="76" stop-index="84" /> @@ -1015,9 +977,9 @@ </expr> </where> </update> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_unique_partition_by"> + <explain sql-case-id="explain_for_select_with_unique_partition_by"> <select> <projections start-index="24" stop-index="49"> <column-projection name="country" start-index="24" stop-index="30" /> @@ -1053,9 +1015,9 @@ <cell-assignment-column name="sales" start-index="269" stop-index="273" /> </model> </select> - </describe> + </explain> - <describe sql-case-id="explain_with_select_comment"> + <explain sql-case-id="explain_with_select_comment"> <select> <projections start-index="78" stop-index="78"> <shorthand-projection start-index="78" stop-index="78" /> @@ -1066,9 +1028,9 @@ </select> <comment start-index="0" stop-index="19" text="/*FORCE_IMCI_NODES*/" /> <comment start-index="36" stop-index="76" text="/*+ SET_VAR(cost_threshold_for_imci=0) */" /> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_group_by"> + <explain sql-case-id="explain_for_select_with_group_by"> <select> <projections start-index="24" stop-index="64"> <column-projection name="calendar_month_desc" start-index="24" stop-index="44" > @@ -1109,9 +1071,9 @@ </column-item> </group-by> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_function"> + <explain sql-case-id="explain_for_select_with_function"> <select> <projections start-index="24" stop-index="39"> <aggregation-projection type="SUM" expression="SUM(amount_sold)" start-index="24" stop-index="39" /> @@ -1140,9 +1102,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_function_and_function"> + <explain sql-case-id="explain_for_select_with_function_and_function"> <select> <projections start-index="24" stop-index="41"> <aggregation-projection type="SUM" expression="SUM(quantity_sold)" start-index="24" stop-index="41" /> @@ -1171,9 +1133,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select"> + <explain sql-case-id="explain_for_select"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24" /> @@ -1213,9 +1175,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_emp_range" > + <explain sql-case-id="explain_for_select_emp_range" > <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1224,9 +1186,9 @@ <simple-table name="emp_range" start-index="31" stop-index="39"/> </from> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_emp_comp" > + <explain sql-case-id="explain_for_select_emp_comp" > <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1235,9 +1197,9 @@ <simple-table name="emp_comp" start-index="31" stop-index="38"/> </from> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_with_comments"> + <explain sql-case-id="explain_for_select_with_comments"> <select> <projections start-index="44" stop-index="59"> <column-projection name="deptno" start-index="44" stop-index="49"/> @@ -1251,9 +1213,9 @@ </group-by> </select> <comment text="/*+ result_cache */" start-index="24" stop-index="42"/> - </describe> + </explain> - <describe sql-case-id="explain_for_select_job_history" > + <explain sql-case-id="explain_for_select_job_history" > <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1262,9 +1224,9 @@ <simple-table name="v_emp_job_history" start-index="31" stop-index="47"/> </from> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_emp_comp_where"> + <explain sql-case-id="explain_for_select_emp_comp_where"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24" /> @@ -1286,9 +1248,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_emp_range_where"> + <explain sql-case-id="explain_for_select_emp_range_where"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24" /> @@ -1317,9 +1279,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_where_and_function"> + <explain sql-case-id="explain_for_select_where_and_function"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24" /> @@ -1348,9 +1310,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_xml_query"> + <explain sql-case-id="explain_for_select_xml_query"> <select> <projections start-index="24" stop-index="107"> <expression-projection text="XMLQUERY('/PurchaseOrder/LineItems/LineItem')" start-index="24" stop-index="107" /> @@ -1380,9 +1342,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_where_between"> + <explain sql-case-id="explain_for_select_where_between"> <select> <projections start-index="24" stop-index="53"> <aggregation-projection type="SUM" alias="total_revenue" expression="SUM(amount_sold)" start-index="24" stop-index="39"/> @@ -1406,9 +1368,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_where_between_groupby_having"> + <explain sql-case-id="explain_for_select_where_between_groupby_having"> <select> <projections start-index="24" stop-index="49"> <column-projection name="cust_last_name" start-index="24" stop-index="39"> @@ -1496,9 +1458,9 @@ </expr> </having> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_alias_where_colon"> + <explain sql-case-id="explain_for_select_alias_where_colon"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1532,9 +1494,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_where_todate_function"> + <explain sql-case-id="explain_for_select_where_todate_function"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1563,9 +1525,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_where_colon"> + <explain sql-case-id="explain_for_select_where_colon"> <select> <projections start-index="24" stop-index="24"> <shorthand-projection start-index="24" stop-index="24"/> @@ -1599,9 +1561,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_group_by_multi_columns"> + <explain sql-case-id="explain_for_select_group_by_multi_columns"> <select> <projections start-index="24" stop-index="65"> <column-projection name="prod_name" start-index="24" stop-index="34"> @@ -1729,9 +1691,9 @@ </column-item> </group-by> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_in_sub_query"> + <explain sql-case-id="explain_for_select_in_sub_query"> <select> <projections start-index="24" stop-index="39"> <aggregation-projection type="SUM" expression="sum(amount_sold)" start-index="24" stop-index="39"/> @@ -1774,9 +1736,9 @@ </expr> </where> </select> - </describe> + </explain> - <describe sql-case-id="explain_for_select_between_to_date_function"> + <explain sql-case-id="explain_for_select_between_to_date_function"> <select> <projections start-index="24" stop-index="39"> <aggregation-projection type="SUM" expression="sum(amount_sold)" start-index="24" stop-index="39"/> @@ -1814,5 +1776,5 @@ </expr> </where> </select> - </describe> + </explain> </sql-parser-test-cases> diff --git a/test/it/parser/src/main/resources/sql/supported/dal/describe.xml b/test/it/parser/src/main/resources/sql/supported/dal/describe.xml new file mode 100644 index 00000000000..d1dbd0949d7 --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/dal/describe.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<sql-cases> + <sql-case id="desc_table" value="DESC tableName" db-types="MySQL" /> + <sql-case id="desc_table_with_col_name" value="DESC tableName colName" db-types="MySQL" /> + <sql-case id="desc_table_with_placeholder" value="DESC tableName ___" db-types="MySQL" /> + <sql-case id="desc_table_with_wild" value="DESC tableName `u%`" db-types="MySQL" /> + <sql-case id="describe_table" value="DESCRIBE tableName" db-types="MySQL" /> + <sql-case id="describe_table_with_col_name" value="DESCRIBE tableName colName" db-types="MySQL" /> + <sql-case id="describe_table_with_placeholder" value="DESC tableName ___" db-types="MySQL" /> + <sql-case id="describe_table_with_wild" value="DESC tableName `u%`" db-types="MySQL" /> +</sql-cases> diff --git a/test/it/parser/src/main/resources/sql/supported/dal/explain.xml b/test/it/parser/src/main/resources/sql/supported/dal/explain.xml index e0858cfeb33..b3df533e652 100644 --- a/test/it/parser/src/main/resources/sql/supported/dal/explain.xml +++ b/test/it/parser/src/main/resources/sql/supported/dal/explain.xml @@ -34,14 +34,6 @@ <sql-case id="explain_with_analyze_update" value="EXPLAIN ANALYZE UPDATE t_order SET id = 1" db-types="MySQL" /> <sql-case id="explain_with_analyze_insert" value="EXPLAIN ANALYZE INSERT INTO t_order (order_id) VALUES(1)" db-types="MySQL" /> <sql-case id="explain_table" value="EXPLAIN TABLE t_order ORDER BY order_id LIMIT 1 OFFSET 2" db-types="MySQL" /> - <sql-case id="desc_table" value="DESC tableName" db-types="MySQL" /> - <sql-case id="desc_table_with_col_name" value="DESC tableName colName" db-types="MySQL" /> - <sql-case id="desc_table_with_placeholder" value="DESC tableName ___" db-types="MySQL" /> - <sql-case id="desc_table_with_wild" value="DESC tableName `u%`" db-types="MySQL" /> - <sql-case id="describe_table" value="DESCRIBE tableName" db-types="MySQL" /> - <sql-case id="describe_table_with_col_name" value="DESCRIBE tableName colName" db-types="MySQL" /> - <sql-case id="describe_table_with_placeholder" value="DESC tableName ___" db-types="MySQL" /> - <sql-case id="describe_table_with_wild" value="DESC tableName `u%`" db-types="MySQL" /> <sql-case id="explain_create_materialized_view_with_data" value="EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) CREATE MATERIALIZED VIEW matview_schema.mv_withdata2 (a) AS SELECT generate_series(1, 10) WITH DATA;" db-types="PostgreSQL" /> <sql-case id="explain_create_materialized_view_with_no_data" value="EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) CREATE MATERIALIZED VIEW matview_schema.mv_nodata2 (a) AS SELECT generate_series(1, 10) WITH NO DATA;" db-types="PostgreSQL" /> <sql-case id="explain_performance" value="EXPLAIN PERFORMANCE SELECT 1" db-types="openGauss" />