Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Doris grammar rules for RECOVER and tests #33436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,14 @@ databaseName
: identifier
;

newDatabaseName
: identifier
;

databaseId
: identifier
;

databaseNames
: databaseName (COMMA_ databaseName)*
;
Expand All @@ -684,6 +692,10 @@ tableName
: (owner DOT_)? name
;

tableId
: identifier
;

columnName
: identifier
;
Expand Down Expand Up @@ -840,6 +852,15 @@ partitionName
: identifier
;

newPartitionName
: identifier
;


partitionId
: identifier
;

identifierList
: identifier (COMMA_ identifier)*
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ restart
: RESTART
;

recoverDatabase
: RECOVER DATABASE databaseName (databaseId | AS newDatabaseName)?
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use rule-element-labels instead of the newDatabaseName rule.

;

recoverPartition
: RECOVER PARTITION partitionName partitionId? (AS newPartitionName)? FROM tableName
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

;

recoverTable
: RECOVER TABLE tableName tableId? (AS newDatabaseName)?
;

shutdown
: SHUTDOWN
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ execute
| repairTable
| dropTable
| truncateTable
| recoverTable
| createIndex
| dropIndex
| createProcedure
Expand All @@ -39,6 +40,7 @@ execute
| dropFunction
| createDatabase
| dropDatabase
| recoverDatabase
| createEvent
| dropEvent
| createLogfileGroup
Expand Down Expand Up @@ -128,6 +130,7 @@ execute
| dropTablespace
| delimiter
| startReplica
| recoverPartition
// TODO consider refactor following sytax to SEMI_? EOF
) (SEMI_ EOF? | EOF)
| EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,6 +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;
Expand Down Expand Up @@ -212,14 +218,15 @@
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 java.util.Collection;
import java.util.LinkedList;
import java.util.List;

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.
*/
Expand Down Expand Up @@ -1070,4 +1077,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you consider using the DatabaseSegment?


private String databaseId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 RecoverPartitionStatement extends AbstractSQLStatement implements DDLStatement {

private String partitionName;

private String partitionId;

private String databaseName;

private String newPartitionName;

private String owner;

private String tableName;

}
Comment on lines +30 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, use class types instead of the primitive types.

Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to reuse this abstract class in other databases? If not, we should consider removing it.

}
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the code comments.

*/
public final class DorisRecoverPartitionStatement extends RecoverPartitionStatement implements DorisStatement {
}
Loading