未验证 提交 f3322ee0 编写于 作者: D DuanZhengqiang 提交者: GitHub

support mysql store procedure create, alter, drop and call statement (#6771)

* support mysql store procedure create, alter, drop and call

* modify code format
上级 5411d908
......@@ -36,6 +36,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStat
import org.apache.shardingsphere.sql.parser.binder.statement.ddl.DropIndexStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.ddl.DropTableStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.ddl.TruncateStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.CallStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.DeleteStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.SelectStatementContext;
......@@ -58,6 +59,7 @@ import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DDLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropTableStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.TruncateStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.CallStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.DMLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement;
......@@ -110,6 +112,9 @@ public final class SQLStatementContextFactory {
if (sqlStatement instanceof InsertStatement) {
return new InsertStatementContext(schemaMetaData, parameters, (InsertStatement) sqlStatement);
}
if (sqlStatement instanceof CallStatement) {
return new CallStatementContext((CallStatement) sqlStatement);
}
throw new UnsupportedOperationException(String.format("Unsupported SQL statement `%s`", sqlStatement.getClass().getSimpleName()));
}
......
/*
* 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.binder.statement.dml;
import lombok.Getter;
import lombok.ToString;
import org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.CallStatement;
@Getter
@ToString(callSuper = true)
public final class CallStatementContext extends CommonSQLStatementContext<CallStatement> {
public CallStatementContext(final CallStatement sqlStatement) {
super(sqlStatement);
}
}
......@@ -614,3 +614,15 @@ pattern
connectionId_
: NUMBER_
;
labelName
: identifier
;
cursorName
: identifier
;
conditionName
: identifier
;
......@@ -17,7 +17,7 @@
grammar DDLStatement;
import Symbol, Keyword, MySQLKeyword, Literals, BaseRule, DMLStatement;
import Symbol, Keyword, MySQLKeyword, Literals, BaseRule, DMLStatement, DALStatement;
createTable
: CREATE TEMPORARY? TABLE notExistClause_ tableName (createDefinitionClause? tableOptions_? partitionClause? duplicateAsQueryExpression? | createLikeClause)
......@@ -578,7 +578,7 @@ timestampValue
;
routineBody
: NOT_SUPPORT_
: simpleStatement | compoundStatement
;
serverOption_
......@@ -600,9 +600,173 @@ routineOption_
;
procedureParameter_
: ( IN | OUT | INOUT ) identifier dataType
: (IN | OUT | INOUT)? identifier dataType
;
fileSizeLiteral_
: FILESIZE_LITERAL | numberLiterals
;
simpleStatement
: validStatement
;
compoundStatement
: beginStatement
;
validStatement
: (createTable | alterTable | dropTable | truncateTable
| insert | replace | update | delete | select
| setVariable | beginStatement | declareStatement | flowControlStatement | cursorStatement | conditionHandlingStatement) SEMI_?
;
beginStatement
: (labelName COLON_)? BEGIN validStatement* END labelName? SEMI_?
;
declareStatement
: DECLARE variable (COMMA_ variable)* dataType (DEFAULT simpleExpr)*
;
flowControlStatement
: caseStatement | ifStatement | iterateStatement | leaveStatement | loopStatement | repeatStatement | returnStatement | whileStatement
;
caseStatement
: CASE expr?
(WHEN expr THEN validStatement+)+
(ELSE validStatement+)?
END CASE
;
ifStatement
: IF expr THEN validStatement+
(ELSEIF expr THEN validStatement+)*
(ELSE validStatement+)?
END IF
;
iterateStatement
: ITERATE labelName
;
leaveStatement
: LEAVE labelName
;
loopStatement
: (labelName COLON_)? LOOP
validStatement+
END LOOP labelName?
;
repeatStatement
: (labelName COLON_)? REPEAT
validStatement+
UNTIL expr
END REPEAT labelName?
;
returnStatement
: RETURN expr
;
whileStatement
: (labelName COLON_)? WHILE expr DO
validStatement+
END WHILE labelName?
;
cursorStatement
: cursorCloseStatement | cursorDeclareStatement | cursorFetchStatement | cursorOpenStatement
;
cursorCloseStatement
: CLOSE cursorName
;
cursorDeclareStatement
: DECLARE cursorName CURSOR FOR select
;
cursorFetchStatement
: FETCH ((NEXT)? FROM)? cursorName INTO variable (COMMA_ variable)*
;
cursorOpenStatement
: OPEN cursorName
;
conditionHandlingStatement
: declareConditionStatement | declareHandlerStatement | getDiagnosticsStatement | resignalStatement | signalStatement
;
declareConditionStatement
: DECLARE conditionName CONDITION FOR conditionValue
;
declareHandlerStatement
: DECLARE handlerAction HANDLER FOR conditionValue (COMMA_ conditionValue)* validStatement
;
getDiagnosticsStatement
: GET (CURRENT | STACKED)? DIAGNOSTICS
((statementInformationItem (COMMA_ statementInformationItem)*)
| (CONDITION conditionNumber conditionInformationItem (COMMA_ conditionInformationItem)*))
;
statementInformationItem
: variable EQ_ statementInformationItemName
;
conditionInformationItem
: variable EQ_ conditionInformationItemName
;
conditionNumber
: variable | numberLiterals
;
statementInformationItemName
: NUMBER
| ROW_COUNT
;
conditionInformationItemName
: CLASS_ORIGIN
| SUBCLASS_ORIGIN
| RETURNED_SQLSTATE
| MESSAGE_TEXT
| MYSQL_ERRNO
| CONSTRAINT_CATALOG
| CONSTRAINT_SCHEMA
| CONSTRAINT_NAME
| CATALOG_NAME
| SCHEMA_NAME
| TABLE_NAME
| COLUMN_NAME
| CURSOR_NAME
;
handlerAction
: CONTINUE | EXIT | UNDO
;
conditionValue
: numberLiterals | SQLSTATE (VALUE)? stringLiterals | conditionName | SQLWARNING | NOT FOUND | SQLEXCEPTION
;
resignalStatement
: RESIGNAL conditionValue?
(SET signalInformationItem (COMMA_ signalInformationItem)*)?
;
signalStatement
: SIGNAL conditionValue
(SET signalInformationItem (COMMA_ signalInformationItem)*)?
;
signalInformationItem
: conditionInformationItemName EQ_ expr
;
......@@ -222,7 +222,7 @@ projections
;
projection
: expr (AS? alias)? | qualifiedShorthand
: expr (AS? alias)? (INTO columnName)? | qualifiedShorthand
;
unqualifiedShorthand
......
......@@ -34,6 +34,9 @@ execute
| truncateTable
| createIndex
| dropIndex
| createProcedure
| alterProcedure
| dropProcedure
| setTransaction
| beginTransaction
| setAutoCommit
......
......@@ -23,6 +23,7 @@ import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.statement.DDLVisitor;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AddColumnSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterDefinitionClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterProcedureContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterTableContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeColumnSpecificationContext;
......@@ -34,12 +35,14 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateD
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateDefinitionContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateIndexContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateLikeClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateProcedureContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateTableContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateViewContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropColumnSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropDatabaseContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropIndexContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropPrimaryKeySpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropProcedureContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropTableContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropViewContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FirstOrAfterColumnContext;
......@@ -71,13 +74,16 @@ import org.apache.shardingsphere.sql.parser.sql.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.DataTypeSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterProcedureStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateProcedureStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateViewStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropProcedureStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropTableStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropViewStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.RenameTableStatement;
......@@ -411,4 +417,19 @@ public final class MySQLDDLVisitor extends MySQLVisitor implements DDLVisitor {
}
return result;
}
@Override
public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
return new CreateProcedureStatement();
}
@Override
public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
return new AlterProcedureStatement();
}
@Override
public ASTNode visitDropProcedure(final DropProcedureContext ctx) {
return new DropProcedureStatement();
}
}
......@@ -51,6 +51,12 @@ public enum VisitorRule {
ALTER_INDEX("AlterIndex", SQLStatementType.DDL),
DROP_INDEX("DropIndex", SQLStatementType.DDL),
CREATE_PROCEDURE("CreateProcedure", SQLStatementType.DDL),
ALTER_PROCEDURE("AlterProcedure", SQLStatementType.DDL),
DROP_PROCEDURE("DropProcedure", SQLStatementType.DDL),
SET_TRANSACTION("SetTransaction", SQLStatementType.TCL),
......
/*
* 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.sql.statement.ddl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* Alter procedure statement.
*/
@RequiredArgsConstructor
@Getter
public final class AlterProcedureStatement extends DDLStatement {
}
/*
* 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.sql.statement.ddl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* Create procedure statement.
*/
@RequiredArgsConstructor
@Getter
public final class CreateProcedureStatement extends DDLStatement {
}
/*
* 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.sql.statement.ddl;
/**
* Drop procedure statement.
*/
public final class DropProcedureStatement extends DDLStatement {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册