diff --git a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4 b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4 index b9c35e2392636..0f17e10ecf055 100644 --- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4 +++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4 @@ -667,10 +667,6 @@ databaseName : identifier ; -newDatabaseName - : identifier - ; - databaseId : identifier ; @@ -855,11 +851,6 @@ partitionName : identifier ; -newPartitionName - : identifier - ; - - partitionId : identifier ; diff --git a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4 b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4 index f14209f12924e..db095d783f52a 100644 --- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4 +++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4 @@ -412,15 +412,15 @@ restart ; recoverDatabase - : RECOVER DATABASE databaseName (databaseId | AS newDatabaseName)? + : RECOVER DATABASE databaseName (databaseId | AS newDatabaseName=identifier)? ; recoverPartition - : RECOVER PARTITION partitionName partitionId? (AS newPartitionName)? FROM tableName + : RECOVER PARTITION partitionName partitionId? (AS newPartitionName=identifier)? FROM tableName ; recoverTable - : RECOVER TABLE tableName tableId? (AS newDatabaseName)? + : RECOVER TABLE tableName tableId? (AS newTableName=identifier)? ; shutdown 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 807c281389ed6..86fa85d466912 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 @@ -123,6 +123,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.LoadTableIndexSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionIdSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment; @@ -137,8 +138,12 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseIdSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableIdSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -935,17 +940,17 @@ private VariableAssignSegment getVariableAssignSegment(final OptionValueContext ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText()); return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), variable, ctx.setExprOrDefault().getText()); } - + private VariableAssignSegment getVariableAssignSegment(final OptionValueListContext ctx) { VariableSegment variable = new VariableSegment( ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText()); return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.setExprOrDefault().stop.getStopIndex(), variable, ctx.setExprOrDefault().getText()); } - + private VariableAssignSegment getVariableAssignSegment(final OptionValueNoOptionTypeContext ctx) { return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getVariableSegment(ctx), getAssignValue(ctx)); } - + private VariableSegment getVariableSegment(final OptionValueNoOptionTypeContext ctx) { if (null != ctx.NAMES()) { // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection @@ -1080,44 +1085,89 @@ public ASTNode visitHelp(final HelpContext ctx) { result.setSearchString(ctx.textOrIdentifier().getText()); return result; } - + @Override public ASTNode visitRecoverDatabase(final RecoverDatabaseContext ctx) { DorisRecoverDatabaseStatement result = new DorisRecoverDatabaseStatement(); - result.setDatabaseName(new IdentifierValue(ctx.databaseName().getText()).getValue()); + DatabaseSegment databaseName = new DatabaseSegment( + ctx.databaseName().start.getStartIndex(), + ctx.databaseName().stop.getStopIndex(), + new IdentifierValue(ctx.databaseName().identifier().getText())); + result.setDatabaseName(databaseName); + if (null != ctx.databaseId()) { - result.setDatabaseId(new IdentifierValue(ctx.databaseId().getText()).getValue()); + DatabaseIdSegment databaseIdSegment = new DatabaseIdSegment( + ctx.databaseId().start.getStartIndex(), + ctx.databaseId().stop.getStopIndex(), + new IdentifierValue(ctx.databaseId().identifier().getText())); + result.setDatabaseId(databaseIdSegment); } - if (null != ctx.newDatabaseName()) { - result.setDatabaseName(new IdentifierValue(ctx.newDatabaseName().getText()).getValue()); + if (null != ctx.newDatabaseName) { + DatabaseSegment newDatabaseName = new DatabaseSegment( + ctx.newDatabaseName.start.getStartIndex(), + ctx.newDatabaseName.stop.getStopIndex(), + new IdentifierValue(ctx.newDatabaseName.getText())); + result.setDatabaseName(newDatabaseName); } return result; } - + @Override public ASTNode visitRecoverPartition(final RecoverPartitionContext ctx) { DorisRecoverPartitionStatement result = new DorisRecoverPartitionStatement(); - result.setPartitionName(new IdentifierValue(ctx.partitionName().getText()).getValue()); + PartitionSegment partitionSegment = new PartitionSegment( + ctx.partitionName().start.getStartIndex(), + ctx.partitionName().stop.getStopIndex(), + new IdentifierValue(ctx.partitionName().identifier().getText())); + result.setPartitionName(partitionSegment); if (null != ctx.partitionId()) { - result.setPartitionId(new IdentifierValue(ctx.partitionId().getText()).getValue()); + PartitionIdSegment partitionId = new PartitionIdSegment( + ctx.partitionId().start.getStartIndex(), + ctx.partitionId().stop.getStopIndex(), + new IdentifierValue(ctx.partitionId().identifier().getText())); + result.setPartitionId(partitionId); } - if (null != ctx.newPartitionName()) { - result.setNewPartitionName(new IdentifierValue(ctx.newPartitionName().getText()).getValue()); + if (null != ctx.newPartitionName) { + final PartitionSegment newPartitionName = new PartitionSegment( + ctx.newPartitionName.start.getStartIndex(), + ctx.newPartitionName.stop.getStopIndex(), + new IdentifierValue(ctx.newPartitionName.getText())); + result.setNewPartitionName(newPartitionName); } - if (null != ctx.tableName().owner()) { - result.setOwner(new IdentifierValue(ctx.tableName().owner().getText()).getValue()); - } - result.setTableName(new IdentifierValue(ctx.tableName().name().getText()).getValue()); + SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName()); + result.setTableName(simpleTableSegment); + return result; } - + @Override public ASTNode visitRecoverTable(final RecoverTableContext ctx) { DorisRecoverTableStatement result = new DorisRecoverTableStatement(); - result.setTableName(new IdentifierValue(ctx.tableName().getText()).getValue()); + SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName()); + result.setTableName(simpleTableSegment); if (null != ctx.tableId()) { - result.setTableName(new IdentifierValue(ctx.tableId().getText()).getValue()); + final TableIdSegment tableIdSegment = new TableIdSegment( + ctx.tableId().start.getStartIndex(), + ctx.tableId().stop.getStopIndex(), + new IdentifierValue(ctx.tableId().getText())); + result.setTableId(tableIdSegment); } return result; } + + private SimpleTableSegment createSimpleTableSegment(final TableNameContext tableNameContext) { + final TableNameSegment tableNameSegment = new TableNameSegment( + tableNameContext.start.getStartIndex(), + tableNameContext.stop.getStopIndex(), + new IdentifierValue(tableNameContext.getText())); + SimpleTableSegment simpleTableSegment = new SimpleTableSegment(tableNameSegment); + if (null != tableNameContext.owner()) { + OwnerSegment ownerSegment = new OwnerSegment( + tableNameContext.owner().start.getStartIndex(), + tableNameContext.owner().stop.getStopIndex(), + new IdentifierValue(tableNameContext.owner().getText())); + simpleTableSegment.setOwner(ownerSegment); + } + return simpleTableSegment; + } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverDatabaseStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/dal/PartitionIdSegment.java similarity index 63% rename from parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverDatabaseStatement.java rename to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/dal/PartitionIdSegment.java index f261d9aef4c18..d303424794820 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverDatabaseStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/dal/PartitionIdSegment.java @@ -15,22 +15,25 @@ * limitations under the License. */ -package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; +package org.apache.shardingsphere.sql.parser.statement.core.segment.dal; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; -import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; /** - * Create database statement. + * Partition Id segment. */ +@RequiredArgsConstructor @Getter @Setter -public abstract class RecoverDatabaseStatement extends AbstractSQLStatement implements DDLStatement { +public final class PartitionIdSegment implements SQLSegment { - private String databaseName; + private final int startIndex; - private String databaseId; + private final int stopIndex; + private final IdentifierValue name; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverTableStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/DatabaseIdSegment.java similarity index 62% rename from parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverTableStatement.java rename to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/DatabaseIdSegment.java index ee28c90563945..345aa694de0b7 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverTableStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/DatabaseIdSegment.java @@ -15,22 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; +package org.apache.shardingsphere.sql.parser.statement.core.segment.generic; import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; /** - * Create database statement. + * Database Id segment. */ +@RequiredArgsConstructor @Getter -@Setter -public abstract class RecoverTableStatement extends AbstractSQLStatement implements DDLStatement { +public final class DatabaseIdSegment implements SQLSegment { - private String tableName; + private final int startIndex; - private String tableId; + private final int stopIndex; + private final IdentifierValue identifier; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverPartitionStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableIdSegment.java similarity index 57% rename from parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverPartitionStatement.java rename to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableIdSegment.java index c8aff8f38c7e9..d6901e8bc970d 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverPartitionStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableIdSegment.java @@ -15,30 +15,23 @@ * limitations under the License. */ -package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; +package org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table; import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; /** - * Create database statement. + * Table Id segment. */ +@RequiredArgsConstructor @Getter -@Setter -public abstract class RecoverPartitionStatement extends AbstractSQLStatement implements DDLStatement { +public final class TableIdSegment implements SQLSegment { - private String partitionName; + private final int startIndex; - private String partitionId; - - private String databaseName; - - private String newPartitionName; - - private String owner; - - private String tableName; + private final int stopIndex; + private final IdentifierValue identifier; } diff --git a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java index 02a2ede5ecb81..af7d5046255b4 100644 --- a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java @@ -17,11 +17,22 @@ package org.apache.shardingsphere.sql.parser.statement.doris.dal; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverDatabaseStatement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseIdSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; /** - * Doris create database statement. + * Doris recover database statement. */ -public final class DorisRecoverDatabaseStatement extends RecoverDatabaseStatement implements DorisStatement { + +@Setter +@Getter +public final class DorisRecoverDatabaseStatement extends AbstractSQLStatement implements DorisStatement { + + private DatabaseSegment databaseName; + + private DatabaseIdSegment databaseId; } diff --git a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java index 1f19bb7a394f4..8c3cf4ed96288 100644 --- a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java @@ -17,11 +17,29 @@ package org.apache.shardingsphere.sql.parser.statement.doris.dal; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverPartitionStatement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionIdSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionSegment; +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.AbstractSQLStatement; import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; /** - * Doris create database statement. + * Doris recover partition statement. */ -public final class DorisRecoverPartitionStatement extends RecoverPartitionStatement implements DorisStatement { +@Setter +@Getter +public final class DorisRecoverPartitionStatement extends AbstractSQLStatement implements DorisStatement { + + private PartitionSegment partitionName; + + private PartitionSegment newPartitionName; + + private PartitionIdSegment partitionId; + + private DatabaseSegment databaseName; + + private SimpleTableSegment tableName; } diff --git a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java index a01ada6b5a2fd..76938bc85559d 100644 --- a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java @@ -17,11 +17,22 @@ package org.apache.shardingsphere.sql.parser.statement.doris.dal; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverTableStatement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableIdSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; /** - * Doris create database statement. + * Doris recover table statement. */ -public final class DorisRecoverTableStatement extends RecoverTableStatement implements DorisStatement { + +@Getter +@Setter +public final class DorisRecoverTableStatement extends AbstractSQLStatement implements DorisStatement { + + private SimpleTableSegment tableName; + + private TableIdSegment tableId; }