From 0945d5912ffdbde69ee667dadf30eabe878d6534 Mon Sep 17 00:00:00 2001 From: Shamil Valiev <35022048+shamilv@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:15:15 +0200 Subject: [PATCH 1/2] Add Doris grammar rules and tests --- .../src/main/antlr4/imports/doris/BaseRule.g4 | 21 +++++++++ .../main/antlr4/imports/doris/DALStatement.g4 | 12 +++++ .../sql/parser/autogen/DorisStatement.g4 | 3 ++ .../type/DorisDALStatementVisitor.java | 45 +++++++++++++++++++ .../core/database/visitor/SQLVisitorRule.java | 8 +++- .../dal/RecoverDatabaseStatement.java | 36 +++++++++++++++ .../dal/RecoverPartitionStatement.java | 45 +++++++++++++++++++ .../statement/dal/RecoverTableStatement.java | 36 +++++++++++++++ .../dal/DorisRecoverDatabaseStatement.java | 27 +++++++++++ .../dal/DorisRecoverPartitionStatement.java | 27 +++++++++++ .../doris/dal/DorisRecoverTableStatement.java | 27 +++++++++++ .../parser/jaxb/RootSQLParserTestCases.java | 12 +++++ .../dal/RecoverDatabaseStatementTestCase.java | 26 +++++++++++ .../RecoverPartitionStatementTestCase.java | 26 +++++++++++ .../dal/RecoverTableStatementTestCase.java | 26 +++++++++++ .../src/main/resources/case/dal/recover.xml | 33 ++++++++++++++ .../sql/supported/dal/recover-database.xml | 23 ++++++++++ .../sql/supported/dal/recover-partition.xml | 24 ++++++++++ .../sql/supported/dal/recover-table.xml | 24 ++++++++++ 19 files changed, 480 insertions(+), 1 deletion(-) create mode 100644 parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverDatabaseStatement.java create mode 100644 parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverPartitionStatement.java create mode 100644 parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverTableStatement.java create mode 100644 parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java create mode 100644 parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java create mode 100644 parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverDatabaseStatementTestCase.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverPartitionStatementTestCase.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverTableStatementTestCase.java create mode 100644 test/it/parser/src/main/resources/case/dal/recover.xml create mode 100644 test/it/parser/src/main/resources/sql/supported/dal/recover-database.xml create mode 100644 test/it/parser/src/main/resources/sql/supported/dal/recover-partition.xml create mode 100644 test/it/parser/src/main/resources/sql/supported/dal/recover-table.xml 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 8cf25e65a6395..742afbc38dd34 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 @@ -664,6 +664,14 @@ databaseName : identifier ; +newDatabaseName + : identifier + ; + +databaseId + : identifier + ; + databaseNames : databaseName (COMMA_ databaseName)* ; @@ -684,6 +692,10 @@ tableName : (owner DOT_)? name ; +tableId + : identifier + ; + columnName : identifier ; @@ -840,6 +852,15 @@ partitionName : identifier ; +newPartitionName + : identifier + ; + + +partitionId + : identifier + ; + identifierList : identifier (COMMA_ 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 aab259b1aed18..f14209f12924e 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 @@ -411,6 +411,18 @@ restart : RESTART ; +recoverDatabase + : RECOVER DATABASE databaseName (databaseId | AS newDatabaseName)? + ; + +recoverPartition + : RECOVER PARTITION partitionName partitionId? (AS newPartitionName)? FROM tableName + ; + +recoverTable + : RECOVER TABLE tableName tableId? (AS newDatabaseName)? + ; + shutdown : SHUTDOWN ; diff --git a/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4 b/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4 index 1c4816f721ee7..df7ef3e4eec39 100644 --- a/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4 +++ b/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4 @@ -31,6 +31,7 @@ execute | repairTable | dropTable | truncateTable + | recoverTable | createIndex | dropIndex | createProcedure @@ -39,6 +40,7 @@ execute | dropFunction | createDatabase | dropDatabase + | recoverDatabase | createEvent | dropEvent | createLogfileGroup @@ -128,6 +130,7 @@ execute | dropTablespace | delimiter | startReplica + | recoverPartition // TODO consider refactor following sytax to SEMI_? EOF ) (SEMI_ EOF? | EOF) | EOF 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 84eb110699b9b..871317d464a70 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 @@ -160,6 +160,7 @@ import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisKillStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisLoadIndexInfoStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisOptimizeTableStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverPartitionStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRepairTableStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisResetPersistStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisResetStatement; @@ -215,11 +216,15 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetSlaveOptionSegment; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverDatabaseStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverTableStatement; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import static org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.*; + /** * DAL statement visitor for Doris. */ @@ -1070,4 +1075,44 @@ 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()); + if (null != ctx.databaseId()) { + result.setDatabaseId(new IdentifierValue(ctx.databaseId().getText()).getValue()); + } + if (null != ctx.newDatabaseName()) { + result.setDatabaseName(new IdentifierValue(ctx.newDatabaseName().getText()).getValue()); + } + return result; + } + + @Override + public ASTNode visitRecoverPartition(final RecoverPartitionContext ctx) { + DorisRecoverPartitionStatement result = new DorisRecoverPartitionStatement(); + result.setPartitionName(new IdentifierValue(ctx.partitionName().getText()).getValue()); + if (null != ctx.partitionId()) { + result.setPartitionId(new IdentifierValue(ctx.partitionId().getText()).getValue()); + } + if (null != ctx.newPartitionName()) { + result.setNewPartitionName(new IdentifierValue(ctx.newPartitionName().getText()).getValue()); + } + if (null != ctx.tableName().owner()) { + result.setOwner(new IdentifierValue(ctx.tableName().owner().getText()).getValue()); + } + result.setTableName(new IdentifierValue(ctx.tableName().name().getText()).getValue()); + return result; + } + + @Override + public ASTNode visitRecoverTable(final RecoverTableContext ctx) { + DorisRecoverTableStatement result = new DorisRecoverTableStatement(); + result.setTableName(new IdentifierValue(ctx.tableName().getText()).getValue()); + if (null != ctx.tableId()) { + result.setTableName(new IdentifierValue(ctx.tableId().getText()).getValue()); + } + return result; + } } diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java index adc547a80e8e3..9a2766ba6068d 100644 --- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java +++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java @@ -85,6 +85,8 @@ public enum SQLVisitorRule { DROP_TABLE("DropTable", SQLStatementType.DDL), + RECOVER_TABLE("RecoverTable", SQLStatementType.DAL), + TRUNCATE_TABLE("TruncateTable", SQLStatementType.DDL), CREATE_INDEX("CreateIndex", SQLStatementType.DDL), @@ -137,6 +139,8 @@ public enum SQLVisitorRule { DROP_DATABASE("DropDatabase", SQLStatementType.DDL), + RECOVER_DATABASE("RecoverDatabase", SQLStatementType.DAL), + DROP_DATABASE_LINK("DropDatabaseLink", SQLStatementType.DDL), ALTER_DATABASE_DICTIONARY("AlterDatabaseDictionary", SQLStatementType.DDL), @@ -711,7 +715,9 @@ public enum SQLVisitorRule { START_REPLICA("StartReplica", SQLStatementType.RL), - OPEN("Open", SQLStatementType.DDL); + OPEN("Open", SQLStatementType.DDL), + + RECOVER_PARTITION("RecoverPartition", SQLStatementType.DAL); private final String name; 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/statement/dal/RecoverDatabaseStatement.java new file mode 100644 index 0000000000000..f261d9aef4c18 --- /dev/null +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverDatabaseStatement.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; + +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; + +/** + * Create database statement. + */ +@Getter +@Setter +public abstract class RecoverDatabaseStatement extends AbstractSQLStatement implements DDLStatement { + + private String databaseName; + + private String databaseId; + +} 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/statement/dal/RecoverPartitionStatement.java new file mode 100644 index 0000000000000..bd1bd26a53911 --- /dev/null +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverPartitionStatement.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +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.generic.table.TableNameSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; + +/** + * Create database statement. + */ +@Getter +@Setter +public abstract class RecoverPartitionStatement extends AbstractSQLStatement implements DDLStatement { + + private String partitionName; + + private String partitionId; + + private String databaseName; + + private String newPartitionName; + + private String owner; + + private String tableName; + +} 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/statement/dal/RecoverTableStatement.java new file mode 100644 index 0000000000000..ee28c90563945 --- /dev/null +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/RecoverTableStatement.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.sql.parser.statement.core.statement.dal; + +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; + +/** + * Create database statement. + */ +@Getter +@Setter +public abstract class RecoverTableStatement extends AbstractSQLStatement implements DDLStatement { + + private String tableName; + + private String tableId; + +} 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 new file mode 100644 index 0000000000000..02a2ede5ecb81 --- /dev/null +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverDatabaseStatement.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.sql.parser.statement.doris.dal; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverDatabaseStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; + +/** + * Doris create database statement. + */ +public final class DorisRecoverDatabaseStatement extends RecoverDatabaseStatement implements DorisStatement { +} 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 new file mode 100644 index 0000000000000..1f19bb7a394f4 --- /dev/null +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverPartitionStatement.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.sql.parser.statement.doris.dal; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverPartitionStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; + +/** + * Doris create database statement. + */ +public final class DorisRecoverPartitionStatement extends RecoverPartitionStatement implements DorisStatement { +} 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 new file mode 100644 index 0000000000000..a01ada6b5a2fd --- /dev/null +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisRecoverTableStatement.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.sql.parser.statement.doris.dal; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.RecoverTableStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; + +/** + * Doris create database statement. + */ +public final class DorisRecoverTableStatement extends RecoverTableStatement implements DorisStatement { +} 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 0d6471aa7e995..6aaba108e0d69 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 @@ -41,6 +41,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.KillStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.LoadIndexInfoStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.OptimizeTableStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.RecoverPartitionStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.RepairTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ResetParameterStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.ResetPersistStatementTestCase; @@ -285,6 +286,8 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.OpenStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.PreparedStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.PurgeStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.RecoverDatabaseStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.RecoverTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RefreshMatViewStmtStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.ReindexStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RenameStatementTestCase; @@ -711,6 +714,15 @@ public final class RootSQLParserTestCases { @XmlElement(name = "create-database") private final List createDatabaseTestCases = new LinkedList<>(); + @XmlElement(name = "recover-database") + private final List recoverDatabaseTestCases = new LinkedList<>(); + + @XmlElement(name = "recover-table") + private final List recoverTableTestCases = new LinkedList<>(); + + @XmlElement(name = "recover-partition") + private final List recoverPartitionTestCases = new LinkedList<>(); + @XmlElement(name = "create-database-link") private final List createDatabaseLinkTestCases = new LinkedList<>(); diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverDatabaseStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverDatabaseStatementTestCase.java new file mode 100644 index 0000000000000..073443441445e --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverDatabaseStatementTestCase.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal; + +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +/** + * Create database statement test case. + */ +public final class RecoverDatabaseStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverPartitionStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverPartitionStatementTestCase.java new file mode 100644 index 0000000000000..1613ea573ae04 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverPartitionStatementTestCase.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal; + +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +/** + * Create database statement test case. + */ +public final class RecoverPartitionStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverTableStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverTableStatementTestCase.java new file mode 100644 index 0000000000000..852d8c892dc15 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/RecoverTableStatementTestCase.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal; + +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +/** + * Create database statement test case. + */ +public final class RecoverTableStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/resources/case/dal/recover.xml b/test/it/parser/src/main/resources/case/dal/recover.xml new file mode 100644 index 0000000000000..7a9899f02e89b --- /dev/null +++ b/test/it/parser/src/main/resources/case/dal/recover.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dal/recover-database.xml b/test/it/parser/src/main/resources/sql/supported/dal/recover-database.xml new file mode 100644 index 0000000000000..249e86b247a8d --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/dal/recover-database.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dal/recover-partition.xml b/test/it/parser/src/main/resources/sql/supported/dal/recover-partition.xml new file mode 100644 index 0000000000000..528b69cda22bb --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/dal/recover-partition.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dal/recover-table.xml b/test/it/parser/src/main/resources/sql/supported/dal/recover-table.xml new file mode 100644 index 0000000000000..a44be5b6797f9 --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/dal/recover-table.xml @@ -0,0 +1,24 @@ + + + + + + + + + From 683359d73987cafbc3f4ecd3a684282e2fa079bf Mon Sep 17 00:00:00 2001 From: Shamil Valiev <35022048+shamilv@users.noreply.github.com> Date: Tue, 29 Oct 2024 06:57:45 +0100 Subject: [PATCH 2/2] Add Doris grammar rules and tests --- .../statement/type/DorisDALStatementVisitor.java | 14 ++++++++------ .../statement/dal/RecoverPartitionStatement.java | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) 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 871317d464a70..b608c9763a38c 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 @@ -124,6 +124,9 @@ 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.PartitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetSlaveOptionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowLikeSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableAssignSegment; @@ -160,7 +163,9 @@ import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisKillStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisLoadIndexInfoStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisOptimizeTableStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverDatabaseStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverPartitionStatement; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverTableStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRepairTableStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisResetPersistStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisResetStatement; @@ -213,17 +218,14 @@ import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisUninstallComponentStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisUninstallPluginStatement; import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisUseStatement; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetSlaveOptionSegment; -import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverDatabaseStatement; -import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisRecoverTableStatement; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import static org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.*; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.RecoverDatabaseContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.RecoverPartitionContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.RecoverTableContext; /** * DAL statement visitor for Doris. 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/statement/dal/RecoverPartitionStatement.java index bd1bd26a53911..c8aff8f38c7e9 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/statement/dal/RecoverPartitionStatement.java @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement;