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 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
1. Mode: Support modifying Hikari-CP configurations via props in standalone mode [#34185](https://github.com/apache/shardingsphere/pull/34185)
1. Encrypt: Support insert statement rewrite use quote [#34259](https://github.com/apache/shardingsphere/pull/34259)
1. Infra: Support connecting to Firebird via jdbcUrl containing the absolute path to fdb - [#34335](https://github.com/apache/shardingsphere/pull/34335)
1. SQL Parser: Support parsing Doris RECOVER - [#31504](https://github.com/apache/shardingsphere/pull/31504)

### Bug Fixes

Expand Down
12 changes: 12 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 @@ -667,6 +667,10 @@ databaseName
: identifier
;

databaseId
: identifier
;

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

tableId
: identifier
;

columnName
: identifier
;
Expand Down Expand Up @@ -843,6 +851,10 @@ partitionName
: 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=identifier)?
;

recoverPartition
: RECOVER PARTITION partitionName partitionId? (AS newPartitionName=identifier)? FROM tableName
;

recoverTable
: RECOVER TABLE tableName tableId? (AS newTableName=identifier)?
;

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 @@ -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;
Expand All @@ -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;
Expand All @@ -163,6 +168,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 @@ -220,6 +228,10 @@
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 @@ -1073,4 +1085,88 @@ public ASTNode visitHelp(final HelpContext ctx) {
result.setSearchString(ctx.textOrIdentifier().getText());
return result;
}

@Override
public ASTNode visitRecoverDatabase(final RecoverDatabaseContext ctx) {
DorisRecoverDatabaseStatement result = new DorisRecoverDatabaseStatement();
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()) {
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) {
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();
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()) {
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) {
final PartitionSegment newPartitionName = new PartitionSegment(
ctx.newPartitionName.start.getStartIndex(),
ctx.newPartitionName.stop.getStopIndex(),
new IdentifierValue(ctx.newPartitionName.getText()));
result.setNewPartitionName(newPartitionName);
}
SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName());
result.setTableName(simpleTableSegment);

return result;
}

@Override
public ASTNode visitRecoverTable(final RecoverTableContext ctx) {
DorisRecoverTableStatement result = new DorisRecoverTableStatement();
SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName());
result.setTableName(simpleTableSegment);
if (null != ctx.tableId()) {
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;
}
}
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,39 @@
/*
* 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.segment.dal;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

/**
* Partition Id segment.
*/
@RequiredArgsConstructor
@Getter
@Setter
public final class PartitionIdSegment implements SQLSegment {

private final int startIndex;

private final int stopIndex;

private final IdentifierValue name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.segment.generic;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

/**
* Database Id segment.
*/
@RequiredArgsConstructor
@Getter
public final class DatabaseIdSegment implements SQLSegment {

private final int startIndex;

private final int stopIndex;

private final IdentifierValue identifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.segment.generic.table;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

/**
* Table Id segment.
*/
@RequiredArgsConstructor
@Getter
public final class TableIdSegment implements SQLSegment {

private final int startIndex;

private final int stopIndex;

private final IdentifierValue identifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 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 recover database statement.
*/
@Setter
@Getter
public final class DorisRecoverDatabaseStatement extends AbstractSQLStatement implements DorisStatement {

private DatabaseSegment databaseName;

private DatabaseIdSegment databaseId;
}
Loading
Loading