From f72ebcb4bb27be76b64620d3513888843f299158 Mon Sep 17 00:00:00 2001 From: Timofey Sakharovsky <81485481+TedCraft@users.noreply.github.com> Date: Sun, 24 Nov 2024 11:56:39 +0300 Subject: [PATCH] Added firebird database type and parser module (#33773) * Add firebird datatype type and parser module Co-authored-by: vasilevskyy * Update RELEASE-NOTES.md --------- Co-authored-by: vasilevskyy --- RELEASE-NOTES.md | 2 + infra/database/type/firebird/pom.xml | 43 + .../FirebirdConnectionPropertiesParser.java | 45 + .../database/FirebirdDatabaseMetaData.java | 48 + .../firebird/type/FirebirdDatabaseType.java | 40 + ....core.connector.ConnectionPropertiesParser | 18 + ....metadata.database.DialectDatabaseMetaData | 18 + ...here.infra.database.core.type.DatabaseType | 18 + ...irebirdConnectionPropertiesParserTest.java | 67 ++ .../FirebirdDatabaseMetaDataTest.java | 44 + .../type/FirebirdDatabaseTypeTest.java | 36 + infra/database/type/pom.xml | 1 + .../DriverJDBCPushDownExecuteExecutor.java | 10 + ...iverJDBCPushDownExecuteUpdateExecutor.java | 10 + parser/sql/dialect/firebird/pom.xml | 40 + .../main/antlr4/imports/firebird/Alphabet.g4 | 49 + .../main/antlr4/imports/firebird/BaseRule.g4 | 566 ++++++++++ .../main/antlr4/imports/firebird/Comments.g4 | 23 + .../antlr4/imports/firebird/DCLStatement.g4 | 151 +++ .../antlr4/imports/firebird/DDLStatement.g4 | 572 ++++++++++ .../antlr4/imports/firebird/DMLStatement.g4 | 202 ++++ .../imports/firebird/FirebirdKeyword.g4 | 980 ++++++++++++++++++ .../main/antlr4/imports/firebird/Keyword.g4 | 545 ++++++++++ .../main/antlr4/imports/firebird/Literals.g4 | 49 + .../main/antlr4/imports/firebird/Symbol.g4 | 59 ++ .../antlr4/imports/firebird/TCLStatement.g4 | 40 + .../sql/parser/autogen/FirebirdStatement.g4 | 55 + .../parser/firebird/parser/FirebirdLexer.java | 32 + .../firebird/parser/FirebirdParser.java | 40 + .../firebird/parser/FirebirdParserFacade.java | 43 + .../statement/FirebirdStatementVisitor.java | 575 ++++++++++ .../FirebirdStatementVisitorFacade.java | 72 ++ .../type/FirebirdDALStatementVisitor.java | 27 + .../type/FirebirdDCLStatementVisitor.java | 65 ++ .../type/FirebirdDDLStatementVisitor.java | 321 ++++++ .../type/FirebirdDMLStatementVisitor.java | 492 +++++++++ .../type/FirebirdTCLStatementVisitor.java | 56 + ...here.sql.parser.spi.DialectSQLParserFacade | 18 + ...e.sql.parser.spi.SQLStatementVisitorFacade | 18 + .../internal/InternalFirebirdParserIT.java | 25 + .../InternalUnsupportedFirebirdParserIT.java | 25 + .../src/test/resources/logback-test.xml | 34 + parser/sql/dialect/pom.xml | 1 + parser/sql/engine/pom.xml | 5 + parser/sql/statement/type/firebird/pom.xml | 36 + .../statement/firebird/FirebirdStatement.java | 33 + .../firebird/dal/FirebirdSetStatement.java | 27 + .../firebird/dal/FirebirdShowStatement.java | 27 + .../dcl/FirebirdAlterUserStatement.java | 27 + .../dcl/FirebirdCreateRoleStatement.java | 27 + .../dcl/FirebirdCreateUserStatement.java | 27 + .../dcl/FirebirdDropRoleStatement.java | 27 + .../dcl/FirebirdDropUserStatement.java | 27 + .../firebird/dcl/FirebirdGrantStatement.java | 27 + .../dcl/FirebirdRenameUserStatement.java | 28 + .../firebird/dcl/FirebirdRevokeStatement.java | 27 + .../ddl/FirebirdAlterDomainStatement.java | 27 + .../ddl/FirebirdAlterProcedureStatement.java | 27 + .../ddl/FirebirdAlterSequenceStatement.java | 27 + .../ddl/FirebirdAlterTableStatement.java | 27 + .../ddl/FirebirdAlterTriggerStatement.java | 27 + .../ddl/FirebirdCommentStatement.java | 27 + .../ddl/FirebirdCreateCollationStatement.java | 27 + .../ddl/FirebirdCreateDomainStatement.java | 27 + .../ddl/FirebirdCreateFunctionStatement.java | 27 + .../ddl/FirebirdCreateProcedureStatement.java | 27 + .../ddl/FirebirdCreateSequenceStatement.java | 27 + .../ddl/FirebirdCreateTableStatement.java | 27 + .../ddl/FirebirdCreateTriggerStatement.java | 27 + .../ddl/FirebirdDropTableStatement.java | 27 + .../ddl/FirebirdExecuteStatement.java | 27 + .../firebird/dml/FirebirdDeleteStatement.java | 27 + .../firebird/dml/FirebirdInsertStatement.java | 27 + .../firebird/dml/FirebirdMergeStatement.java | 27 + .../firebird/dml/FirebirdSelectStatement.java | 43 + .../firebird/dml/FirebirdUpdateStatement.java | 27 + .../firebird/tcl/FirebirdCommitStatement.java | 27 + .../tcl/FirebirdRollbackStatement.java | 27 + .../tcl/FirebirdSavepointStatement.java | 27 + .../tcl/FirebirdSetTransactionStatement.java | 27 + parser/sql/statement/type/pom.xml | 1 + .../parser/internal/cases/sql/SQLCases.java | 2 +- .../resources/case/ddl/create-function.xml | 1 + .../resources/case/ddl/create-procedure.xml | 13 + .../sql/supported/dcl/create-role.xml | 2 +- .../sql/supported/dcl/create-user.xml | 2 +- .../sql/supported/ddl/create-function.xml | 1 + .../sql/supported/ddl/create-procedure.xml | 2 + .../sql/supported/dml/select-comment.xml | 6 +- 89 files changed, 6608 insertions(+), 6 deletions(-) create mode 100644 infra/database/type/firebird/pom.xml create mode 100644 infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java create mode 100644 infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java create mode 100644 infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseType.java create mode 100644 infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser create mode 100644 infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData create mode 100644 infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType create mode 100644 infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java create mode 100644 infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaDataTest.java create mode 100644 infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseTypeTest.java create mode 100644 parser/sql/dialect/firebird/pom.xml create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Alphabet.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/BaseRule.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Comments.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DCLStatement.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DDLStatement.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/FirebirdKeyword.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Keyword.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Literals.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Symbol.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/TCLStatement.g4 create mode 100644 parser/sql/dialect/firebird/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/FirebirdStatement.g4 create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdLexer.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParser.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParserFacade.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitorFacade.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDALStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDCLStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDDLStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdTCLStatementVisitor.java create mode 100644 parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade create mode 100644 parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade create mode 100644 parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalFirebirdParserIT.java create mode 100644 parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalUnsupportedFirebirdParserIT.java create mode 100644 parser/sql/dialect/firebird/src/test/resources/logback-test.xml create mode 100644 parser/sql/statement/type/firebird/pom.xml create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/FirebirdStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdSetStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdShowStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdAlterUserStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateRoleStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateUserStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropRoleStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropUserStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdGrantStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRenameUserStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRevokeStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterDomainStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterProcedureStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterSequenceStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTableStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTriggerStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCommentStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateCollationStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateDomainStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateFunctionStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateProcedureStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateSequenceStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTableStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTriggerStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdDropTableStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdExecuteStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdMergeStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdSelectStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdCommitStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdRollbackStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSavepointStatement.java create mode 100644 parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSetTransactionStatement.java diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 8d72e00ed165f..911bcde21bcf6 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -4,6 +4,8 @@ ### New Features +1. Kernel: Add firebird sql parser module and database type [#33773](https://github.com/apache/shardingsphere/pull/33773) + ### Enhancements 1. Kernel: Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382) diff --git a/infra/database/type/firebird/pom.xml b/infra/database/type/firebird/pom.xml new file mode 100644 index 0000000000000..95ef8db8741b5 --- /dev/null +++ b/infra/database/type/firebird/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-database-type + 5.5.2-SNAPSHOT + + shardingsphere-infra-database-firebird + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-infra-database-core + ${project.version} + + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + + diff --git a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java new file mode 100644 index 0000000000000..0f803ebd0e64c --- /dev/null +++ b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.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.infra.database.firebird.connector; + +import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; +import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser; +import org.apache.shardingsphere.infra.database.core.connector.StandardConnectionProperties; +import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl; +import org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser; + +import java.util.Properties; + +/** + * Connection properties parser of Firebird. + */ +public final class FirebirdConnectionPropertiesParser implements ConnectionPropertiesParser { + + private static final int DEFAULT_PORT = 3050; + + @Override + public ConnectionProperties parse(final String url, final String username, final String catalog) { + JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url); + return new StandardConnectionProperties(jdbcUrl.getHostname(), jdbcUrl.getPort(DEFAULT_PORT), jdbcUrl.getDatabase(), null, jdbcUrl.getQueryProperties(), new Properties()); + } + + @Override + public String getDatabaseType() { + return "Firebird"; + } +} diff --git a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java new file mode 100644 index 0000000000000..a03a6e59680f5 --- /dev/null +++ b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java @@ -0,0 +1,48 @@ +/* + * 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.infra.database.firebird.metadata.database; + +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; + +/** + * Database metadata of Firebird. + */ +public final class FirebirdDatabaseMetaData implements DialectDatabaseMetaData { + + @Override + public QuoteCharacter getQuoteCharacter() { + return QuoteCharacter.QUOTE; + } + + @Override + public NullsOrderType getDefaultNullsOrderType() { + return NullsOrderType.LOW; + } + + @Override + public String formatTableNamePattern(final String tableNamePattern) { + return tableNamePattern.toUpperCase(); + } + + @Override + public String getDatabaseType() { + return "Firebird"; + } +} diff --git a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseType.java b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseType.java new file mode 100644 index 0000000000000..d3e275b4d2799 --- /dev/null +++ b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseType.java @@ -0,0 +1,40 @@ +/* + * 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.infra.database.firebird.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; + +import java.util.Arrays; +import java.util.Collection; + +/** + * Database type of Firebird. + */ +public final class FirebirdDatabaseType implements DatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird"); + } + + @Override + public String getType() { + return "Firebird"; + } + +} diff --git a/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser new file mode 100644 index 0000000000000..6d440a2f748b2 --- /dev/null +++ b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.infra.database.firebird.connector.FirebirdConnectionPropertiesParser diff --git a/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData new file mode 100644 index 0000000000000..f9db1b93a022d --- /dev/null +++ b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.infra.database.firebird.metadata.database.FirebirdDatabaseMetaData diff --git a/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType new file mode 100644 index 0000000000000..79c142d883e1b --- /dev/null +++ b/infra/database/type/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.infra.database.firebird.type.FirebirdDatabaseType diff --git a/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java new file mode 100644 index 0000000000000..a980af1367ca9 --- /dev/null +++ b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java @@ -0,0 +1,67 @@ +/* + * 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.infra.database.firebird.connector; + +import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; +import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser; +import org.apache.shardingsphere.infra.database.core.exception.UnrecognizedDatabaseURLException; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import java.util.Properties; +import java.util.stream.Stream; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class FirebirdConnectionPropertiesParserTest { + + private final ConnectionPropertiesParser parser = DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, TypedSPILoader.getService(DatabaseType.class, "Firebird")); + + @ParameterizedTest(name = "{0}") + @ArgumentsSource(NewConstructorTestCaseArgumentsProvider.class) + void assertNewConstructor(final String name, final String url, final String hostname, final int port, final String catalog, final String schema, final Properties queryProps) { + ConnectionProperties actual = parser.parse(url, null, null); + assertThat(actual.getHostname(), is(hostname)); + assertThat(actual.getPort(), is(port)); + assertThat(actual.getCatalog(), is(catalog)); + assertThat(actual.getSchema(), is(schema)); + assertThat(actual.getQueryProperties(), is(queryProps)); + } + + @Test + void assertNewConstructorFailure() { + assertThrows(UnrecognizedDatabaseURLException.class, () -> parser.parse("jdbc:firebirdsql:xxxxxxxx", null, null)); + } + + private static class NewConstructorTestCaseArgumentsProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(final ExtensionContext extensionContext) { + return Stream.of(Arguments.of("simple", "jdbc:firebirdsql://127.0.0.1/foo_ds", "127.0.0.1", 3050, "foo_ds", null, new Properties())); + } + } +} diff --git a/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaDataTest.java b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaDataTest.java new file mode 100644 index 0000000000000..16c09d44c5b57 --- /dev/null +++ b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaDataTest.java @@ -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.infra.database.firebird.metadata.database; + +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class FirebirdDatabaseMetaDataTest { + + private final DialectDatabaseMetaData dialectDatabaseMetaData = DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, TypedSPILoader.getService(DatabaseType.class, "Firebird")); + + @Test + void assertGetQuoteCharacter() { + assertThat(dialectDatabaseMetaData.getQuoteCharacter(), is(QuoteCharacter.QUOTE)); + } + + @Test + void assertGetDefaultNullsOrderType() { + assertThat(dialectDatabaseMetaData.getDefaultNullsOrderType(), is(NullsOrderType.LOW)); + } +} diff --git a/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseTypeTest.java b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseTypeTest.java new file mode 100644 index 0000000000000..89bb43eee364c --- /dev/null +++ b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseTypeTest.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.infra.database.firebird.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class FirebirdDatabaseTypeTest { + + @Test + void assertGetJdbcUrlPrefixes() { + assertThat(TypedSPILoader.getService(DatabaseType.class, "Firebird").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird"))); + } + +} diff --git a/infra/database/type/pom.xml b/infra/database/type/pom.xml index fd6bdda0cca27..ce6fbee3212e6 100644 --- a/infra/database/type/pom.xml +++ b/infra/database/type/pom.xml @@ -38,6 +38,7 @@ doris hive presto + firebird h2 sql92 p6spy diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java index b385d5d2ab927..5071dc31653d5 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java @@ -43,7 +43,10 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; import java.sql.Connection; import java.sql.ResultSet; @@ -101,6 +104,9 @@ private boolean doExecute(final ShardingSphereDatabase database, final Execution processEngine.executeSQL(executionGroupContext, executionContext.getQueryContext()); List results = jdbcExecutor.execute(executionGroupContext, new ExecuteCallbackFactory(prepareEngine.getType()).newInstance(database, executeCallback, executionContext.getSqlStatementContext().getSqlStatement())); + if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext().getSqlStatement())) { + connection.commit(); + } if (MetaDataRefreshEngine.isRefreshMetaDataRequired(executionContext.getSqlStatementContext())) { new MetaDataRefreshEngine(connection.getContextManager().getPersistServiceFacade().getMetaDataManagerPersistService(), database, metaData.getProps()) .refresh(executionContext.getQueryContext().getSqlStatementContext(), executionContext.getRouteContext().getRouteUnits()); @@ -119,6 +125,10 @@ private Collection getStatements(final ExecutionGroup> getParameterSets(final ExecutionGroup executionGroup) { Collection> result = new LinkedList<>(); for (JDBCExecutionUnit each : executionGroup.getInputs()) { diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java index c48137c834bff..e865af16713ef 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java @@ -41,6 +41,9 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; import java.sql.Connection; import java.sql.SQLException; @@ -106,6 +109,9 @@ private int doExecuteUpdate(final ShardingSphereDatabase database, final Executi .newInstance(database, executionContext.getQueryContext().getSqlStatementContext().getSqlStatement(), updateCallback); List updateCounts = jdbcExecutor.execute(executionGroupContext, callback); if (MetaDataRefreshEngine.isRefreshMetaDataRequired(executionContext.getQueryContext().getSqlStatementContext())) { + if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext().getSqlStatement())) { + connection.commit(); + } new MetaDataRefreshEngine(connection.getContextManager().getPersistServiceFacade().getMetaDataManagerPersistService(), database, props) .refresh(executionContext.getQueryContext().getSqlStatementContext(), executionContext.getRouteContext().getRouteUnits()); } @@ -123,6 +129,10 @@ private Collection getStatements(final ExecutionGroup> getParameterSets(final ExecutionGroup executionGroup) { Collection> result = new LinkedList<>(); for (JDBCExecutionUnit each : executionGroup.getInputs()) { diff --git a/parser/sql/dialect/firebird/pom.xml b/parser/sql/dialect/firebird/pom.xml new file mode 100644 index 0000000000000..e8e2f14da4fe9 --- /dev/null +++ b/parser/sql/dialect/firebird/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-parser-sql-dialect + 5.5.2-SNAPSHOT + + shardingsphere-parser-sql-firebird + ${project.artifactId} + + + firebird + + + + + org.apache.shardingsphere + shardingsphere-infra-database-firebird + ${project.version} + + + diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Alphabet.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Alphabet.g4 new file mode 100644 index 0000000000000..07f17373fab8d --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Alphabet.g4 @@ -0,0 +1,49 @@ +/* + * 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. + */ + +lexer grammar Alphabet; + +FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR'; + +fragment A: [Aa]; +fragment B: [Bb]; +fragment C: [Cc]; +fragment D: [Dd]; +fragment E: [Ee]; +fragment F: [Ff]; +fragment G: [Gg]; +fragment H: [Hh]; +fragment I: [Ii]; +fragment J: [Jj]; +fragment K: [Kk]; +fragment L: [Ll]; +fragment M: [Mm]; +fragment N: [Nn]; +fragment O: [Oo]; +fragment P: [Pp]; +fragment Q: [Qq]; +fragment R: [Rr]; +fragment S: [Ss]; +fragment T: [Tt]; +fragment U: [Uu]; +fragment V: [Vv]; +fragment W: [Ww]; +fragment X: [Xx]; +fragment Y: [Yy]; +fragment Z: [Zz]; +fragment UL_: '_'; +fragment HYPHEN: '-'; \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/BaseRule.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/BaseRule.g4 new file mode 100644 index 0000000000000..979c4a1105142 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/BaseRule.g4 @@ -0,0 +1,566 @@ +/* + * 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. + */ + +grammar BaseRule; + +import Symbol, Keyword, FirebirdKeyword, Literals; + +parameterMarker + : QUESTION_ + ; + +literals + : stringLiterals + | numberLiterals + | dateTimeLiterals + | hexadecimalLiterals + | bitValueLiterals + | booleanLiterals + | nullValueLiterals + ; + +stringLiterals + : characterSetName? STRING_ collateClause? + ; + +numberLiterals + : (PLUS_ | MINUS_)? NUMBER_ + ; + +dateTimeLiterals + : (DATE | TIME | TIMESTAMP) STRING_ + | LBE_ identifier STRING_ RBE_ + ; + +hexadecimalLiterals + : characterSetName? HEX_DIGIT_ collateClause? + ; + +bitValueLiterals + : characterSetName? BIT_NUM_ collateClause? + ; + +booleanLiterals + : TRUE | FALSE + ; + +nullValueLiterals + : NULL + ; + +identifier + : IDENTIFIER_ | unreservedWord + ; + +unreservedWord + : ADA + | C92 | CATALOG_NAME | CHARACTER_SET_CATALOG | CHARACTER_SET_NAME | CHARACTER_SET_SCHEMA + | CLASS_ORIGIN | COBOL | COLLATION_CATALOG | COLLATION_NAME | COLLATION_SCHEMA + | COLUMN_NAME | COMMAND_FUNCTION | COMMITTED | CONDITION_NUMBER | CONNECTION_NAME + | CONSTRAINT_CATALOG | CONSTRAINT_NAME | CONSTRAINT_SCHEMA | CURSOR_NAME + | DATA | DATETIME_INTERVAL_CODE | DATETIME_INTERVAL_PRECISION | DYNAMIC_FUNCTION + | FORTRAN + | LENGTH + | MESSAGE_LENGTH | MESSAGE_OCTET_LENGTH | MESSAGE_TEXT | MORE92 | MUMPS + | NAME | NULLABLE | NUMBER + | PASCAL | PLI + | REPEATABLE | RETURNED_LENGTH | RETURNED_OCTET_LENGTH | RETURNED_SQLSTATE | ROW_COUNT + | SCALE | SCHEMA_NAME | SERIALIZABLE | SERVER_NAME | SUBCLASS_ORIGIN + | TABLE_NAME | TYPE + | UNCOMMITTED | UNNAMED | VALUE | FIRSTNAME | MIDDLENAME | LASTNAME + ; + +variable + : (AT_? AT_)? (GLOBAL | LOCAL)? DOT_? identifier + ; + +schemaName + : identifier + ; + +savepointName + : identifier + ; + +variableName + : (owner DOT_)? name + ; + +domainName + : identifier + ; + +packageName + : identifier + ; + +tableName + : (owner DOT_)? name + ; + +parameterName + : identifier + ; + +collationName + : identifier + ; + +attributeName + : identifier + ; + +login + : identifier + ; + +password + : STRING_ + ; + +roleName + : identifier + ; + +columnName + : (owner DOT_)? name + ; + +viewName + : identifier + | (owner DOT_)? identifier + ; + +functionName + : identifier + ; + +triggerName + : identifier + ; + +argumentName + : identifier + ; + +owner + : identifier + ; + +engineName + : identifier + ; + +information + : identifier + ; + +localVariableDeclarationName + : identifier + ; + +baseSortName + : identifier + ; + +constraintName + : identifier + ; + +externalModuleName + : identifier + ; + +cursorName + : identifier + ; + +procedureName + : identifier + ; + +name + : identifier + ; + +columnNames + : LP_? columnName (COMMA_ columnName)* RP_? + ; + +tableNames + : LP_? tableName (COMMA_ tableName)* RP_? + ; + +characterSetName + : IDENTIFIER_ + ; + +expr + : expr andOperator expr + | expr orOperator expr + | notOperator expr + | LP_ expr RP_ + | booleanPrimary + ; + +andOperator + : AND | AND_ + ; + +orOperator + : OR | CONCAT_ + ; + +notOperator + : NOT | NOT_ + ; + +booleanPrimary + : booleanPrimary IS NOT? (TRUE | FALSE | UNKNOWN | NULL) + | booleanPrimary SAFE_EQ_ predicate + | booleanPrimary comparisonOperator predicate + | booleanPrimary comparisonOperator (ALL | SOME | ANY) subquery + | predicate + ; + +comparisonOperator + : EQ_ | GTE_ | GT_ | LTE_ | LT_ | NEQ_ + ; + +predicate + : + | bitExpr NOT? IN subquery + | bitExpr NOT? IN LP_ expr (COMMA_ expr)* RP_ + | bitExpr NOT? BETWEEN bitExpr AND predicate + | bitExpr NOT? LIKE simpleExpr (ESCAPE simpleExpr)? + | bitExpr NOT? STARTING WITH? bitExpr + | bitExpr IS NOT? DISTINCT FROM bitExpr + | bitExpr NOT? SIMILAR TO bitExpr (ESCAPE bitExpr)? + | bitExpr + ; + +bitExpr + : bitExpr VERTICAL_BAR_ bitExpr + | bitExpr AMPERSAND_ bitExpr + | bitExpr SIGNED_LEFT_SHIFT_ bitExpr + | bitExpr SIGNED_RIGHT_SHIFT_ bitExpr + | bitExpr PLUS_ bitExpr + | bitExpr MINUS_ bitExpr + | bitExpr ASTERISK_ bitExpr + | bitExpr SLASH_ bitExpr + | bitExpr MOD_ bitExpr + | bitExpr CARET_ bitExpr + | bitExpr PLUS_ intervalExpression + | bitExpr MINUS_ intervalExpression + | simpleExpr + ; + +simpleExpr + : functionCall + | parameterMarker + | literals + | columnName + | simpleExpr COLLATE (STRING_ | identifier) + | variable + | (PLUS_ | MINUS_ | TILDE_ | NOT_) simpleExpr + | LP_ expr (COMMA_ expr)* RP_ + | EXISTS? subquery + | LBE_ identifier expr RBE_ + | matchExpression + | caseExpression + | intervalExpression + | timeConstants + ; + +functionCall + : aggregationFunction | specialFunction | regularFunction + ; + +aggregationFunction + : aggregationFunctionName LP_ distinct? (expr (COMMA_ expr)* | ASTERISK_)? RP_ overClause? + ; + +aggregationFunctionName + : MAX | MIN | SUM | COUNT | AVG + ; + +distinct + : DISTINCT + ; + +specialFunction + : castFunction + | convertFunction + | positionFunction + | substringFunction + | extractFunction + | trimFunction + | windowFunction + ; + +castFunction + : CAST LP_ (expr | NULL) AS dataType RP_ + ; + +convertFunction + : CONVERT LP_ expr USING identifier RP_ + ; + +positionFunction + : POSITION LP_ expr IN expr RP_ + ; + +substringFunction + : SUBSTRING LP_ expr FROM NUMBER_ (FOR NUMBER_)? RP_ + ; + +extractFunction + : EXTRACT LP_ identifier FROM expr RP_ + ; + +trimFunction + : TRIM LP_ ((LEADING | BOTH | TRAILING) expr? FROM)? expr RP_ + | TRIM LP_ (expr FROM)? expr RP_ + ; + +regularFunction + : regularFunctionName LP_ (expr (COMMA_ expr)* | ASTERISK_)? RP_ + ; + +regularFunctionName + : identifier | IF | INTERVAL + | CHAR_LENGTH | CHARACTER_LENGTH | BIT_LENGTH | OCTET_LENGTH + | UPPER | LOWER + | NULLIF + | COALESCE + ; + +timeConstants + : CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP | LOCALTIME | LOCALTIMESTAMP + ; + +matchExpression + : literals MATCH UNIQUE? (PARTIAL | FULL) subquery + ; + +caseExpression + : CASE simpleExpr? caseWhen+ caseElse? END + ; + +caseWhen + : WHEN expr THEN expr + ; + +caseElse + : ELSE expr + ; + +intervalExpression + : INTERVAL expr intervalUnit + ; + +intervalUnit + : MICROSECOND | SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER | YEAR + ; + +subquery + : 'Default does not match anything' + ; + +orderByClause + : ORDER BY orderByItem (COMMA_ orderByItem)* limitClause? + ; + +orderByItem + : (columnName | numberLiterals) (ASC | DESC)? + ; + +limitClause + : rowsClause | offsetDefinition + ; + +rowsClause + : ROWS expr (TO expr)? + ; + +offsetDefinition + : offsetClause + | fetchClause + | (offsetClause fetchClause) + ; + +offsetClause + : OFFSET limitOffset (ROW | ROWS) + ; + +fetchClause + : FETCH (FIRST | NEXT) limitRowCount (ROW | ROWS) ONLY + ; + +limitRowCount + : numberLiterals | parameterMarker | bindLiterals + ; + +limitOffset + : numberLiterals | parameterMarker | bindLiterals + ; + +dataType + : dataTypeName dataTypeLength? characterSet? collateClause? + | dataTypeName LP_ STRING_ (COMMA_ STRING_)* RP_ characterSet? collateClause? + | dataTypeName LBT_ (NUMBER_? COLON_ NUMBER | NUMBER_ (COMMA_ NUMBER_)*) RBT_ + ; + +dataTypeName + : CHARACTER | CHARACTER VARYING | CHAR VARYING | NATIONAL CHARACTER | NATIONAL CHARACTER VARYING | CHAR | VARCHAR | NCHAR + | NATIONAL CHAR | NATIONAL CHAR VARYING | BIT | BIT VARYING | NUMERIC | DECIMAL | DEC | INTEGER | SMALLINT | BOOLEAN + | FLOAT | REAL | DOUBLE PRECISION | DATE | TIME | TIMESTAMP | INTERVAL | TIME WITH TIME ZONE | TIMESTAMP WITH TIME ZONE + | identifier + ; + +dataTypeLength + : LP_ NUMBER_ (COMMA_ NUMBER_)? RP_ + ; + +characterSet + : (CHARACTER | CHAR) SET EQ_? ignoredIdentifier + ; + +collateClause + : COLLATE EQ_? (STRING_ | ignoredIdentifier) + ; + +ignoredIdentifier + : identifier (DOT_ identifier)? + ; + +dropBehaviour + : (CASCADE | RESTRICT)? + ; + +windowFunction + : funcName = (ROW_NUMBER | RANK | DENSE_RANK) LP_ (expr (COMMA_ expr)* | ASTERISK_)? RP_ overClause? + | funcName = (LEAD | LAG | FIRST_VALUE | LAST_VALUE | NTH_VALUE) LP_ (expr (COMMA_ expr)* | ASTERISK_)? RP_ overClause? + ; + +overClause + : OVER LP_ (PARTITION BY expr (COMMA_ expr)*)? orderByClause? RP_ + ; + +attributeCollation + : SQ_ attributeCollationName EQ_ (STRING_ | NUMBER_) SQ_ + ; + +attributeCollationName + : DISABLE_COMPRESSIONS + | DISABLE_EXPANSIONS + | ICU_VERSION + | LOCALE + | MULTI_LEVEL + | NUMERIC_SORT + | SPECIALS_FIRST + ; + +defaultValue + : (literals | NULL | contextVariables) + ; + +contextVariables + : CURRENT_CONNECTION | CURRENT_DATE | CURRENT_ROLE + | CURRENT_TIME | CURRENT_TIMESTAMP + | CURRENT_TRANSACTION | CURRENT_USER + | INSERTING | UPDATING | DELETING + | NEW | NOW | OLD | ROW_COUNT + | SQLCODE | GDSCODE | SQLSTATE + | TODAY | TOMORROW | USER | YESTERDAY + ; + +announcementArgument + : argumentName typeDescriptionArgument (NOT NULL)? collateClause? + ; + +announcementArgumentClause + : announcementArgument (COMMA_ announcementArgument)* + ; + +typeDescriptionArgument + : dataType + | (TYPE OF)? domainName + | TYPE OF COLUMN (tableName | viewName) DOT_ columnName + ; + + +externalModule + : EQ_ externalModuleName NOT_ functionName (NOT_ information)? EQ_ + ; + +sortOrder + : DOS850 | DB_DEU850 | DB_ESP850 | DB_FRA850 | DB_FRC850 | DB_ITA850 | DB_NLD850 | DB_PTB850 | DB_SVE850 | DB_UK850 | DB_US850 + | DOS852 | DB_CSY | DB_PLK | DB_SLO | PDOX_CSY | PDOX_HUN | PDOX_PLK | PDOX_SLO + | DOS857 | DB_TRK + | DOS858 + | DOS860 | DB_PTG860 + | DOS861 | PDOX_IS + | DOS862 + | DOS863 | DB_FRC863 + | DOS864 + | DOS865 | DB_DAN865 | DB_NOR865 | PDOX_NORDAN4 + | DOS866 + | DOS869 + | EUCJ_0208 + | GB_2312 + | ISO8859_1 | DA_DA | DE_DE | DU_NL | EN_UK | EN_US | ES_ES | ES_ES_CI_AI | FI_FI | FR_CA | FR_FR | IS_IS | IT_IT | NO_NO | PT_PT | PT_BR | SV_SV + | ISO8859_2 | CS_CZ | ISO_HUN | ISO_PLK + | ISO8859_3 + | ISO8859_4 + | ISO8859_5 + | ISO8859_6 + | ISO8859_7 + | ISO8859_8 + | ISO8859_9 + | ISO8859_13 | LT_LT + | KOI8R | KOI8R_RU + | KOI8U | KOI8R_UA + | KSC_5601 | KSC_DIC_TIONAR + | NEXT | NXT_DEU | NXT_ESP | NXT_FRA | NXT_ITA | NXT_US + | NONE + | OCTETS + | SJIS_0208 + | UNICODE_FSS + | UTF8 | USC_BASIC | UNICODE + | WIN1250 | BS_BA | PXW_CSY | PXW_HUN | PXW_HUNDC | PXW_PLK | PXW_SLOV | WIN_CZ | WIN_CZ_CI_AI + | WIN1251 | WIN1251_UA | PXW_CYRL + | WIN1252 | PXW_INTL | PXW_INTL850 | PXW_NORDAN4 | PXW_SPAN | PXW_SWEDFIN | WIN_PTBR + | WIN1253 | PXW_GREEK + | WIN1254 | PXW_TURK + | WIN1255 + | WIN1256 + | WIN1257 | WIN1257_EE | WIN1257_LT | WIN1257_LV + | WIN1258 + ; + +attribute + : attributeName EQ_ STRING_ + ; + +attributeClause + : attribute (COMMA_ attribute)* + ; + +bindLiterals + : COLON_ identifier + ; \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Comments.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Comments.g4 new file mode 100644 index 0000000000000..0eeaf0cd26757 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Comments.g4 @@ -0,0 +1,23 @@ +/* + * 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. + */ + +lexer grammar Comments; + +import Symbol; + +BLOCK_COMMENT: '/*' (BLOCK_COMMENT|.)*? '*/' -> channel(HIDDEN); +INLINE_COMMENT: '--' ~[\r\n]* ('\r'? '\n' | EOF) -> channel(HIDDEN); \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DCLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DCLStatement.g4 new file mode 100644 index 0000000000000..3bb7600f706f2 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DCLStatement.g4 @@ -0,0 +1,151 @@ +/* + * 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. + */ + +grammar DCLStatement; + +import BaseRule; + +grant + : GRANT privilegeClause TO grantee (COMMA_ grantee)* (WITH GRANT OPTION)? + ; + +revoke + : REVOKE (GRANT OPTION FOR)? privilegeClause FROM grantee (COMMA_ grantee)* dropBehaviour + ; + +privilegeClause + : privileges ON onObjectClause + ; + +privileges + : privilegeType (COMMA_ privilegeType)* + ; + +privilegeType + : ALL PRIVILEGES + | SELECT + | DELETE + | INSERT + | UPDATE + | REFERENCES + | USAGE + ; + +grantee + : objectRecepient | userRecepient + ; + +onObjectClause + : objectType? privilegeLevel + ; + +objectType + : TABLE + | VIEW + | PROCEDURE + | FUNCTION + | PACKAGE + | GENERATOR + | SEQUENCE + | DOMAIN + | EXCEPTION + | ROLE + | CHARACTER SET + | COLLATION + | FILTER + ; + +objectRecepient + : PROCEDURE procedureName + | FUNCTION functionName + | PACKAGE packageName + | TRIGGER triggerName + | VIEW viewName + ; + +userRecepient + : USER? identifier + | ROLE? roleName + | GROUP identifier + ; + +privilegeLevel + : tableName + ; + +createRole + : CREATE ROLE roleName + ; + +createUser + : CREATE USER login PASSWORD password + firstNameClause? middleNameClause? lastNameClause? + activeClause? usingPluginClause? + tagsAttributeClause? grantAdminRoleClause? + ; + +firstNameClause + : FIRSTNAME STRING_ + ; + +middleNameClause + : MIDDLENAME STRING_ + ; + +lastNameClause + : LASTNAME STRING_ + ; + +activeClause + : ACTIVE | INACTIVE + ; + +usingPluginClause + : USING PLUGIN STRING_ + ; + +tagsAttributeClause + : TAGS LP_ attributeClause RP_ + ; + +grantAdminRoleClause + : GRANT ADMIN ROLE + ; + +//createUser +// : CREATE USER identifier password (userOptions)? +// ; +// +//alterUser +// : ALTER USER identifier (password)? (userOptions)? +// ; +// +//dropUser +// : DROP username +// ; +// +//username +// : USER identifier +// ; +// +//password +// : PASSWORD STRING_ +// ; +// +//userOptions +// : (FIRSTNAME STRING_)? (MIDDLENAME STRING_)? (LASTNAME STRING_)? ((GRANT | REVOKE) ADMIN ROLE)? +// ; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DDLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DDLStatement.g4 new file mode 100644 index 0000000000000..573760eeca160 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DDLStatement.g4 @@ -0,0 +1,572 @@ +/* + * 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. + */ + +grammar DDLStatement; + +import DMLStatement; + +createTable + : CREATE createTemporaryTable? TABLE tableName createDefinitionClause sqlSecurity? + ; + +createCollation + : CREATE COLLATION collationName FOR characterSetName fromCollationClause? paddingClause? caseSensitivityClause? accentSensitivityClause? attributeClause? + ; + +fromCollationClause + : FROM baseSortName | FROM EXTERNAL LP_ STRING_ RP_ + ; + +paddingClause + : NO PAD | PAD SPACE + ; + +caseSensitivityClause + : CASE SENSITIVE | CASE INSENSITIVE + ; + +accentSensitivityClause + : ACCENT SENSITIVE | ACCENT INSENSITIVE + ; + +attributeClause + : attributeCollation (SEMI_ attributeCollation)* + ; + +createDomain + : CREATE DOMAIN domainName AS? dataType defaultClause? notNullClause? checkClause? characterSetClause? collateClause? + ; + +defaultClause + : DEFAULT defaultValue? + ; + +notNullClause + : NOT NULL + ; + +checkClause + : CHECK LP_ expr RP_ + ; + +characterSetClause + : CHARACTER SET characterSetName collateClause? + ; + +alterTable + : ALTER TABLE tableName alterDefinitionClause + ; + +alterSequence + : ALTER SEQUENCE tableName sequenceRestartClause? sequenceIncrementClause? + ; + +createSequence + : CREATE (GENERATOR | SEQUENCE) tableName sequenceRestartClause? sequenceIncrementClause? + ; + +alterDomain + : ALTER DOMAIN domainName toTableClause? defaultAlterDomainClause? notNullAlterDomainClause? constraintClause? typeClause? + ; + +toTableClause + : TO tableName + ; + +defaultAlterDomainClause + : (SET DEFAULT defaultValue | DROP DEFAULT) + ; + +notNullAlterDomainClause + : (SET | DROP) NOT NULL + ; + +constraintClause + : (ADD CONSTRAINT? CHECK LP_ expr RP_ | DROP CONSTRAINT) + ; + +typeClause + : TYPE dataType (CHARACTER SET literals (COLLATE sortOrder)?)? + ; + +dropTable + : DROP TABLE tableNames dropBehaviour + ; + +createFunction + : CREATE FUNCTION functionName + inputArgumentClause? + RETURNS typeDescriptionArgument + collateClause? + DETERMINISTIC? + ( + EXTERNAL NAME externalModuleName ENGINE engineName + | + (SQL SECURITY (DEFINER | INVOKER))? + AS + announcementClause? + BEGIN + statementBlock + END + ) + ; + +statementBlock + : (statement SEMI_?)* + ; + +statement + : select + | insert + | update + | delete + | returnStatement + | cursorOpenStatement + | cursorCloseStatement + | assignmentStatement + | transferStatement + | fetchStatement + | whileStatement + | ifStatement + | executeStmt + ; + +cursorOpenStatement + : OPEN cursorName + ; + +cursorCloseStatement + : CLOSE cursorName + ; + +announcementClause + : announcement (COMMA_ announcement)* + ; + +announcement + : localVariableOrCursorAnnouncement + | procedureAnnouncement + | functioneAnnouncement + ; + +localVariableOrCursorAnnouncement + : DECLARE VARIABLE? ( + localVariableDeclarationName typeDescriptionArgument + (NOT NULL)? + collateClause? + ((EQ_ | DEFAULT) defaultValue)? + | cursorName + CURSOR FOR (SCROLL | NO SCROLL)? LP_ select RP_ SEMI_? ) + ; + +procedureAnnouncement + : PROCEDURE procedureName inputArgumentClause? (RETURNS inputArgumentClause)? + ; + +functioneAnnouncement + : FUNCTION functionName inputArgumentClause? RETURNS typeDescriptionArgument collateClause? DETERMINISTIC? + ; + +inputArgument + : announcementArgument ((EQ_ | DEFAULT) defaultValue)? + ; + +inputArgumentClause + : LP_ (inputArgument (COMMA_ inputArgument)*)? RP_ + ; + +createDatabase + : CREATE SCHEMA schemaName createDatabaseSpecification_* + ; + +dropDatabase + : DROP SCHEMA schemaName dropBehaviour + ; + +createView + : (CREATE (OR ALTER)? VIEW) + viewName viewAliasClause? + AS select + (WITH (CASCADED | LOCAL)? CHECK OPTION)? + ; + +viewAliasClause + : LP_ viewAlias (COMMA_ viewAlias)* RP_ + ; + +viewAlias + : columnName (AS alias)? + ; + +dropView + : DROP VIEW viewName dropBehaviour + ; + +createTemporaryTable + : GLOBAL TEMPORARY + ; + +sqlSecurity + : SQL SECURITY (DEFINER | INVOKER) + ; + +createDefinitionClause + : LP_ createDefinition (COMMA_ createDefinition)* RP_ + ; + +sequenceRestartClause + : RESTART (WITH bitExpr)? + ; + +sequenceIncrementClause + : INCREMENT BY? NUMBER_ + ; + +createDatabaseSpecification_ + : DEFAULT CHARACTER SET EQ_? characterSetName + ; + +createDefinition + : columnDefinition | constraintDefinition | checkConstraintDefinition + ; + +columnDefinition + : columnName dataType? (GENERATED BY DEFAULT AS IDENTITY ( LP_ START WITH NUMBER_ RP_)?)? dataTypeOption* + ; + + +dataTypeOption + : primaryKey usingDefinition? + | UNIQUE usingDefinition? + | NOT? NULL + | collateClause + | checkConstraintDefinition + | referenceDefinition + | DEFAULT (literals | expr) + | STRING_ + | (COMPUTED BY? | GENERATED ALWAYS AS) LP_ expr RP_ + ; + +checkConstraintDefinition + : (CONSTRAINT ignoredIdentifier?)? checkClause + ; + +referenceDefinition + : REFERENCES tableName columnNames? usingDefinition? (ON (UPDATE | DELETE) referenceOption)* + ; + +referenceOption + : CASCADE | SET NULL | NO ACTION | SET DEFAULT + ; + +usingDefinition + : USING (ASC(ENDING)? | DESC(ENDING)?)? INDEX identifier + ; + +constraintDefinition + : (CONSTRAINT constraintName?)? (primaryKeyOption | uniqueOption | foreignKeyOption)? + ; + +primaryKeyOption + : primaryKey columnNames usingDefinition? + ; + +primaryKey + : PRIMARY KEY + ; + +uniqueOption + : UNIQUE columnNames usingDefinition? + ; + +foreignKeyOption + : FOREIGN KEY columnNames referenceDefinition + ; + +createLikeClause + : LP_? LIKE tableName RP_? + ; + + +alterDefinitionClause + : addColumnSpecification + | modifyColumnSpecification + | dropColumnSpecification + | addConstraintSpecification + | dropConstraintSpecification + ; + +addColumnSpecification + : ADD COLUMN? columnDefinition + ; + +modifyColumnSpecification + : modifyColumn (TO tableName + | POSITION expr + | TYPE (dataType | domainName) + | SET DEFAULT defaultValue + | DROP DEFAULT + | SET NOT NULL + | DROP NOT NULL + | (TYPE dataType)? (GENERATED ALWAYS AS | COMPUTED BY?) LP_ expr RP_ + | RESTART (WITH NUMBER_)? + ) + ; + +modifyColumn + : ALTER COLUMN? columnName + ; + +dropColumnSpecification + : DROP COLUMN? columnName + ; + +addConstraintSpecification + : ADD constraintDefinition + ; + +dropConstraintSpecification + : DROP constraintDefinition + ; + +returnStatement + : RETURN expr + ; + +createProcedure + : (CREATE (OR ALTER)? PROCEDURE) procedureClause + ; + +alterProcedure + : ALTER PROCEDURE procedureClause + ; + +procedureClause + : procedureName (AUTHID (OWNER | CALLER))? + inputArgumentClause? + (RETURNS LP_ outputArgumentList RP_)? + ( + EXTERNAL NAME externalModuleName ENGINE engineName + | + (SQL SECURITY (DEFINER | INVOKER))? + AS + announcementClause? + BEGIN + statementBlock + END + ) + ; + +executeStmt + : executeProcedure | executeBlock + ; + +executeProcedure + : EXECUTE PROCEDURE procedureName exprClause? returningValuesClause? + ; + +exprClause + : LP_ expr (COMMA_ expr)* RP_ + ; + +returningValuesClause + : RETURNING_VALUES exprClause SEMI_ + ; + +createTrigger + : (CREATE (OR ALTER)? TRIGGER) triggerName triggerClause + ; + +alterTrigger + : ALTER TRIGGER triggerName (ACTIVE | INACTIVE)? ((BEFORE | AFTER) eventListTable)? (POSITION expr)? triggerClause + ; + +announcmentTriggerClause + : ( + announcmentTableTrigger | + announcmentTableTriggerSQL_2003Standart | + announcmentDataBaseTrigger | + announcmentDDLTrigger + ) + ; + +triggerClause + : announcmentTriggerClause? + ( + EXTERNAL NAME externalModuleName ENGINE engineName + | + (SQL SECURITY (DEFINER | INVOKER) | DROP SQL SECURITY)? + AS + announcementClause? + BEGIN + statementBlock + END + ) + ; + +announcmentTableTrigger + : FOR (tableName | viewName) + (ACTIVE | INACTIVE)? + (BEFORE | AFTER) eventListTable + (POSITION expr)? + ; + +eventListTable + : dmlStatement (OR dmlStatement)* + ; + +listDDLStatement + : ANY DDL STATEMENT + | ddlStatement (OR ddlStatement)* + ; + +dmlStatement + : INSERT | UPDATE | DELETE + ; + +ddlStatement + : (CREATE | ALTER | DROP) TABLE + | (CREATE | ALTER | DROP) PROCEDURE + | (CREATE | ALTER | DROP) FUNCTION + | (CREATE | ALTER | DROP) TRIGGER + | (CREATE | ALTER | DROP) EXCEPTION + | (CREATE | ALTER | DROP) VIEW + | (CREATE | ALTER | DROP) DOMAIN + | (CREATE | ALTER | DROP) ROLE + | (CREATE | ALTER | DROP) SEQUENCE + | (CREATE | ALTER | DROP) USER + | (CREATE|ALTER|DROP) INDEX + | (CREATE | DROP) COLLATION + | ALTER CHARACTER SET + | (CREATE | ALTER | DROP) PACKAGE + | (CREATE | DROP) PACKAGE BODY + | (CREATE | ALTER | DROP) MAPPING + ; + +announcmentTableTriggerSQL_2003Standart + : (ACTIVE | INACTIVE)? + (BEFORE | AFTER) eventListTable + (POSITION expr)? + ON (tableName | viewName) + ; + +announcmentDataBaseTrigger + : (ACTIVE | INACTIVE)? + ON eventConnectOrTransaction + (POSITION expr)? + ; + +eventConnectOrTransaction + : CONNECT + | DISCONNECT + | TRANSACTION START + | TRANSACTION COMMIT + | TRANSACTION ROLLBACK + ; + +announcmentDDLTrigger + : (ACTIVE | INACTIVE)? + (BEFORE | AFTER) listDDLStatement + (POSITION expr)? + ; + +executeBlock + : EXECUTE BLOCK + inputArgumentList? + (RETURNS LP_ outputArgumentList RP_)? + AS + announcementClause? + BEGIN + statementBlock + END SEMI_ + ; + +inputArgumentList + : LP_ announcementArgument EQ_ QUESTION_ (COMMA_ (announcementArgument EQ_ QUESTION_))* RP_ + ; + +outputArgumentList + : announcementArgumentClause + ; + +assignmentStatement + : variableName EQ_ expr + ; + +transferStatement + : SUSPEND SEMI_ + ; + +whileStatement + : WHILE LP_ expr RP_ DO compoundStatement + ; + +fetchStatement + : FETCH cursorName + (INTO COLON_ variable (COMMA_ (COLON_ variable))* SEMI_)? + | FETCH (NEXT + | PRIOR + | FIRST + | LAST + | ABSOLUTE NUMBER_ + | RELATIVE NUMBER_ ) FROM cursorName (INTO LBT_ COLON_ RBT_ variable (COMMA_ (LBT_ COLON_ RBT_ variable))* SEMI_)? + ; + +ifStatement + : IF LP_ expr RP_ + THEN compoundStatement+ + (ELSE compoundStatement+)? + ; + +compoundStatement + : (createTable | alterTable | dropTable | dropDatabase | insert | update | delete | select | createView | beginStatement | ifStatement | fetchStatement | leaveStatement | transferStatement | cursorCloseStatement | assignmentStatement) SEMI_? + ; + +beginStatement + : BEGIN compoundStatement* END SEMI_? + ; + +leaveStatement + : LEAVE expr? SEMI_ + ; + +comment + : COMMENT ON ( + DATABASE + | baseTypeComment tableName + | COLUMN tableName.columnName + | (PROCEDURE | FUNCTION) PARAMETER (packageName DOT_)? procedureName DOT_ parameterName + | (PROCEDURE | EXTERNAL? FUNCTION) (packageName DOT_)? procedureName + ) IS (STRING_ | NULL) + ; + +baseTypeComment + : CHARACTER SET + | COLLATION + | DOMAIN + | EXCEPTION + | FILTER + | GENERATOR + | INDEX + | PACKAGE + | USER + | ROLE + | SEQUENCE + | TABLE + | TRIGGER + | VIEW + ; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 new file mode 100644 index 0000000000000..3d8067b57ae2e --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 @@ -0,0 +1,202 @@ +/* + * 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. + */ + +grammar DMLStatement; + +import BaseRule; + +insert + : INSERT INTO? tableName (insertValuesClause | insertSelectClause) + ; + +insertValuesClause + : columnNames? (VALUES | VALUE) assignmentValues (COMMA_ assignmentValues)* + ; + +insertSelectClause + : columnNames? select + ; + +update + : UPDATE tableReferences setAssignmentsClause whereClause? + ; + +assignment + : columnName EQ_ VALUES? LP_? assignmentValue RP_? + ; + +setAssignmentsClause + : SET assignment (COMMA_ assignment)* + ; + +assignmentValues + : LP_ assignmentValue (COMMA_ assignmentValue)* RP_ + | LP_ RP_ + ; + +assignmentValue + : expr | DEFAULT | blobValue | bindLiterals + ; + +blobValue + : STRING_ + ; + +delete + : DELETE singleTableClause whereClause? + ; + +singleTableClause + : FROM tableName (AS? alias)? + ; + +select + : withClause? combineClause + ; + +combineClause + : selectClause (UNION (DISTINCT | ALL)? selectClause)* + ; + +selectClause + : SELECT selectSpecification* projections fromClause? whereClause? groupByClause? havingClause? orderByClause? limitClause? + ; + + +selectSpecification + : duplicateSpecification + ; + +duplicateSpecification + : ALL | DISTINCT + ; + +projections + : (unqualifiedShorthand | projection) (COMMA_ projection)* + ; + +projection + : (columnName | expr) (AS? alias)? | qualifiedShorthand + ; + +alias + : identifier | STRING_ + ; + +unqualifiedShorthand + : ASTERISK_ + ; + +qualifiedShorthand + : identifier DOT_ASTERISK_ + ; + +fromClause + : FROM tableReferences joinedTable? + ; + +tableReferences + : escapedTableReference (COMMA_ escapedTableReference)* + ; + +escapedTableReference + : tableReference | LBE_ tableReference RBE_ + ; + +tableReference + : tableFactor joinedTable* + ; + +tableFactor + : tableName (AS? alias)? | subquery (AS? alias)? columnNames? | LP_ tableReferences RP_ + ; + +joinedTable + : ((INNER | CROSS)? JOIN) tableFactor joinSpecification? + | (LEFT | RIGHT | FULL) OUTER? JOIN tableFactor joinSpecification + | NATURAL (INNER | (LEFT | RIGHT | FULL) (OUTER?))? JOIN tableFactor + ; + +joinSpecification + : ON expr | USING columnNames + ; + +whereClause + : WHERE (expr | CURRENT OF cursorName) + ; + +groupByClause + : GROUP BY orderByItem (COMMA_ orderByItem)* + ; + +havingClause + : HAVING expr + ; + +subquery + : LP_ (withClause? combineClause) RP_ + ; + +withClause + : WITH RECURSIVE? cteClause (COMMA_ cteClause)* + ; + +cteClause + : identifier (LP_ columnNames RP_)? AS subquery + ; + +merge + : MERGE intoClause usingClause + mergeWhen (mergeWhen)* + (RETURNING returnExprListClause (INTO variableListClause)?)? + ; + +intoClause + : INTO (tableName | viewName | subquery) (AS? alias)? + ; + +usingClause + : USING ((tableName | viewName) | subquery) (AS? alias)? ON expr + ; + +mergeWhen + : mergeWhenMatched | mergeWhenNotMatched + ; + +mergeWhenMatched + : WHEN MATCHED (AND expr)? THEN (UPDATE SET columnName EQ_ expr (COMMA_ (columnName EQ_ expr))* | DELETE ) + ; + +mergeWhenNotMatched + : WHEN NOT MATCHED (AND expr)? THEN INSERT columnNames? VALUES LP_ expr RP_ + ; + +returnExpr + : expr (AS? alias) + ; + +returnExprListClause + : returnExpr (COMMA_ returnExpr)* + ; + +variableList + : LBT_ COLON_ RBT_ variableName + ; + +variableListClause + : variableList (COMMA_ variableList)* + ; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/FirebirdKeyword.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/FirebirdKeyword.g4 new file mode 100644 index 0000000000000..c3181ced17353 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/FirebirdKeyword.g4 @@ -0,0 +1,980 @@ +/* + * 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. + */ + +lexer grammar FirebirdKeyword; + +import Alphabet, Keyword; + +WS + : [ \t\r\n] + ->skip + ; + +ADA + : A D A + ; + +C92 + : C + ; + +CATALOG_NAME + : C A T A L O G UL_ N A M E + ; + +CHARACTER_SET_CATALOG + : C H A R A C T E R UL_ S E T UL_ C A T A L O G + ; + +CHARACTER_SET_NAME + : C H A R A C T E R UL_ S E T UL_ N A M E + ; + +CHARACTER_SET_SCHEMA + : C H A R A C T E R UL_ S E T UL_ S C H E M A + ; + +CLASS_ORIGIN + : C L A S S UL_ O R I G I N + ; + +COBOL + : C O B O L + ; + +COLLATION_CATALOG + : C O L L A T I O N UL_ C A T A L O G + ; + +COLLATION_NAME + : C O L L A T I O N UL_ N A M E + ; + +COLLATION_SCHEMA + : C O L L A T I O N UL_ S C H E M A + ; + +COLUMN_NAME + : C O L U M N UL_ N A M E + ; + +COMMAND_FUNCTION + : C O M M A N D UL_ F U N C T I O N + ; + +COMMITTED + : C O M M I T T E D + ; + +CONDITION_NUMBER + : C O N D I T I O N UL_ N U M B E R + ; + +CONNECTION_NAME + : C O N N E C T I O N UL_ N A M E + ; + +CONSTRAINT_CATALOG + : C O N S T R A I N T UL_ C A T A L O G + ; + +CONSTRAINT_NAME + : C O N S T R A I N T UL_ N A M E + ; + +CONSTRAINT_SCHEMA + : C O N S T R A I N T UL_ S C H E M A + ; + +CURSOR_NAME + : C U R S O R UL_ N A M E + ; + +DATA + : D A T A + ; + +DATETIME_INTERVAL_CODE + : D A T E T I M E UL_ I N T E R V A L UL_ C O D E + ; + +DATETIME_INTERVAL_PRECISION + : D A T E T I M E UL_ I N T E R V A L UL_ P R E C I S I O N + ; + +DYNAMIC_FUNCTION + : D Y N A M I C UL_ F U N C T I O N + ; + +FORTRAN + : F O R T R A N + ; + +LENGTH + : L E N G T H + ; + +MESSAGE_LENGTH + : M E S S A G E UL_ L E N G T H + ; + +MESSAGE_OCTET_LENGTH + : M E S S A G E UL_ O C T E T UL_ L E N G T H + ; + +MESSAGE_TEXT + : M E S S A G E UL_ T E X T + ; + +MORE92 + : M O R E + ; + +MUMPS + : M U M P S + ; + +NULLABLE + : N U L L A B L E + ; + +NUMBER + : N U M B E R + ; + +PASCAL + : P A S C A L + ; + +PLI + : P L I + ; + +REPEATABLE + : R E P E A T A B L E + ; + +RETURNED_LENGTH + : R E T U R N E D UL_ L E N G T H + ; + +RETURNED_OCTET_LENGTH + : R E T U R N E D UL_ O C T E T UL_ L E N G T H + ; + +RETURNED_SQLSTATE + : R E T U R N E D UL_ S Q L S T A T E + ; + +ROW_COUNT + : R O W UL_ C O U N T + ; + +SCALE + : S C A L E + ; + +SCHEMA_NAME + : S C H E M A UL_ N A M E + ; + +SERIALIZABLE + : S E R I A L I Z A B L E + ; + +SERVER_NAME + : S E R V E R UL_ N A M E + ; + +SUBCLASS_ORIGIN + : S U B C L A S S UL_ O R I G I N + ; + +TABLE_NAME + : T A B L E UL_ N A M E + ; + +UNCOMMITTED + : U N C O M M I T T E D + ; + +UNNAMED + : U N N A M E D + ; + +ABSOLUTE + : A B S O L U T E + ; + +ACTION + : A C T I O N + ; + +ALLOCATE + : A L L O C A T E + ; + +ARE + : A R E + ; + +ASSERTION + : A S S E R T I O N + ; + +AT + : A T + ; + +AUTHORIZATION + : A U T H O R I Z A T I O N + ; + +BIT + : B I T + ; + +BIT_LENGTH + : B I T UL_ L E N G T H + ; + +BOTH + : B O T H + ; + +CASCADE + : C A S C A D E + ; + +CATALOG + : C A T A L O G + ; + +CHAR_LENGTH + : C H A R UL_ L E N G T H + ; + +CHARACTER_LENGTH + : C H A R A C T E R UL_ L E N G T H + ; + +CHECK + : C H E C K + ; + +COALESCE + : C O A L E S C E + ; + +COLLATE + : C O L L A T E + ; + +CONNECT + : C O N N E C T + ; + +CONNECTION + : C O N N E C T I O N + ; + +CONSTRAINTS + : C O N S T R A I N T S + ; + +CONTINUE + : C O N T I N U E + ; + +CONVERT + : C O N V E R T + ; + +CORRESPONDING + : C O R R E S P O N D I N G + ; + +CURRENT_DATE + : C U R R E N T UL_ D A T E + ; + +CURRENT_TIME + : C U R R E N T UL_ T I M E + ; + +CURRENT_TIMESTAMP + : C U R R E N T UL_ T I M E S T A M P + ; + +CURSOR + : C U R S O R + ; + +DEALLOCATE + : D E A L L O C A T E + ; + +DEC + : D E C + ; + +DECLARE + : D E C L A R E + ; + +DEFERRABLE + : D E F E R R A B L E + ; + +DEFERRED + : D E F E R R E D + ; + +DESCRIBE + : D E S C R I B E + ; + +DESCRIPTOR + : D E S C R I P T O R + ; + +DIAGNOSTICS + : D I A G N O S T I C S + ; + +DISCONNECT + : D I S C O N N E C T + ; + +DOMAIN + : D O M A I N + ; + +END + : E N D + ; + +END_EXEC + : E N D '-' E X E C + ; + +ESCAPE + : E S C A P E + ; + +EXCEPT + : E X C E P T + ; + +EXCEPTION + : E X C E P T I O N + ; + +EXEC + : E X E C + ; + +EXECUTE + : E X E C U T E + ; + +EXTERNAL + : E X T E R N A L + ; + +EXTRACT + : E X T R A C T + ; + +FETCH + : F E T C H + ; + +FIRST + : F I R S T + ; + +FOUND + : F O U N D + ; + +GET + : G E T + ; + +GLOBAL + : G L O B A L + ; + +GO + : G O + ; + +GOTO + : G O T O + ; + +IDENTITY + : I D E N T I T Y + ; + +IMMEDIATE + : I M M E D I A T E + ; + +INDICATOR + : I N D I C A T O R + ; + +INITIALLY + : I N I T I A L L Y + ; + +INPUT + : I N P U T + ; + +INSENSITIVE + : I N S E N S I T I V E + ; + +INTERSECT + : I N T E R S E C T + ; + +ISOLATION + : I S O L A T I O N + ; + +LANGUAGE + : L A N G U A G E + ; + +LAST + : L A S T + ; + +LEADING + : L E A D I N G + ; + +LEVEL + : L E V E L + ; + +LOWER + : L O W E R + ; + +MATCH + : M A T C H + ; + +MODULE + : M O D U L E + ; + +NATIONAL + : N A T I O N A L + ; + +NCHAR + : N C H A R + ; + +NO + : N O + ; + +NULLIF + : N U L L I F + ; + +NUMERIC + : N U M E R I C + ; + +OCTET_LENGTH + : O C T E T UL_ L E N G T H + ; + +OF + : O F + ; + +ONLY + : O N L Y + ; + +OPTION + : O P T I O N + ; + +OUTPUT + : O U T P U T + ; + +OVERLAPS + : O V E R L A P S + ; + +PAD + : P A D + ; + +PARTIAL + : P A R T I A L + ; + +PREPARE + : P R E P A R E + ; + +PRIOR + : P R I O R + ; + +PRIVILEGES + : P R I V I L E G E S + ; + +PUBLIC + : P U B L I C + ; + +READ + : R E A D + ; + +REFERENCES + : R E F E R E N C E S + ; + +RELATIVE + : R E L A T I V E + ; + +RESTRICT + : R E S T R I C T + ; + +ROWS + : R O W S + ; + +SCROLL + : S C R O L L + ; + +SECTION + : S E C T I O N + ; + +SESSION + : S E S S I O N + ; + +SESSION_USER + : S E S S I O N UL_ U S E R + ; + +SIZE + : S I Z E + ; + +SMALLINT + : S M A L L I N T + ; + +SOME + : S O M E + ; + +SPACE + : S P A C E + ; + +SQLCODE + : S Q L C O D E + ; + +SQLERROR + : S Q L E R R O R + ; + +SQLSTATE + : S Q L S T A T E + ; + +SYSTEM_USER + : S Y S T E M UL_ U S E R + ; + +TEMPORARY + : T E M P O R A R Y + ; + +TIMEZONE_HOUR + : T I M E Z O N E UL_ H O U R + ; + +TIMEZONE_MINUTE + : T I M E Z O N E UL_ M I N U T E + ; + +TRAILING + : T R A I L I N G + ; + +TRANSACTION + : T R A N S A C T I O N + ; + +TRANSLATE + : T R A N S L A T E + ; + +TRANSLATION + : T R A N S L A T I O N + ; + +UNKNOWN + : U N K N O W N + ; + +UPPER + : U P P E R + ; + +USAGE + : U S A G E + ; + +USER + : U S E R + ; + +VALUE + : V A L U E + ; + +VARYING + : V A R Y I N G + ; + +WHENEVER + : W H E N E V E R + ; + +WORK + : W O R K + ; + +WRITE + : W R I T E + ; + +ZONE + : Z O N E + ; + +ENDING + : E N D I N G + ; + +SECURITY + : S E C U R I T Y + ; + +INVOKER + : I N V O K E R + ; + +RECURSIVE + : R E C U R S I V E + ; + +ROW + : R O W + ; + +RETURNS + : R E T U R N S + ; + +DETERMINISTIC + : D E T E R M I N I S T I C + ; + +ENGINE + : E N G I N E + ; + +SECIRITY + : S E C I R I T Y + ; + +VARIABLE + : V A R I A B L E + ; + +RETURN + : R E T U R N + ; + +AUTHID + : A U T H I D + ; + +OWNER + : O W N E R + ; + +CALLER + : C A L L E R + ; + +ROW_NUMBER + : R O W UL_ N U M B E R + ; + +RANK + : R A N K + ; + +DENSE_RANK + : D E N S E UL_ R A N K + ; + +LEAD + : L E A D + ; + +LAG + : L A G + ; + +FIRST_VALUE + : F I R S T UL_ V A L U E + ; + +LAST_VALUE + : L A S T UL_ V A L U E + ; + +NTH_VALUE + : N T H UL_ V A L U E + ; + +PARTITION + : P A R T I T I O N + ; + +OVER + : O V E R + ; + +GENERATED + : G E N E R A T E D + ; + +ALWAYS + : A L W A Y S + ; + +COMPUTED + : C O M P U T E D + ; + +RESTART + : R E S T A R T + ; + +SEQUENCE + : S E Q U E N C E + ; + +INCREMENT + : I N C R E M E N T + ; + +SENSITIVE + : S E N S I T I V E + ; + +ACCENT + : A C C E N T + ; + +DISABLE_COMPRESSIONS + : D I S A B L E HYPHEN C O M P R E S S I O N S + ; + +DISABLE_EXPANSIONS + : D I S A B L E HYPHEN E X P A N S I O N S + ; + +ICU_VERSION + : I C U HYPHEN V E R S I O N + ; + +MULTI_LEVEL + : M U L T I HYPHEN L E V E L + ; + +NUMERIC_SORT + : N U M E R I C HYPHEN S O R T + ; + +SPECIALS_FIRST + : S P E C I A L S HYPHEN F I R S T + ; + +LOCALE + : L O C A L E + ; + +STARTING + : S T A R T I N G + ; + +MERGE + : M E R G E + ; + +RETURNING + : R E T U R N I N G + ; + +MATCHED + : M A T C H E D + ; + +PASSWORD + : P A S S W O R D + ; + +FIRSTNAME + : F I R S T N A M E + ; + +MIDDLENAME + : M I D D L E N A M E + ; + +LASTNAME + : L A S T N A M E + ; + +RETURNING_VALUES + : R E T U R N I N G UL_ V A L U E S + ; + +ACTIVE + : A C T I V E + ; + +INACTIVE + : I N A C T I V E + ; + +PLUGIN + : P L U G I N + ; + +TAGS + : T A G S + ; + +ADMIN + : A D M I N + ; + +BEFORE + : B E F O R E + ; + +AFTER + : A F T E R + ; + +BLOCK + : B L O C K + ; + +SUSPEND + : S U S P E N D + ; + +ROLE + : R O L E + ; + +START + : S T A R T + ; + +DDL + : D D L + ; + +STATEMENT + : S T A T E M E N T + ; + +PACKAGE + : P A C K A G E + ; + +BODY + : B O D Y + ; + +MAPPING + : M A P P I N G + ; + +GENERATOR + : G E N E R A T O R + ; + +WHILE + : W H I L E + ; + +LEAVE + : L E A V E + ; + +FILTER + : F I L T E R + ; + +PARAMETER + : P A R A M E T E R + ; + +DATABASE + : D A T A B A S E + ; + +COMMENT + : C O M M E N T + ; + +SIMILAR + : S I M I L A R + ; \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Keyword.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Keyword.g4 new file mode 100644 index 0000000000000..68694fc391ebd --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Keyword.g4 @@ -0,0 +1,545 @@ +/* + * 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. + */ + +lexer grammar Keyword; + +import Alphabet; + +WS + : [ \t\r\n] + ->skip + ; + +SELECT + : S E L E C T + ; + +INSERT + : I N S E R T + ; + +UPDATE + : U P D A T E + ; + +DELETE + : D E L E T E + ; + +CREATE + : C R E A T E + ; + +ALTER + : A L T E R + ; + +DROP + : D R O P + ; + +TRUNCATE + : T R U N C A T E + ; + +SCHEMA + : S C H E M A + ; + +GRANT + : G R A N T + ; + +REVOKE + : R E V O K E + ; + +ADD + : A D D + ; + +SET + : S E T + ; + +TABLE + : T A B L E + ; + +COLUMN + : C O L U M N + ; + +INDEX + : I N D E X + ; + +CONSTRAINT + : C O N S T R A I N T + ; + +PRIMARY + : P R I M A R Y + ; + +UNIQUE + : U N I Q U E + ; + +FOREIGN + : F O R E I G N + ; + +KEY + : K E Y + ; + +POSITION + : P O S I T I O N + ; + +PRECISION + : P R E C I S I O N + ; + +FUNCTION + : F U N C T I O N + ; + +TRIGGER + : T R I G G E R + ; + +PROCEDURE + : P R O C E D U R E + ; + +VIEW + : V I E W + ; + +INTO + : I N T O + ; + +VALUES + : V A L U E S + ; + +WITH + : W I T H + ; + +UNION + : U N I O N + ; + +DISTINCT + : D I S T I N C T + ; + +CASE + : C A S E + ; + +WHEN + : W H E N + ; + +CAST + : C A S T + ; + +TRIM + : T R I M + ; + +SUBSTRING + : S U B S T R I N G + ; + +FROM + : F R O M + ; + +NATURAL + : N A T U R A L + ; + +JOIN + : J O I N + ; + +FULL + : F U L L + ; + +INNER + : I N N E R + ; + +OUTER + : O U T E R + ; + +LEFT + : L E F T + ; + +RIGHT + : R I G H T + ; + +CROSS + : C R O S S + ; + +USING + : U S I N G + ; + +WHERE + : W H E R E + ; + +AS + : A S + ; + +ON + : O N + ; + +IF + : I F + ; + +ELSE + : E L S E + ; + +THEN + : T H E N + ; + +FOR + : F O R + ; + +TO + : T O + ; + +AND + : A N D + ; + +OR + : O R + ; + +IS + : I S + ; + +NOT + : N O T + ; + +NULL + : N U L L + ; + +TRUE + : T R U E + ; + +FALSE + : F A L S E + ; + +EXISTS + : E X I S T S + ; + +BETWEEN + : B E T W E E N + ; + +IN + : I N + ; + +ALL + : A L L + ; + +ANY + : A N Y + ; + +LIKE + : L I K E + ; + +ORDER + : O R D E R + ; + +GROUP + : G R O U P + ; + +BY + : B Y + ; + +ASC + : A S C + ; + +DESC + : D E S C + ; + +HAVING + : H A V I N G + ; + +LIMIT + : L I M I T + ; + +OFFSET + : O F F S E T + ; + +BEGIN + : B E G I N + ; + +COMMIT + : C O M M I T + ; + +ROLLBACK + : R O L L B A C K + ; + +SAVEPOINT + : S A V E P O I N T + ; + +BOOLEAN + : B O O L E A N + ; + +DOUBLE + : D O U B L E + ; + +CHAR + : C H A R + ; + +CHARACTER + : C H A R A C T E R + ; + +ARRAY + : A R R A Y + ; + +INTERVAL + : I N T E R V A L + ; + +DATE + : D A T E + ; + +TIME + : T I M E + ; + +TIMESTAMP + : T I M E S T A M P + ; + +LOCALTIME + : L O C A L T I M E + ; + +LOCALTIMESTAMP + : L O C A L T I M E S T A M P + ; + +YEAR + : Y E A R + ; + +QUARTER + : Q U A R T E R + ; + +MONTH + : M O N T H + ; + +WEEK + : W E E K + ; + +DAY + : D A Y + ; + +HOUR + : H O U R + ; + +MINUTE + : M I N U T E + ; + +SECOND + : S E C O N D + ; + +MICROSECOND + : M I C R O S E C O N D + ; + +MAX + : M A X + ; + +MIN + : M I N + ; + +SUM + : S U M + ; + +COUNT + : C O U N T + ; + +AVG + : A V G + ; + +DEFAULT + : D E F A U L T + ; + +CURRENT + : C U R R E N T + ; + +ENABLE + : E N A B L E + ; + +DISABLE + : D I S A B L E + ; + +CALL + : C A L L + ; + +INSTANCE + : I N S T A N C E + ; + +PRESERVE + : P R E S E R V E + ; + +DO + : D O + ; + +DEFINER + : D E F I N E R + ; + +CURRENT_USER + : C U R R E N T UL_ U S E R + ; + +SQL + : S Q L + ; + + +CASCADED + : C A S C A D E D + ; + +LOCAL + : L O C A L + ; + +CLOSE + : C L O S E + ; + +OPEN + : O P E N + ; + +NEXT + : N E X T + ; + +NAME + : N A M E + ; + +COLLATION + : C O L L A T I O N + ; + +NAMES + : N A M E S + ; + +INTEGER + : I N T E G E R + ; + +REAL + : R E A L + ; + +DECIMAL + : D E C I M A L + ; + +TYPE + : T Y P E + ; + +VARCHAR + : V A R C H A R + ; + +FLOAT + : F L O A T + ; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Literals.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Literals.g4 new file mode 100644 index 0000000000000..3e52be725dd6f --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Literals.g4 @@ -0,0 +1,49 @@ +/* + * 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. + */ + +lexer grammar Literals; + +import Alphabet, Symbol; + +IDENTIFIER_ + : [A-Za-z_$0-9\u0080-\uFFFF]*?[A-Za-z_$\u0080-\uFFFF]+?[A-Za-z_$0-9\u0080-\uFFFF]* + | DQ_ ~'"'+ DQ_ + ; + +STRING_ + : (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_) + ; + +NUMBER_ + : INT_? DOT_? INT_ (E (PLUS_ | MINUS_)? INT_)? + ; + +HEX_DIGIT_ + : '0x' HEX_+ | 'X' SQ_ HEX_+ SQ_ + ; + +BIT_NUM_ + : '0b' ('0' | '1')+ | B SQ_ ('0' | '1')+ SQ_ + ; + +fragment INT_ + : [0-9]+ + ; + +fragment HEX_ + : [0-9a-fA-F] + ; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Symbol.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Symbol.g4 new file mode 100644 index 0000000000000..cbfae02c857b6 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/Symbol.g4 @@ -0,0 +1,59 @@ +/* + * 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. + */ + +lexer grammar Symbol; + +AND_: '&&'; +CONCAT_: '||'; +NOT_: '!'; +TILDE_: '~'; +VERTICAL_BAR_: '|'; +AMPERSAND_: '&'; +SIGNED_LEFT_SHIFT_: '<<'; +SIGNED_RIGHT_SHIFT_: '>>'; +CARET_: '^'; +MOD_: '%'; +COLON_: ':'; +PLUS_: '+'; +MINUS_: '-'; +ASTERISK_: '*'; +SLASH_: '/'; +BACKSLASH_: '\\'; +DOT_: '.'; +DOT_ASTERISK_: '.*'; +SAFE_EQ_: '<=>'; +DEQ_: '=='; +EQ_: '='; +NEQ_: '<>' | '!='; +GT_: '>'; +GTE_: '>='; +LT_: '<'; +LTE_: '<='; +POUND_: '#'; +LP_: '('; +RP_: ')'; +LBE_: '{'; +RBE_: '}'; +LBT_: '['; +RBT_: ']'; +COMMA_: ','; +DQ_: '"'; +SQ_ : '\''; +QUESTION_: '?'; +AT_: '@'; +SEMI_: ';'; +COMMENT_: '--'; diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/TCLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/TCLStatement.g4 new file mode 100644 index 0000000000000..b02a512d7e585 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/TCLStatement.g4 @@ -0,0 +1,40 @@ +/* + * 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. + */ + +grammar TCLStatement; + +import BaseRule; + +setTransaction + : SET TRANSACTION ISOLATION LEVEL levelOfIsolation + ; + +commit + : COMMIT + ; + +rollback + : ROLLBACK + ; + +levelOfIsolation + : READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ| SERIALIZABLE + ; + +savepoint + : SAVEPOINT savepointName + ; \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/FirebirdStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/FirebirdStatement.g4 new file mode 100644 index 0000000000000..cee3d14084499 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/FirebirdStatement.g4 @@ -0,0 +1,55 @@ +/* + * 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. + */ + +grammar FirebirdStatement; + +import Comments, DDLStatement, TCLStatement, DCLStatement; + +execute + : (select + | insert + | update + | delete + | createDatabase + | dropDatabase + | createTable + | alterTable + | dropTable + | createView + | dropView + | setTransaction + | commit + | rollback + | grant + | revoke + | createFunction + | createProcedure + | alterSequence + | createCollation + | createDomain + | alterDomain + | createRole + | savepoint + | createTrigger + | alterTrigger + | createSequence + | merge + | createUser + | executeStmt + | comment + ) SEMI_? EOF + ; diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdLexer.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdLexer.java new file mode 100644 index 0000000000000..64119db30eebd --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdLexer.java @@ -0,0 +1,32 @@ +/* + * 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.firebird.parser; + +import org.antlr.v4.runtime.CharStream; +import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementLexer; + +/** + * SQL lexer for Firebird. + */ +public final class FirebirdLexer extends FirebirdStatementLexer implements SQLLexer { + + public FirebirdLexer(final CharStream input) { + super(input); + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParser.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParser.java new file mode 100644 index 0000000000000..71adc7aa1896e --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParser.java @@ -0,0 +1,40 @@ +/* + * 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.firebird.parser; + +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.TokenStream; +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.parser.SQLParser; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser; +import org.apache.shardingsphere.sql.parser.core.ParseASTNode; + +/** + * SQL parser for Firebird. + */ +public final class FirebirdParser extends FirebirdStatementParser implements SQLParser { + + public FirebirdParser(final TokenStream input) { + super(input); + } + + @Override + public ASTNode parse() { + return new ParseASTNode(execute(), (CommonTokenStream) getTokenStream()); + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParserFacade.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParserFacade.java new file mode 100644 index 0000000000000..c474080ae93bf --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/parser/FirebirdParserFacade.java @@ -0,0 +1,43 @@ +/* + * 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.firebird.parser; + +import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer; +import org.apache.shardingsphere.sql.parser.api.parser.SQLParser; +import org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade; + +/** + * SQL parser facade for Firebird. + */ +public final class FirebirdParserFacade implements DialectSQLParserFacade { + + @Override + public Class getLexerClass() { + return FirebirdLexer.class; + } + + @Override + public Class getParserClass() { + return FirebirdParser.class; + } + + @Override + public String getDatabaseType() { + return "Firebird"; + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitor.java new file mode 100644 index 0000000000000..f6a71dea23752 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitor.java @@ -0,0 +1,575 @@ +/* + * 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.firebird.visitor.statement; + +import lombok.AccessLevel; +import lombok.Getter; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.misc.Interval; +import org.antlr.v4.runtime.tree.TerminalNode; +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementBaseVisitor; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AggregationFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.BitExprContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.BitValueLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.BooleanLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.BooleanPrimaryContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CastFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ColumnNameContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ColumnNamesContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DataTypeContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DataTypeLengthContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DataTypeNameContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ExprContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.FunctionCallContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.HexadecimalLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.IdentifierContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.IntervalExpressionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.LiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.NullValueLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.NumberLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.OrderByClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.OrderByItemContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.OwnerContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ParameterMarkerContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.PredicateContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.RegularFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SchemaNameContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SimpleExprContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SpecialFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.StringLiteralsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableNameContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableNamesContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.UnreservedWordContext; +import org.apache.shardingsphere.sql.parser.statement.core.enums.AggregationType; +import org.apache.shardingsphere.sql.parser.statement.core.enums.OrderDirection; +import org.apache.shardingsphere.sql.parser.statement.core.enums.ParameterMarkerType; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ListExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.NotExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.complex.CommonExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubqueryExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.AggregationDistinctProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.AggregationProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.OrderBySegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.ColumnOrderByItemSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.IndexOrderByItemSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.OrderByItemSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeLengthSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.ParameterMarkerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; +import org.apache.shardingsphere.sql.parser.statement.core.util.SQLUtils; +import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.keyword.KeywordValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.BooleanLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NullLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.OtherLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.parametermarker.ParameterMarkerValue; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdSelectStatement; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Statement visitor for Firebird. + */ +@Getter(AccessLevel.PROTECTED) +public abstract class FirebirdStatementVisitor extends FirebirdStatementBaseVisitor { + + private final Collection parameterMarkerSegments = new LinkedList<>(); + + @Override + public final ASTNode visitParameterMarker(final ParameterMarkerContext ctx) { + return new ParameterMarkerValue(parameterMarkerSegments.size(), ParameterMarkerType.QUESTION); + } + + @Override + public final ASTNode visitLiterals(final LiteralsContext ctx) { + if (null != ctx.stringLiterals()) { + return visit(ctx.stringLiterals()); + } + if (null != ctx.numberLiterals()) { + return visit(ctx.numberLiterals()); + } + if (null != ctx.hexadecimalLiterals()) { + return visit(ctx.hexadecimalLiterals()); + } + if (null != ctx.bitValueLiterals()) { + return visit(ctx.bitValueLiterals()); + } + if (null != ctx.booleanLiterals()) { + return visit(ctx.booleanLiterals()); + } + if (null != ctx.nullValueLiterals()) { + return visit(ctx.nullValueLiterals()); + } + throw new IllegalStateException("Literals must have string, number, dateTime, hex, bit, boolean or null."); + } + + @Override + public final ASTNode visitStringLiterals(final StringLiteralsContext ctx) { + return new StringLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitNumberLiterals(final NumberLiteralsContext ctx) { + return new NumberLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitHexadecimalLiterals(final HexadecimalLiteralsContext ctx) { + // TODO deal with hexadecimalLiterals + return new OtherLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitBitValueLiterals(final BitValueLiteralsContext ctx) { + // TODO deal with bitValueLiterals + return new OtherLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitBooleanLiterals(final BooleanLiteralsContext ctx) { + return new BooleanLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitNullValueLiterals(final NullValueLiteralsContext ctx) { + return new NullLiteralValue(ctx.getText()); + } + + @Override + public final ASTNode visitIdentifier(final IdentifierContext ctx) { + UnreservedWordContext unreservedWord = ctx.unreservedWord(); + return null == unreservedWord ? new IdentifierValue(ctx.getText()) : visit(unreservedWord); + } + + @Override + public final ASTNode visitUnreservedWord(final UnreservedWordContext ctx) { + return new IdentifierValue(ctx.getText()); + } + + @Override + public final ASTNode visitSchemaName(final SchemaNameContext ctx) { + return visit(ctx.identifier()); + } + + @Override + public final ASTNode visitTableName(final TableNameContext ctx) { + SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name()))); + OwnerContext owner = ctx.owner(); + if (null != owner) { + result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(), owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier()))); + } + return result; + } + + @Override + public final ASTNode visitColumnName(final ColumnNameContext ctx) { + ColumnSegment result = new ColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())); + OwnerContext owner = ctx.owner(); + if (null != owner) { + result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(), owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier()))); + } + return result; + } + + @Override + public final ASTNode visitTableNames(final TableNamesContext ctx) { + CollectionValue result = new CollectionValue<>(); + for (TableNameContext each : ctx.tableName()) { + result.getValue().add((SimpleTableSegment) visit(each)); + } + return result; + } + + @Override + public final ASTNode visitColumnNames(final ColumnNamesContext ctx) { + CollectionValue result = new CollectionValue<>(); + for (ColumnNameContext each : ctx.columnName()) { + result.getValue().add((ColumnSegment) visit(each)); + } + return result; + } + + @Override + public final ASTNode visitExpr(final ExprContext ctx) { + if (null != ctx.booleanPrimary()) { + return visit(ctx.booleanPrimary()); + } + if (null != ctx.LP_()) { + return visit(ctx.expr(0)); + } + if (null != ctx.andOperator()) { + return createBinaryOperationExpression(ctx, ctx.andOperator().getText()); + } + if (null != ctx.orOperator()) { + return createBinaryOperationExpression(ctx, ctx.orOperator().getText()); + } + return new NotExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (ExpressionSegment) visit(ctx.expr(0)), false); + } + + private ASTNode createBinaryOperationExpression(final ExprContext ctx, final String operator) { + ExpressionSegment left = (ExpressionSegment) visit(ctx.expr(0)); + ExpressionSegment right = (ExpressionSegment) visit(ctx.expr(1)); + String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); + } + + @Override + public final ASTNode visitBooleanPrimary(final BooleanPrimaryContext ctx) { + if (null != ctx.IS()) { + String rightText = ""; + if (null != ctx.NOT()) { + rightText = rightText + ctx.start.getInputStream().getText(new Interval(ctx.NOT().getSymbol().getStartIndex(), ctx.NOT().getSymbol().getStopIndex())) + " "; + } + Token operatorToken = null; + if (null != ctx.NULL()) { + operatorToken = ctx.NULL().getSymbol(); + } + if (null != ctx.TRUE()) { + operatorToken = ctx.TRUE().getSymbol(); + } + if (null != ctx.FALSE()) { + operatorToken = ctx.FALSE().getSymbol(); + } + int startIndex = null == operatorToken ? ctx.IS().getSymbol().getStopIndex() + 2 : operatorToken.getStartIndex(); + rightText = rightText + ctx.start.getInputStream().getText(new Interval(startIndex, ctx.stop.getStopIndex())); + ExpressionSegment right = new LiteralExpressionSegment(ctx.IS().getSymbol().getStopIndex() + 2, ctx.stop.getStopIndex(), rightText); + String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + ExpressionSegment left = (ExpressionSegment) visit(ctx.booleanPrimary()); + String operator = "IS"; + return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); + } + if (null != ctx.comparisonOperator() || null != ctx.SAFE_EQ_()) { + return createCompareSegment(ctx); + } + return visit(ctx.predicate()); + } + + private ASTNode createCompareSegment(final BooleanPrimaryContext ctx) { + ExpressionSegment left = (ExpressionSegment) visit(ctx.booleanPrimary()); + ExpressionSegment right; + if (null != ctx.predicate()) { + right = (ExpressionSegment) visit(ctx.predicate()); + } else { + right = new SubqueryExpressionSegment( + new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (FirebirdSelectStatement) visit(ctx.subquery()), getOriginalText(ctx.subquery()))); + } + String operator = null == ctx.SAFE_EQ_() ? ctx.comparisonOperator().getText() : ctx.SAFE_EQ_().getText(); + String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); + } + + @Override + public final ASTNode visitPredicate(final PredicateContext ctx) { + if (null != ctx.IN()) { + return createInSegment(ctx); + } + if (null != ctx.BETWEEN()) { + return createBetweenSegment(ctx); + } + if (null != ctx.LIKE()) { + return createBinaryOperationExpressionFromLike(ctx); + } + return visit(ctx.bitExpr(0)); + } + + private BinaryOperationExpression createBinaryOperationExpressionFromLike(final PredicateContext ctx) { + ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0)); + ListExpression right = new ListExpression(ctx.simpleExpr(0).start.getStartIndex(), ctx.simpleExpr().get(ctx.simpleExpr().size() - 1).stop.getStopIndex()); + for (SimpleExprContext each : ctx.simpleExpr()) { + right.getItems().add((ExpressionSegment) visit(each)); + } + String operator = null == ctx.NOT() ? "LIKE" : "NOT LIKE"; + String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); + } + + private InExpression createInSegment(final PredicateContext ctx) { + ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0)); + ExpressionSegment right; + if (null != ctx.subquery()) { + right = new SubqueryExpressionSegment(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (FirebirdSelectStatement) visit(ctx.subquery()), + getOriginalText(ctx.subquery()))); + } else { + ListExpression listExpression = new ListExpression(ctx.LP_().getSymbol().getStartIndex(), ctx.RP_().getSymbol().getStopIndex()); + for (ExprContext each : ctx.expr()) { + listExpression.getItems().add((ExpressionSegment) visit(each)); + } + right = listExpression; + } + boolean not = null != ctx.NOT(); + return new InExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, not); + } + + private BetweenExpression createBetweenSegment(final PredicateContext ctx) { + ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0)); + ExpressionSegment between = (ExpressionSegment) visit(ctx.bitExpr(1)); + ExpressionSegment and = (ExpressionSegment) visit(ctx.predicate()); + boolean not = null != ctx.NOT(); + return new BetweenExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, between, and, not); + } + + @Override + public final ASTNode visitBitExpr(final BitExprContext ctx) { + if (null != ctx.simpleExpr()) { + return createExpressionSegment(visit(ctx.simpleExpr()), ctx); + } + ExpressionSegment left = (ExpressionSegment) visit(ctx.getChild(0)); + ExpressionSegment right = (ExpressionSegment) visit(ctx.getChild(2)); + String operator = ctx.getChild(1).getText(); + String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); + } + + private ASTNode createExpressionSegment(final ASTNode astNode, final ParserRuleContext context) { + if (astNode instanceof StringLiteralValue) { + return new LiteralExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((StringLiteralValue) astNode).getValue()); + } + if (astNode instanceof NumberLiteralValue) { + return new LiteralExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((NumberLiteralValue) astNode).getValue()); + } + if (astNode instanceof BooleanLiteralValue) { + return new LiteralExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((BooleanLiteralValue) astNode).getValue()); + } + if (astNode instanceof ParameterMarkerValue) { + ParameterMarkerValue parameterMarker = (ParameterMarkerValue) astNode; + ParameterMarkerExpressionSegment segment = new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), + parameterMarker.getValue(), parameterMarker.getType()); + parameterMarkerSegments.add(segment); + return segment; + } + if (astNode instanceof SubquerySegment) { + return new SubqueryExpressionSegment((SubquerySegment) astNode); + } + if (astNode instanceof OtherLiteralValue) { + return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), ((OtherLiteralValue) astNode).getValue()); + } + return astNode; + } + + @Override + public final ASTNode visitSimpleExpr(final SimpleExprContext ctx) { + int startIndex = ctx.getStart().getStartIndex(); + int stopIndex = ctx.getStop().getStopIndex(); + if (null != ctx.subquery()) { + return new SubquerySegment(startIndex, stopIndex, (FirebirdSelectStatement) visit(ctx.subquery()), getOriginalText(ctx.subquery())); + } + if (null != ctx.parameterMarker()) { + ParameterMarkerValue parameterMarker = (ParameterMarkerValue) visit(ctx.parameterMarker()); + ParameterMarkerExpressionSegment segment = new ParameterMarkerExpressionSegment(startIndex, stopIndex, parameterMarker.getValue(), parameterMarker.getType()); + parameterMarkerSegments.add(segment); + return segment; + } + if (null != ctx.literals()) { + return SQLUtils.createLiteralExpression(visit(ctx.literals()), startIndex, stopIndex, ctx.literals().start.getInputStream().getText(new Interval(startIndex, stopIndex))); + } + if (null != ctx.functionCall()) { + return visit(ctx.functionCall()); + } + if (null != ctx.columnName()) { + return visit(ctx.columnName()); + } + return new CommonExpressionSegment(startIndex, stopIndex, ctx.getText()); + } + + @Override + public final ASTNode visitIntervalExpression(final IntervalExpressionContext ctx) { + calculateParameterCount(Collections.singleton(ctx.expr())); + return new ExpressionProjectionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), getOriginalText(ctx)); + } + + @Override + public final ASTNode visitFunctionCall(final FunctionCallContext ctx) { + if (null != ctx.aggregationFunction()) { + return visit(ctx.aggregationFunction()); + } + if (null != ctx.specialFunction()) { + return visit(ctx.specialFunction()); + } + if (null != ctx.regularFunction()) { + return visit(ctx.regularFunction()); + } + throw new IllegalStateException("FunctionCallContext must have aggregationFunction, regularFunction or specialFunction."); + } + + @Override + public final ASTNode visitAggregationFunction(final AggregationFunctionContext ctx) { + String aggregationType = ctx.aggregationFunctionName().getText(); + return AggregationType.isAggregationType(aggregationType) + ? createAggregationSegment(ctx, aggregationType) + : new ExpressionProjectionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), getOriginalText(ctx)); + } + + private ASTNode createAggregationSegment(final AggregationFunctionContext ctx, final String aggregationType) { + AggregationType type = AggregationType.valueOf(aggregationType.toUpperCase()); + if (null != ctx.distinct()) { + AggregationDistinctProjectionSegment result = + new AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), type, getOriginalText(ctx), getDistinctExpression(ctx)); + result.getParameters().addAll(getExpressions(ctx)); + return result; + } + AggregationProjectionSegment result = new AggregationProjectionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), type, getOriginalText(ctx)); + result.getParameters().addAll(getExpressions(ctx)); + return result; + } + + private Collection getExpressions(final AggregationFunctionContext ctx) { + if (null == ctx.expr()) { + return Collections.emptyList(); + } + Collection result = new LinkedList<>(); + for (ExprContext each : ctx.expr()) { + result.add((ExpressionSegment) visit(each)); + } + return result; + } + + private String getDistinctExpression(final AggregationFunctionContext ctx) { + StringBuilder result = new StringBuilder(); + for (int i = 3; i < ctx.getChildCount() - 1; i++) { + result.append(ctx.getChild(i).getText()); + } + return result.toString(); + } + + @Override + public final ASTNode visitSpecialFunction(final SpecialFunctionContext ctx) { + if (null != ctx.castFunction()) { + return visit(ctx.castFunction()); + } + return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getChild(0).getChild(0).getText(), getOriginalText(ctx)); + } + + @Override + public final ASTNode visitCastFunction(final CastFunctionContext ctx) { + calculateParameterCount(Collections.singleton(ctx.expr())); + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx)); + ASTNode exprSegment = visit(ctx.expr()); + if (exprSegment instanceof ColumnSegment) { + result.getParameters().add((ColumnSegment) exprSegment); + } else if (exprSegment instanceof LiteralExpressionSegment) { + result.getParameters().add((LiteralExpressionSegment) exprSegment); + } + result.getParameters().add((DataTypeSegment) visit(ctx.dataType())); + return result; + } + + @Override + public final ASTNode visitRegularFunction(final RegularFunctionContext ctx) { + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.regularFunctionName().getText(), getOriginalText(ctx)); + Collection expressionSegments = ctx.expr().stream().map(each -> (ExpressionSegment) visit(each)).collect(Collectors.toList()); + result.getParameters().addAll(expressionSegments); + return result; + } + + @Override + public final ASTNode visitDataTypeName(final DataTypeNameContext ctx) { + Collection dataTypeNames = new LinkedList<>(); + for (int i = 0; i < ctx.getChildCount(); i++) { + dataTypeNames.add(ctx.getChild(i).getText()); + } + return new KeywordValue(String.join(" ", dataTypeNames)); + } + + // TODO :FIXME, sql case id: insert_with_str_to_date + private void calculateParameterCount(final Collection exprContexts) { + for (ExprContext each : exprContexts) { + visit(each); + } + } + + @Override + public final ASTNode visitOrderByClause(final OrderByClauseContext ctx) { + Collection items = new LinkedList<>(); + for (OrderByItemContext each : ctx.orderByItem()) { + items.add((OrderByItemSegment) visit(each)); + } + return new OrderBySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), items); + } + + @Override + public final ASTNode visitOrderByItem(final OrderByItemContext ctx) { + OrderDirection orderDirection = null == ctx.DESC() ? OrderDirection.ASC : OrderDirection.DESC; + if (null != ctx.columnName()) { + ColumnSegment column = (ColumnSegment) visit(ctx.columnName()); + return new ColumnOrderByItemSegment(column, orderDirection, null); + } + return new IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(), ctx.numberLiterals().getStop().getStopIndex(), + SQLUtils.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection, null); + } + + @Override + public final ASTNode visitDataType(final DataTypeContext ctx) { + DataTypeSegment result = new DataTypeSegment(); + result.setDataTypeName(((KeywordValue) visit(ctx.dataTypeName())).getValue()); + result.setStartIndex(ctx.start.getStartIndex()); + result.setStopIndex(ctx.stop.getStopIndex()); + if (null != ctx.dataTypeLength()) { + DataTypeLengthSegment dataTypeLengthSegment = (DataTypeLengthSegment) visit(ctx.dataTypeLength()); + result.setDataLength(dataTypeLengthSegment); + } + return result; + } + + @Override + public final ASTNode visitDataTypeLength(final DataTypeLengthContext ctx) { + DataTypeLengthSegment result = new DataTypeLengthSegment(); + result.setStartIndex(ctx.start.getStartIndex()); + result.setStopIndex(ctx.stop.getStartIndex()); + List numbers = ctx.NUMBER_(); + if (numbers.size() == 1) { + result.setPrecision(Integer.parseInt(numbers.get(0).getText())); + } + if (numbers.size() == 2) { + result.setPrecision(Integer.parseInt(numbers.get(0).getText())); + result.setScale(Integer.parseInt(numbers.get(1).getText())); + } + return result; + } + + /** + * Get original text. + * + * @param ctx context + * @return original text + */ + protected String getOriginalText(final ParserRuleContext ctx) { + return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitorFacade.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitorFacade.java new file mode 100644 index 0000000000000..48b19f5043d02 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/FirebirdStatementVisitorFacade.java @@ -0,0 +1,72 @@ +/* + * 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.firebird.visitor.statement; + +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.RLStatementVisitor; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDALStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDDLStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDMLStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdTCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade; + +/** + * Statement visitor facade for Firebird. + */ +public final class FirebirdStatementVisitorFacade implements SQLStatementVisitorFacade { + + @Override + public Class getDMLVisitorClass() { + return FirebirdDMLStatementVisitor.class; + } + + @Override + public Class getDDLVisitorClass() { + return FirebirdDDLStatementVisitor.class; + } + + @Override + public Class getTCLVisitorClass() { + return FirebirdTCLStatementVisitor.class; + } + + @Override + public Class getDCLVisitorClass() { + return FirebirdDCLStatementVisitor.class; + } + + @Override + public Class getDALVisitorClass() { + return FirebirdDALStatementVisitor.class; + } + + @Override + public Class getRLVisitorClass() { + return null; + } + + @Override + public String getDatabaseType() { + return "Firebird"; + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDALStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDALStatementVisitor.java new file mode 100644 index 0000000000000..3dc7d7a55da6b --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDALStatementVisitor.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.firebird.visitor.statement.type; + +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; + +/** + * DAL statement visitor for Firebird. + */ +public final class FirebirdDALStatementVisitor extends FirebirdStatementVisitor implements DALStatementVisitor { +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDCLStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDCLStatementVisitor.java new file mode 100644 index 0000000000000..72997bdc7c90f --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDCLStatementVisitor.java @@ -0,0 +1,65 @@ +/* + * 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.firebird.visitor.statement.type; + +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateRoleContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateUserContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.GrantContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.RevokeContext; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.firebird.dcl.FirebirdCreateRoleStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dcl.FirebirdCreateUserStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dcl.FirebirdGrantStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dcl.FirebirdRevokeStatement; + +/** + * DCL statement visitor for Firebird. + */ +public final class FirebirdDCLStatementVisitor extends FirebirdStatementVisitor implements DCLStatementVisitor { + + @Override + public ASTNode visitGrant(final GrantContext ctx) { + FirebirdGrantStatement result = new FirebirdGrantStatement(); + if (null != ctx.privilegeClause()) { + result.getTables().add((SimpleTableSegment) visit(ctx.privilegeClause().onObjectClause().privilegeLevel().tableName())); + } + return result; + } + + @Override + public ASTNode visitRevoke(final RevokeContext ctx) { + FirebirdRevokeStatement result = new FirebirdRevokeStatement(); + if (null != ctx.privilegeClause()) { + result.getTables().add((SimpleTableSegment) visit(ctx.privilegeClause().onObjectClause().privilegeLevel().tableName())); + } + return result; + } + + @Override + public ASTNode visitCreateRole(final CreateRoleContext ctx) { + return new FirebirdCreateRoleStatement(); + } + + @Override + public ASTNode visitCreateUser(final CreateUserContext ctx) { + return new FirebirdCreateUserStatement(); + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDDLStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDDLStatementVisitor.java new file mode 100644 index 0000000000000..6a493ddfe01fd --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDDLStatementVisitor.java @@ -0,0 +1,321 @@ +/* + * 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.firebird.visitor.statement.type; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AddColumnSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AddConstraintSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterDefinitionClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterDomainContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterProcedureContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterSequenceContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterTableContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AlterTriggerContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CheckConstraintDefinitionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ColumnDefinitionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CommentContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ConstraintDefinitionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ConstraintNameContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateCollationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateDefinitionClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateDefinitionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateDomainContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateProcedureContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateSequenceContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateTableContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CreateTriggerContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DataTypeOptionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DropColumnSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DropConstraintSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DropTableContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ExecuteStmtContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ModifyColumnSpecificationContext; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.AlterDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.CreateDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.DropColumnDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.AddConstraintDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.DropConstraintDefinitionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdAlterDomainStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdAlterProcedureStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdAlterSequenceStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdAlterTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdAlterTriggerStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCommentStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateCollationStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateDomainStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateFunctionStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateProcedureStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateSequenceStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTriggerStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdExecuteStatement; + +import java.util.Collections; + +/** + * DDL statement visitor for Firebird. + */ +public final class FirebirdDDLStatementVisitor extends FirebirdStatementVisitor implements DDLStatementVisitor { + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitCreateTable(final CreateTableContext ctx) { + FirebirdCreateTableStatement result = new FirebirdCreateTableStatement(); + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + if (null != ctx.createDefinitionClause()) { + CollectionValue createDefinitions = (CollectionValue) visit(ctx.createDefinitionClause()); + for (CreateDefinitionSegment each : createDefinitions.getValue()) { + if (each instanceof ColumnDefinitionSegment) { + result.getColumnDefinitions().add((ColumnDefinitionSegment) each); + } else if (each instanceof ConstraintDefinitionSegment) { + result.getConstraintDefinitions().add((ConstraintDefinitionSegment) each); + } + } + } + return result; + } + + @Override + public ASTNode visitCreateDefinitionClause(final CreateDefinitionClauseContext ctx) { + CollectionValue result = new CollectionValue<>(); + for (CreateDefinitionContext each : ctx.createDefinition()) { + if (null != each.columnDefinition()) { + result.getValue().add((ColumnDefinitionSegment) visit(each.columnDefinition())); + } + if (null != each.constraintDefinition()) { + result.getValue().add((ConstraintDefinitionSegment) visit(each.constraintDefinition())); + } + if (null != each.checkConstraintDefinition()) { + result.getValue().add((ConstraintDefinitionSegment) visit(each.checkConstraintDefinition())); + } + } + return result; + } + + @Override + public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) { + ColumnSegment column = (ColumnSegment) visit(ctx.columnName()); + DataTypeSegment dataType = ctx.dataType() != null ? (DataTypeSegment) visit(ctx.dataType()) : null; + boolean isPrimaryKey = ctx.dataTypeOption().stream().anyMatch(each -> null != each.primaryKey()); + ColumnDefinitionSegment result = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, isPrimaryKey, false, getText(ctx)); + for (DataTypeOptionContext each : ctx.dataTypeOption()) { + if (null != each.referenceDefinition()) { + result.getReferencedTables().add((SimpleTableSegment) visit(each.referenceDefinition().tableName())); + } + } + return result; + } + + private String getText(final ParserRuleContext ctx) { + return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); + } + + @Override + public ASTNode visitCheckConstraintDefinition(final CheckConstraintDefinitionContext ctx) { + return new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex()); + } + + @Override + public ASTNode visitAddConstraintSpecification(final AddConstraintSpecificationContext ctx) { + return new AddConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintDefinitionSegment) visit(ctx.constraintDefinition())); + } + + @Override + public ASTNode visitDropConstraintSpecification(final DropConstraintSpecificationContext ctx) { + return new DropConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintDefinition().constraintName())); + } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitConstraintDefinition(final ConstraintDefinitionContext ctx) { + ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex()); + if (null != ctx.constraintName()) { + result.setConstraintName((ConstraintSegment) visit(ctx.constraintName())); + } + if (null != ctx.primaryKeyOption()) { + result.getPrimaryKeyColumns().addAll(((CollectionValue) visit(ctx.primaryKeyOption().columnNames())).getValue()); + } + if (null != ctx.foreignKeyOption()) { + result.setReferencedTable((SimpleTableSegment) visit(ctx.foreignKeyOption().referenceDefinition().tableName())); + } + return result; + } + + @Override + public ASTNode visitConstraintName(final ConstraintNameContext ctx) { + return new ConstraintSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier())); + } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitAlterTable(final AlterTableContext ctx) { + FirebirdAlterTableStatement result = new FirebirdAlterTableStatement(); + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + if (null != ctx.alterDefinitionClause()) { + for (AlterDefinitionSegment each : ((CollectionValue) visit(ctx.alterDefinitionClause())).getValue()) { + if (each instanceof AddColumnDefinitionSegment) { + result.getAddColumnDefinitions().add((AddColumnDefinitionSegment) each); + } else if (each instanceof ModifyColumnDefinitionSegment) { + result.getModifyColumnDefinitions().add((ModifyColumnDefinitionSegment) each); + } else if (each instanceof DropColumnDefinitionSegment) { + result.getDropColumnDefinitions().add((DropColumnDefinitionSegment) each); + } else if (each instanceof AddConstraintDefinitionSegment) { + result.getAddConstraintDefinitions().add((AddConstraintDefinitionSegment) each); + } else if (each instanceof DropConstraintDefinitionSegment) { + result.getDropConstraintDefinitions().add((DropConstraintDefinitionSegment) each); + } + } + } + return result; + } + + @Override + public ASTNode visitAlterDomain(final AlterDomainContext ctx) { + return new FirebirdAlterDomainStatement(); + } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitAlterDefinitionClause(final AlterDefinitionClauseContext ctx) { + CollectionValue result = new CollectionValue<>(); + if (null != ctx.addColumnSpecification()) { + result.getValue().addAll(((CollectionValue) visit(ctx.addColumnSpecification())).getValue()); + } + if (null != ctx.modifyColumnSpecification()) { + result.getValue().add((ModifyColumnDefinitionSegment) visit(ctx.modifyColumnSpecification())); + } + if (null != ctx.dropColumnSpecification()) { + result.getValue().add((DropColumnDefinitionSegment) visit(ctx.dropColumnSpecification())); + } + return result; + } + + @Override + public ASTNode visitAddColumnSpecification(final AddColumnSpecificationContext ctx) { + CollectionValue result = new CollectionValue<>(); + AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment( + ctx.columnDefinition().getStart().getStartIndex(), ctx.columnDefinition().getStop().getStopIndex(), + Collections.singletonList((ColumnDefinitionSegment) visit(ctx.columnDefinition()))); + result.getValue().add(addColumnDefinition); + return result; + } + + @Override + public ASTNode visitModifyColumnSpecification(final ModifyColumnSpecificationContext ctx) { + // TODO visit pk and table ref + ColumnSegment column = (ColumnSegment) visit(ctx.modifyColumn().columnName()); + DataTypeSegment dataType = null == ctx.dataType() ? null : (DataTypeSegment) visit(ctx.dataType()); + ColumnDefinitionSegment columnDefinition = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, false, false, getText(ctx)); + return new ModifyColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnDefinition); + } + + @Override + public ASTNode visitDropColumnSpecification(final DropColumnSpecificationContext ctx) { + return new DropColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), Collections.singleton((ColumnSegment) visit(ctx.columnName()))); + } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitDropTable(final DropTableContext ctx) { + FirebirdDropTableStatement result = new FirebirdDropTableStatement(); + result.getTables().addAll(((CollectionValue) visit(ctx.tableNames())).getValue()); + return result; + } + + @Override + public ASTNode visitCreateFunction(final CreateFunctionContext ctx) { + return new FirebirdCreateFunctionStatement(); + } + + @Override + public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) { + return new FirebirdCreateProcedureStatement(); + } + + @Override + public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) { + return new FirebirdAlterProcedureStatement(); + } + + @Override + public ASTNode visitAlterSequence(final AlterSequenceContext ctx) { + FirebirdAlterSequenceStatement result = new FirebirdAlterSequenceStatement(); + result.setSequenceName(((SimpleTableSegment) visit(ctx.tableName())).getTableName().getIdentifier().getValue()); + return result; + } + + @Override + public ASTNode visitCreateCollation(final CreateCollationContext ctx) { + return new FirebirdCreateCollationStatement(); + } + + @Override + public ASTNode visitCreateDomain(final CreateDomainContext ctx) { + return new FirebirdCreateDomainStatement(); + } + + @Override + public ASTNode visitAlterTrigger(final AlterTriggerContext ctx) { + return new FirebirdAlterTriggerStatement(); + } + + @Override + public ASTNode visitCreateTrigger(final CreateTriggerContext ctx) { + return new FirebirdCreateTriggerStatement(); + } + + @Override + public ASTNode visitCreateSequence(final CreateSequenceContext ctx) { + FirebirdCreateSequenceStatement result = new FirebirdCreateSequenceStatement(); + result.setSequenceName(((SimpleTableSegment) visit(ctx.tableName())).getTableName().getIdentifier().getValue()); + return result; + } + + @Override + public ASTNode visitExecuteStmt(final ExecuteStmtContext ctx) { + return new FirebirdExecuteStatement(); + } + + @Override + public ASTNode visitComment(final CommentContext ctx) { + FirebirdCommentStatement result = new FirebirdCommentStatement(); + if (null != ctx.tableName()) { + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + } + if (null != ctx.columnName()) { + result.setColumn((ColumnSegment) visit(ctx.columnName())); + } + return result; + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java new file mode 100644 index 0000000000000..c7c69a191b3a9 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java @@ -0,0 +1,492 @@ +/* + * 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.firebird.visitor.statement.type; + +import org.antlr.v4.runtime.misc.Interval; +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AliasContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AssignmentContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AssignmentValueContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.AssignmentValuesContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ColumnNamesContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CombineClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DeleteContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.DuplicateSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.EscapedTableReferenceContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ExprContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.FromClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.GroupByClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.HavingClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.InsertContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.InsertValuesClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.JoinSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.JoinedTableContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.MergeContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.OrderByItemContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ProjectionContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ProjectionsContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.QualifiedShorthandContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SetAssignmentsClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SingleTableClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SubqueryContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableFactorContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableReferenceContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableReferencesContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.UpdateContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.WhereClauseContext; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; +import org.apache.shardingsphere.sql.parser.statement.core.enums.JoinType; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.InsertColumnsSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.complex.CommonExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubqueryExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.AggregationProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.GroupBySegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.OrderBySegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.OrderByItemSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.HavingSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.BooleanLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdInsertStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdMergeStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdSelectStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdUpdateStatement; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * DML statement visitor for Firebird. + */ +public final class FirebirdDMLStatementVisitor extends FirebirdStatementVisitor implements DMLStatementVisitor { + + @Override + public ASTNode visitInsert(final InsertContext ctx) { + FirebirdInsertStatement result = (FirebirdInsertStatement) visit(ctx.insertValuesClause()); + result.setTable((SimpleTableSegment) visit(ctx.tableName())); + result.addParameterMarkerSegments(getParameterMarkerSegments()); + return result; + } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitInsertValuesClause(final InsertValuesClauseContext ctx) { + FirebirdInsertStatement result = new FirebirdInsertStatement(); + if (null != ctx.columnNames()) { + ColumnNamesContext columnNames = ctx.columnNames(); + CollectionValue columnSegments = (CollectionValue) visit(columnNames); + result.setInsertColumns(new InsertColumnsSegment(columnNames.start.getStartIndex(), columnNames.stop.getStopIndex(), columnSegments.getValue())); + } else { + result.setInsertColumns(new InsertColumnsSegment(ctx.start.getStartIndex() - 1, ctx.start.getStartIndex() - 1, Collections.emptyList())); + } + result.getValues().addAll(createInsertValuesSegments(ctx.assignmentValues())); + return result; + } + + private Collection createInsertValuesSegments(final Collection assignmentValuesContexts) { + Collection result = new LinkedList<>(); + for (AssignmentValuesContext each : assignmentValuesContexts) { + result.add((InsertValuesSegment) visit(each)); + } + return result; + } + + @Override + public ASTNode visitUpdate(final UpdateContext ctx) { + FirebirdUpdateStatement result = new FirebirdUpdateStatement(); + result.setTable((TableSegment) visit(ctx.tableReferences())); + result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause())); + if (null != ctx.whereClause()) { + result.setWhere((WhereSegment) visit(ctx.whereClause())); + } + result.addParameterMarkerSegments(getParameterMarkerSegments()); + return result; + } + + @Override + public ASTNode visitSetAssignmentsClause(final SetAssignmentsClauseContext ctx) { + Collection assignments = new LinkedList<>(); + for (AssignmentContext each : ctx.assignment()) { + assignments.add((ColumnAssignmentSegment) visit(each)); + } + return new SetAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), assignments); + } + + @Override + public ASTNode visitAssignmentValues(final AssignmentValuesContext ctx) { + List segments = new LinkedList<>(); + for (AssignmentValueContext each : ctx.assignmentValue()) { + segments.add((ExpressionSegment) visit(each)); + } + return new InsertValuesSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), segments); + } + + @Override + public ASTNode visitAssignment(final AssignmentContext ctx) { + ColumnSegment column = (ColumnSegment) visitColumnName(ctx.columnName()); + List columnSegments = new LinkedList<>(); + columnSegments.add(column); + ExpressionSegment value = (ExpressionSegment) visit(ctx.assignmentValue()); + ColumnAssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value); + result.getColumns().add(column); + return result; + } + + @Override + public ASTNode visitAssignmentValue(final AssignmentValueContext ctx) { + ExprContext expr = ctx.expr(); + if (null != expr) { + return visit(expr); + } + return new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getText()); + } + + @Override + public ASTNode visitDelete(final DeleteContext ctx) { + FirebirdDeleteStatement result = new FirebirdDeleteStatement(); + result.setTable((TableSegment) visit(ctx.singleTableClause())); + if (null != ctx.whereClause()) { + result.setWhere((WhereSegment) visit(ctx.whereClause())); + } + result.addParameterMarkerSegments(getParameterMarkerSegments()); + return result; + } + + @Override + public ASTNode visitSingleTableClause(final SingleTableClauseContext ctx) { + SimpleTableSegment result = (SimpleTableSegment) visit(ctx.tableName()); + if (null != ctx.alias()) { + result.setAlias((AliasSegment) visit(ctx.alias())); + } + return result; + } + + @Override + public ASTNode visitSelect(final SelectContext ctx) { + // TODO :Unsupported for withClause. + FirebirdSelectStatement result = (FirebirdSelectStatement) visit(ctx.combineClause()); + result.addParameterMarkerSegments(getParameterMarkerSegments()); + return result; + } + + @Override + public ASTNode visitCombineClause(final CombineClauseContext ctx) { + // TODO :Unsupported for union SQL. + return visit(ctx.selectClause(0)); + } + + @Override + public ASTNode visitSelectClause(final SelectClauseContext ctx) { + FirebirdSelectStatement result = new FirebirdSelectStatement(); + result.setProjections((ProjectionsSegment) visit(ctx.projections())); + if (!ctx.selectSpecification().isEmpty()) { + result.getProjections().setDistinctRow(isDistinct(ctx.selectSpecification().get(0))); + } + if (null != ctx.fromClause()) { + TableSegment tableSegment = (TableSegment) visit(ctx.fromClause()); + result.setFrom(tableSegment); + } + if (null != ctx.whereClause()) { + result.setWhere((WhereSegment) visit(ctx.whereClause())); + } + if (null != ctx.groupByClause()) { + result.setGroupBy((GroupBySegment) visit(ctx.groupByClause())); + } + if (null != ctx.orderByClause()) { + result.setOrderBy((OrderBySegment) visit(ctx.orderByClause())); + } + if (null != ctx.havingClause()) { + result.setHaving((HavingSegment) visit(ctx.havingClause())); + } + return result; + } + + @Override + public ASTNode visitHavingClause(final HavingClauseContext ctx) { + ExpressionSegment expr = (ExpressionSegment) visit(ctx.expr()); + return new HavingSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), expr); + } + + private boolean isDistinct(final SelectSpecificationContext ctx) { + return ((BooleanLiteralValue) visit(ctx.duplicateSpecification())).getValue(); + } + + @Override + public ASTNode visitDuplicateSpecification(final DuplicateSpecificationContext ctx) { + return new BooleanLiteralValue(null != ctx.DISTINCT()); + } + + @Override + public ASTNode visitProjections(final ProjectionsContext ctx) { + Collection projections = new LinkedList<>(); + if (null != ctx.unqualifiedShorthand()) { + projections.add(new ShorthandProjectionSegment(ctx.unqualifiedShorthand().getStart().getStartIndex(), ctx.unqualifiedShorthand().getStop().getStopIndex())); + } + for (ProjectionContext each : ctx.projection()) { + projections.add((ProjectionSegment) visit(each)); + } + ProjectionsSegment result = new ProjectionsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex()); + result.getProjections().addAll(projections); + return result; + } + + @Override + public ASTNode visitProjection(final ProjectionContext ctx) { + // FIXME :The stop index of project is the stop index of projection, instead of alias. + if (null != ctx.qualifiedShorthand()) { + QualifiedShorthandContext shorthand = ctx.qualifiedShorthand(); + ShorthandProjectionSegment result = new ShorthandProjectionSegment(shorthand.getStart().getStartIndex(), shorthand.getStop().getStopIndex()); + IdentifierValue identifier = new IdentifierValue(shorthand.identifier().getText()); + result.setOwner(new OwnerSegment(shorthand.identifier().getStart().getStartIndex(), shorthand.identifier().getStop().getStopIndex(), identifier)); + return result; + } + AliasSegment alias = null == ctx.alias() ? null : (AliasSegment) visit(ctx.alias()); + if (null != ctx.columnName()) { + ColumnSegment column = (ColumnSegment) visit(ctx.columnName()); + ColumnProjectionSegment result = new ColumnProjectionSegment(column); + result.setAlias(alias); + return result; + } + return createProjection(ctx, alias); + } + + @Override + public ASTNode visitAlias(final AliasContext ctx) { + return null == ctx.identifier() + ? new AliasSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), new IdentifierValue(ctx.STRING_().getText())) + : new AliasSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier())); + } + + private ASTNode createProjection(final ProjectionContext ctx, final AliasSegment alias) { + ASTNode projection = visit(ctx.expr()); + if (projection instanceof AggregationProjectionSegment) { + ((AggregationProjectionSegment) projection).setAlias(alias); + return projection; + } + if (projection instanceof ExpressionProjectionSegment) { + ((ExpressionProjectionSegment) projection).setAlias(alias); + return projection; + } + if (projection instanceof FunctionSegment) { + FunctionSegment segment = (FunctionSegment) projection; + ExpressionProjectionSegment result = new ExpressionProjectionSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getText(), segment); + result.setAlias(alias); + return result; + } + if (projection instanceof CommonExpressionSegment) { + CommonExpressionSegment segment = (CommonExpressionSegment) projection; + ExpressionProjectionSegment result = new ExpressionProjectionSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getText(), segment); + result.setAlias(alias); + return result; + } + // FIXME :For DISTINCT() + if (projection instanceof ColumnSegment) { + ExpressionProjectionSegment result = new ExpressionProjectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), (ColumnSegment) projection); + result.setAlias(alias); + return result; + } + if (projection instanceof SubqueryExpressionSegment) { + SubqueryExpressionSegment subqueryExpressionSegment = (SubqueryExpressionSegment) projection; + String text = ctx.start.getInputStream().getText(new Interval(subqueryExpressionSegment.getStartIndex(), subqueryExpressionSegment.getStopIndex())); + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery(), text); + result.setAlias(alias); + return result; + } + if (projection instanceof BinaryOperationExpression) { + BinaryOperationExpression binaryExpression = (BinaryOperationExpression) projection; + int startIndex = binaryExpression.getStartIndex(); + int stopIndex = null == alias ? binaryExpression.getStopIndex() : alias.getStopIndex(); + ExpressionProjectionSegment result = new ExpressionProjectionSegment(startIndex, stopIndex, binaryExpression.getText(), binaryExpression); + result.setAlias(alias); + return result; + } + if (projection instanceof ParameterMarkerExpressionSegment) { + ParameterMarkerExpressionSegment result = (ParameterMarkerExpressionSegment) projection; + result.setAlias(alias); + return projection; + } + ExpressionSegment column = (ExpressionSegment) projection; + ExpressionProjectionSegment result = null == alias ? new ExpressionProjectionSegment(column.getStartIndex(), column.getStopIndex(), String.valueOf(column.getText()), column) + : new ExpressionProjectionSegment(column.getStartIndex(), ctx.alias().stop.getStopIndex(), String.valueOf(column.getText()), column); + result.setAlias(alias); + return result; + } + + @Override + public ASTNode visitFromClause(final FromClauseContext ctx) { + return visit(ctx.tableReferences()); + } + + @Override + public ASTNode visitTableReferences(final TableReferencesContext ctx) { + TableSegment result = (TableSegment) visit(ctx.escapedTableReference(0)); + if (ctx.escapedTableReference().size() > 1) { + for (int i = 1; i < ctx.escapedTableReference().size(); i++) { + result = generateJoinTableSourceFromEscapedTableReference(ctx.escapedTableReference(i), result); + } + } + return result; + } + + private JoinTableSegment generateJoinTableSourceFromEscapedTableReference(final EscapedTableReferenceContext ctx, final TableSegment tableSegment) { + JoinTableSegment result = new JoinTableSegment(); + result.setStartIndex(tableSegment.getStartIndex()); + result.setStopIndex(ctx.stop.getStopIndex()); + result.setLeft(tableSegment); + result.setRight((TableSegment) visit(ctx)); + result.setJoinType(JoinType.COMMA.name()); + return result; + } + + @Override + public ASTNode visitEscapedTableReference(final EscapedTableReferenceContext ctx) { + return visit(ctx.tableReference()); + } + + @Override + public ASTNode visitTableReference(final TableReferenceContext ctx) { + TableSegment result; + TableSegment left; + left = (TableSegment) visit(ctx.tableFactor()); + if (!ctx.joinedTable().isEmpty()) { + for (JoinedTableContext each : ctx.joinedTable()) { + left = visitJoinedTable(each, left); + } + } + result = left; + return result; + } + + @Override + public ASTNode visitTableFactor(final TableFactorContext ctx) { + if (null != ctx.subquery()) { + FirebirdSelectStatement subquery = (FirebirdSelectStatement) visit(ctx.subquery()); + SubquerySegment subquerySegment = new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), subquery, getOriginalText(ctx.subquery())); + SubqueryTableSegment result = new SubqueryTableSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), subquerySegment); + if (null != ctx.alias()) { + result.setAlias((AliasSegment) visit(ctx.alias())); + } + return result; + } + if (null != ctx.tableName()) { + SimpleTableSegment result = (SimpleTableSegment) visit(ctx.tableName()); + if (null != ctx.alias()) { + result.setAlias((AliasSegment) visit(ctx.alias())); + } + return result; + } + return visit(ctx.tableReferences()); + } + + private JoinTableSegment visitJoinedTable(final JoinedTableContext ctx, final TableSegment tableSegment) { + JoinTableSegment result = new JoinTableSegment(); + result.setLeft(tableSegment); + result.setStartIndex(tableSegment.getStartIndex()); + result.setStopIndex(ctx.stop.getStopIndex()); + TableSegment right = (TableSegment) visit(ctx.tableFactor()); + result.setRight(right); + result.setJoinType(getJoinType(ctx)); + if (null != ctx.joinSpecification()) { + visitJoinSpecification(ctx.joinSpecification(), result); + } + return result; + } + + private String getJoinType(final JoinedTableContext ctx) { + if (null != ctx.LEFT()) { + return JoinType.LEFT.name(); + } else if (null != ctx.RIGHT()) { + return JoinType.RIGHT.name(); + } else if (null != ctx.INNER()) { + return JoinType.INNER.name(); + } else if (null != ctx.CROSS()) { + return JoinType.CROSS.name(); + } + return JoinType.INNER.name(); + } + + private void visitJoinSpecification(final JoinSpecificationContext ctx, final JoinTableSegment joinTableSource) { + if (null != ctx.expr()) { + ExpressionSegment condition = (ExpressionSegment) visit(ctx.expr()); + joinTableSource.setCondition(condition); + } + if (null != ctx.USING()) { + joinTableSource.setUsing(ctx.columnNames().columnName().stream().map(each -> (ColumnSegment) visit(each)).collect(Collectors.toList())); + } + } + + @Override + public ASTNode visitWhereClause(final WhereClauseContext ctx) { + ExpressionSegment segment = (ExpressionSegment) visit(ctx.expr()); + return new WhereSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), segment); + } + + @Override + public ASTNode visitGroupByClause(final GroupByClauseContext ctx) { + Collection items = new LinkedList<>(); + for (OrderByItemContext each : ctx.orderByItem()) { + items.add((OrderByItemSegment) visit(each)); + } + return new GroupBySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), items); + } + + @Override + public ASTNode visitSubquery(final SubqueryContext ctx) { + return visit(ctx.combineClause()); + } + + @Override + public ASTNode visitMerge(final MergeContext ctx) { + FirebirdMergeStatement result = new FirebirdMergeStatement(); + result.setTarget((TableSegment) visit(ctx.intoClause())); + result.setSource((TableSegment) visit(ctx.usingClause())); + // add mergeWhenNotMatched and mergeWhenMatched part + // add RETURNING part + return result; + } +} diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdTCLStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdTCLStatementVisitor.java new file mode 100644 index 0000000000000..8fbf97003aa00 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdTCLStatementVisitor.java @@ -0,0 +1,56 @@ +/* + * 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.firebird.visitor.statement.type; + +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.CommitContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.RollbackContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SavepointContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SetTransactionContext; +import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; +import org.apache.shardingsphere.sql.parser.statement.firebird.tcl.FirebirdCommitStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.tcl.FirebirdRollbackStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.tcl.FirebirdSavepointStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.tcl.FirebirdSetTransactionStatement; + +/** + * TCL statement visitor for Firebird. + */ +public final class FirebirdTCLStatementVisitor extends FirebirdStatementVisitor implements TCLStatementVisitor { + + @Override + public ASTNode visitSetTransaction(final SetTransactionContext ctx) { + return new FirebirdSetTransactionStatement(); + } + + @Override + public ASTNode visitCommit(final CommitContext ctx) { + return new FirebirdCommitStatement(); + } + + @Override + public ASTNode visitRollback(final RollbackContext ctx) { + return new FirebirdRollbackStatement(); + } + + @Override + public ASTNode visitSavepoint(final SavepointContext ctx) { + return new FirebirdSavepointStatement(); + } +} diff --git a/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade b/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade new file mode 100644 index 0000000000000..54f86719a61bd --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.sql.parser.firebird.parser.FirebirdParserFacade diff --git a/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade b/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade new file mode 100644 index 0000000000000..0b5cf05d3c537 --- /dev/null +++ b/parser/sql/dialect/firebird/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitorFacade diff --git a/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalFirebirdParserIT.java b/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalFirebirdParserIT.java new file mode 100644 index 0000000000000..d9f03136a148c --- /dev/null +++ b/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalFirebirdParserIT.java @@ -0,0 +1,25 @@ +/* + * 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.it.firebird.internal; + +import org.apache.shardingsphere.test.it.sql.parser.internal.InternalSQLParserIT; +import org.apache.shardingsphere.test.it.sql.parser.internal.InternalSQLParserITSettings; + +@InternalSQLParserITSettings("Firebird") +class InternalFirebirdParserIT extends InternalSQLParserIT { +} diff --git a/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalUnsupportedFirebirdParserIT.java b/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalUnsupportedFirebirdParserIT.java new file mode 100644 index 0000000000000..9193b19a17475 --- /dev/null +++ b/parser/sql/dialect/firebird/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/firebird/internal/InternalUnsupportedFirebirdParserIT.java @@ -0,0 +1,25 @@ +/* + * 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.it.firebird.internal; + +import org.apache.shardingsphere.test.it.sql.parser.internal.InternalSQLParserITSettings; +import org.apache.shardingsphere.test.it.sql.parser.internal.InternalUnsupportedSQLParserIT; + +@InternalSQLParserITSettings("Firebird") +class InternalUnsupportedFirebirdParserIT extends InternalUnsupportedSQLParserIT { +} diff --git a/parser/sql/dialect/firebird/src/test/resources/logback-test.xml b/parser/sql/dialect/firebird/src/test/resources/logback-test.xml new file mode 100644 index 0000000000000..d17f7efbfaf30 --- /dev/null +++ b/parser/sql/dialect/firebird/src/test/resources/logback-test.xml @@ -0,0 +1,34 @@ + + + + + + + + [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n + + + + + + + + + + + diff --git a/parser/sql/dialect/pom.xml b/parser/sql/dialect/pom.xml index 4e30b65d51711..60d8bf67788f3 100644 --- a/parser/sql/dialect/pom.xml +++ b/parser/sql/dialect/pom.xml @@ -37,6 +37,7 @@ doris hive presto + firebird diff --git a/parser/sql/engine/pom.xml b/parser/sql/engine/pom.xml index d6d7a35cd497a..b435fa596d6d0 100644 --- a/parser/sql/engine/pom.xml +++ b/parser/sql/engine/pom.xml @@ -42,6 +42,11 @@ shardingsphere-parser-sql-statement-doris ${project.version} + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-firebird + ${project.version} + org.apache.shardingsphere shardingsphere-parser-sql-statement-hive diff --git a/parser/sql/statement/type/firebird/pom.xml b/parser/sql/statement/type/firebird/pom.xml new file mode 100644 index 0000000000000..7ff2c3d5db84f --- /dev/null +++ b/parser/sql/statement/type/firebird/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-type + 5.5.2-SNAPSHOT + + shardingsphere-parser-sql-statement-firebird + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-core + ${project.version} + + + diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/FirebirdStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/FirebirdStatement.java new file mode 100644 index 0000000000000..fb194f0c9576e --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/FirebirdStatement.java @@ -0,0 +1,33 @@ +/* + * 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.firebird; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; + +/** + * Firebird statement. + */ +public interface FirebirdStatement extends SQLStatement { + + @Override + default DatabaseType getDatabaseType() { + return TypedSPILoader.getService(DatabaseType.class, "Firebird"); + } +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdSetStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdSetStatement.java new file mode 100644 index 0000000000000..402a0e3e80129 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdSetStatement.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.firebird.dal; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird set statement. + */ +public final class FirebirdSetStatement extends SetStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdShowStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdShowStatement.java new file mode 100644 index 0000000000000..531da728dea09 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dal/FirebirdShowStatement.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.firebird.dal; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird show statement. + */ +public final class FirebirdShowStatement extends ShowStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdAlterUserStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdAlterUserStatement.java new file mode 100644 index 0000000000000..57e87bd4850aa --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdAlterUserStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.AlterUserStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter user statement. + */ +public final class FirebirdAlterUserStatement extends AlterUserStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateRoleStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateRoleStatement.java new file mode 100644 index 0000000000000..1ad51f303f07b --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateRoleStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.CreateRoleStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create role statement. + */ +public final class FirebirdCreateRoleStatement extends CreateRoleStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateUserStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateUserStatement.java new file mode 100644 index 0000000000000..c7eee703c74f5 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdCreateUserStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.CreateUserStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create user statement. + */ +public final class FirebirdCreateUserStatement extends CreateUserStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropRoleStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropRoleStatement.java new file mode 100644 index 0000000000000..9edb68b55998e --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropRoleStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DropRoleStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird drop role statement. + */ +public final class FirebirdDropRoleStatement extends DropRoleStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropUserStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropUserStatement.java new file mode 100644 index 0000000000000..3e9b170038016 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdDropUserStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DropUserStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird drop user statement. + */ +public final class FirebirdDropUserStatement extends DropUserStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdGrantStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdGrantStatement.java new file mode 100644 index 0000000000000..7d2252158284b --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdGrantStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.GrantStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird grant statement. + */ +public final class FirebirdGrantStatement extends GrantStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRenameUserStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRenameUserStatement.java new file mode 100644 index 0000000000000..40678e32c68a1 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRenameUserStatement.java @@ -0,0 +1,28 @@ +/* + * 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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DCLStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird rename user statement. + */ +public final class FirebirdRenameUserStatement extends AbstractSQLStatement implements DCLStatement, FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRevokeStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRevokeStatement.java new file mode 100644 index 0000000000000..b419a14cde69b --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dcl/FirebirdRevokeStatement.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.firebird.dcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.RevokeStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird revoke statement. + */ +public final class FirebirdRevokeStatement extends RevokeStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterDomainStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterDomainStatement.java new file mode 100644 index 0000000000000..145b5d6c24dda --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterDomainStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterDomainStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter table statement. + */ +public final class FirebirdAlterDomainStatement extends AlterDomainStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterProcedureStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterProcedureStatement.java new file mode 100644 index 0000000000000..3f42b4c5dc941 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterProcedureStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterProcedureStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter procedure statement. + */ +public final class FirebirdAlterProcedureStatement extends AlterProcedureStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterSequenceStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterSequenceStatement.java new file mode 100644 index 0000000000000..ff7c40d162a6e --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterSequenceStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterSequenceStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter sequence statement. + */ +public final class FirebirdAlterSequenceStatement extends AlterSequenceStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTableStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTableStatement.java new file mode 100644 index 0000000000000..6a66d3cfea1ae --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTableStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter table statement. + */ +public final class FirebirdAlterTableStatement extends AlterTableStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTriggerStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTriggerStatement.java new file mode 100644 index 0000000000000..70abe7185fc7e --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdAlterTriggerStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTriggerStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter trigger statement. + */ +public final class FirebirdAlterTriggerStatement extends AlterTriggerStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCommentStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCommentStatement.java new file mode 100644 index 0000000000000..b2bed7109f495 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCommentStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CommentStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird comment statement. + */ +public final class FirebirdCommentStatement extends CommentStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateCollationStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateCollationStatement.java new file mode 100644 index 0000000000000..fde125b98bb94 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateCollationStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateCollationStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create collation statement. + */ +public final class FirebirdCreateCollationStatement extends CreateCollationStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateDomainStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateDomainStatement.java new file mode 100644 index 0000000000000..990b6adc7314c --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateDomainStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateDomainStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create domain statement. + */ +public final class FirebirdCreateDomainStatement extends CreateDomainStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateFunctionStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateFunctionStatement.java new file mode 100644 index 0000000000000..ae3bfb7523705 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateFunctionStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateFunctionStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create function statement. + */ +public final class FirebirdCreateFunctionStatement extends CreateFunctionStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateProcedureStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateProcedureStatement.java new file mode 100644 index 0000000000000..44d6ad3598c91 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateProcedureStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateProcedureStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create procedure statement. + */ +public final class FirebirdCreateProcedureStatement extends CreateProcedureStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateSequenceStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateSequenceStatement.java new file mode 100644 index 0000000000000..76fd933dd56f5 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateSequenceStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateSequenceStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create sequence statement. + */ +public final class FirebirdCreateSequenceStatement extends CreateSequenceStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTableStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTableStatement.java new file mode 100644 index 0000000000000..44f33a957fdfa --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTableStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird create table statement. + */ +public final class FirebirdCreateTableStatement extends CreateTableStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTriggerStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTriggerStatement.java new file mode 100644 index 0000000000000..b3228eb94714a --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdCreateTriggerStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTriggerStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird alter procedure statement. + */ +public final class FirebirdCreateTriggerStatement extends CreateTriggerStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdDropTableStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdDropTableStatement.java new file mode 100644 index 0000000000000..18cfd32560aed --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdDropTableStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird drop table statement. + */ +public final class FirebirdDropTableStatement extends DropTableStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdExecuteStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdExecuteStatement.java new file mode 100644 index 0000000000000..88a25819a870d --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/ddl/FirebirdExecuteStatement.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.firebird.ddl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.ExecuteStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird execute statement. + */ +public final class FirebirdExecuteStatement extends ExecuteStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java new file mode 100644 index 0000000000000..080f6f1b3ce16 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.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.firebird.dml; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird delete statement. + */ +public final class FirebirdDeleteStatement extends DeleteStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java new file mode 100644 index 0000000000000..1f7e92aa36657 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.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.firebird.dml; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird insert statement. + */ +public final class FirebirdInsertStatement extends InsertStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdMergeStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdMergeStatement.java new file mode 100644 index 0000000000000..04880da20a7ee --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdMergeStatement.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.firebird.dml; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.MergeStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird merge statement. + */ +public final class FirebirdMergeStatement extends MergeStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdSelectStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdSelectStatement.java new file mode 100644 index 0000000000000..b26ffbd731295 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdSelectStatement.java @@ -0,0 +1,43 @@ +/* + * 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.firebird.dml; + +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +import java.util.Optional; + +/** + * Firebird select statement. + */ +@Setter +public final class FirebirdSelectStatement extends SelectStatement implements FirebirdStatement { + + private LimitSegment limit; + + /** + * Get order by segment. + * + * @return order by segment + */ + public Optional getLimit() { + return Optional.ofNullable(limit); + } +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java new file mode 100644 index 0000000000000..3176d5d921bde --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.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.firebird.dml; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird update statement. + */ +public final class FirebirdUpdateStatement extends UpdateStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdCommitStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdCommitStatement.java new file mode 100644 index 0000000000000..70b4d8b0bf415 --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdCommitStatement.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.firebird.tcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird commit statement. + */ +public final class FirebirdCommitStatement extends CommitStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdRollbackStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdRollbackStatement.java new file mode 100644 index 0000000000000..d9d48a002b31b --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdRollbackStatement.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.firebird.tcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird rollback statement. + */ +public final class FirebirdRollbackStatement extends RollbackStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSavepointStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSavepointStatement.java new file mode 100644 index 0000000000000..61162ecc623af --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSavepointStatement.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.firebird.tcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SavepointStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird savepoint statement. + */ +public final class FirebirdSavepointStatement extends SavepointStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSetTransactionStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSetTransactionStatement.java new file mode 100644 index 0000000000000..d22145c853e4b --- /dev/null +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/tcl/FirebirdSetTransactionStatement.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.firebird.tcl; + +import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetTransactionStatement; +import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; + +/** + * Firebird set transaction statement. + */ +public final class FirebirdSetTransactionStatement extends SetTransactionStatement implements FirebirdStatement { +} diff --git a/parser/sql/statement/type/pom.xml b/parser/sql/statement/type/pom.xml index c8cc9edcc240c..3694c27d3019a 100644 --- a/parser/sql/statement/type/pom.xml +++ b/parser/sql/statement/type/pom.xml @@ -30,6 +30,7 @@ clickhouse doris + firebird hive mysql opengauss diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/sql/SQLCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/sql/SQLCases.java index a486b477d6c99..31d558110fbbc 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/sql/SQLCases.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/sql/SQLCases.java @@ -76,7 +76,7 @@ private Collection getDatabaseTypes(final String databaseTypes) { } private Collection getAllDatabaseTypes() { - return Arrays.asList("H2", "MySQL", "PostgreSQL", "Oracle", "SQLServer", "SQL92", "openGauss", "Doris"); + return Arrays.asList("H2", "MySQL", "PostgreSQL", "Oracle", "SQLServer", "SQL92", "openGauss", "Doris", "Firebird"); } private boolean containsSQLCaseType(final SQLCase sqlCase, final SQLCaseType caseType) { diff --git a/test/it/parser/src/main/resources/case/ddl/create-function.xml b/test/it/parser/src/main/resources/case/ddl/create-function.xml index fd83a87f8a8cd..bcdc3ac4e884f 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-function.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-function.xml @@ -30,4 +30,5 @@ + diff --git a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml index 9f2011c67bfb8..788f6da030de9 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml @@ -51,4 +51,17 @@ + + + + + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dcl/create-role.xml b/test/it/parser/src/main/resources/sql/supported/dcl/create-role.xml index 66e9e187ac42f..970ef54c485c9 100644 --- a/test/it/parser/src/main/resources/sql/supported/dcl/create-role.xml +++ b/test/it/parser/src/main/resources/sql/supported/dcl/create-role.xml @@ -17,7 +17,7 @@ --> - + diff --git a/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml b/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml index 2b499b5b255dd..2b3777268137c 100644 --- a/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml +++ b/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml @@ -22,7 +22,7 @@ - + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml index 5f7efed8d8973..4901542eae3fb 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml @@ -74,4 +74,5 @@ + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml index fc975d00875c7..4769985b11fda 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml @@ -47,4 +47,6 @@ + + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-comment.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-comment.xml index 3f638e45f1c81..7eab09e558fc1 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select-comment.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select-comment.xml @@ -17,8 +17,8 @@ --> - + - - + +