This is an automated email from the ASF dual-hosted git repository. jiangmaolin pushed a commit to branch dev-5.5.1 in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit a71e6f401b3e8ba9b26bcf61f9adb982081f96fe Author: RaigorJiang <[email protected]> AuthorDate: Tue Oct 29 22:39:29 2024 +0800 Add SphereExKernelDistSQLStatementVisitor --- .../src/main/antlr4/imports/SphereExKeyword.g4 | 64 ------------------- .../main/antlr4/imports/SphereExRALStatement.g4 | 64 ------------------- .../SphereExKernelDistSQLStatementVisitor.java | 71 ++++++++++++++++++++++ .../kernel/KernelDistSQLStatementParserEngine.java | 6 +- .../ral/queryable/ShowSeriesNumberStatement.java | 26 ++++++++ .../ral/queryable/ShowSeriesNumberExecutor.java | 48 +++++++++++++++ .../handler/ProxyBackendHandlerFactory.java | 5 ++ ...stsql.handler.engine.query.DistSQLQueryExecutor | 1 + 8 files changed, 156 insertions(+), 129 deletions(-) diff --git a/parser/distsql/engine/src/main/antlr4/imports/SphereExKeyword.g4 b/parser/distsql/engine/src/main/antlr4/imports/SphereExKeyword.g4 index 5774c55c5f8..112189d640c 100644 --- a/parser/distsql/engine/src/main/antlr4/imports/SphereExKeyword.g4 +++ b/parser/distsql/engine/src/main/antlr4/imports/SphereExKeyword.g4 @@ -19,18 +19,6 @@ lexer grammar SphereExKeyword; import Alphabet; -LICENSE - : L I C E N S E - ; - -INFO - : I N F O - ; - -REGISTER - : R E G I S T E R - ; - SERIES : S E R I E S ; @@ -39,34 +27,10 @@ NUMBER : N U M B E R ; -STRUCTURE - : S T R U C T U R E - ; - -WARMUP - : W A R M U P - ; - -LOADING - : L O A D I N G - ; - -STATUS - : S T A T U S - ; - -CONVERTING - : C O N V E R T I N G - ; - LOCKS : L O C K S ; -DIRECTORY - : D I R E C T O R Y - ; - LAST : L A S T ; @@ -78,31 +42,3 @@ EXECUTE FAILED : F A I L E D ; - -MANAGER - : M A N A G E R - ; - -REFERENCES - : R E F E R E N C E S - ; - -REFERENCE - : R E F E R E N C E - ; - -DDL - : D D L - ; - -COLUMNS - : C O L U M N S - ; - -DATA_TYPE - : D A T A UL_ T Y P E - ; - -INSTANCE - : I N S T A N C E - ; diff --git a/parser/distsql/engine/src/main/antlr4/imports/SphereExRALStatement.g4 b/parser/distsql/engine/src/main/antlr4/imports/SphereExRALStatement.g4 index a739f803588..1009ca4f08e 100644 --- a/parser/distsql/engine/src/main/antlr4/imports/SphereExRALStatement.g4 +++ b/parser/distsql/engine/src/main/antlr4/imports/SphereExRALStatement.g4 @@ -19,50 +19,10 @@ grammar SphereExRALStatement; import SphereExKeyword, BaseRule; -showInstanceStorageUnits - : SHOW INSTANCE STORAGE UNITS - ; - -showLicenseInfo - : SHOW LICENSE INFO (license)? - ; - -showLicenseStatus - : SHOW LICENSE STATUS - ; - -registerLicense - : REGISTER LICENSE license - ; - -license - : STRING_ - ; - showSeriesNumber : SHOW SERIES NUMBER ; -showLoadingMetadataList - : SHOW LOADING METADATA LIST (FROM databaseName)? - ; - -showLoadingMetadataStatus - : SHOW LOADING METADATA STATUS storageUnitName (FROM databaseName)? - ; - -showConvertingList - : SHOW CONVERTING LIST (FROM databaseName)? - ; - -showConvertingStatus - : SHOW CONVERTING STATUS tableName (FROM databaseName)? - ; - -exportDatabaseStructure - : EXPORT DATABASE STRUCTURE (FROM databaseName)? TO FILE filePath - ; - showDistLocks : SHOW DIST LOCKS ; @@ -79,34 +39,10 @@ dropLastExecuteFailedNode : DROP LAST EXECUTE FAILED NODE instanceId (COMMA_ instanceId)* ; -showKeyManagerReference - : SHOW KEY MANAGER (REFERENCES | REFERENCE referenceKey) - ; - -dropKeyManagerReference - : DROP KEY MANAGER REFERENCE referenceKey (COMMA_ referenceKey)* - ; - -referenceKey - : STRING_ - ; - lockKey : STRING_ ; -filePath - : STRING_ - ; - -warmupSQL - : WARMUP sql - ; - -sql - : STRING_ - ; - instanceId : IDENTIFIER_ | STRING_ ; diff --git a/parser/distsql/engine/src/main/java/com/sphereex/dbplusengine/distsql/parser/kernel/SphereExKernelDistSQLStatementVisitor.java b/parser/distsql/engine/src/main/java/com/sphereex/dbplusengine/distsql/parser/kernel/SphereExKernelDistSQLStatementVisitor.java new file mode 100644 index 00000000000..f5269a288ef --- /dev/null +++ b/parser/distsql/engine/src/main/java/com/sphereex/dbplusengine/distsql/parser/kernel/SphereExKernelDistSQLStatementVisitor.java @@ -0,0 +1,71 @@ +/* + * 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 com.sphereex.dbplusengine.distsql.parser.kernel; + +import com.sphereex.dbplusengine.distsql.statement.ral.lock.ShowDistLocksStatement; +import com.sphereex.dbplusengine.distsql.statement.ral.lock.UnlockDistLockStatement; +import com.sphereex.dbplusengine.distsql.statement.ral.queryable.ShowLastExecuteFailedNodesStatement; +import com.sphereex.dbplusengine.distsql.statement.ral.queryable.ShowSeriesNumberStatement; +import com.sphereex.dbplusengine.distsql.statement.ral.updatable.DropLastExecuteFailedNodeStatement; +import org.antlr.v4.runtime.tree.ParseTree; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementBaseVisitor; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.DropLastExecuteFailedNodeContext; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowDistLocksContext; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowLastExecuteFailedNodesContext; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSeriesNumberContext; +import org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.UnlockDistLockContext; +import org.apache.shardingsphere.sql.parser.api.ASTNode; +import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; + +import java.util.stream.Collectors; + +/** + * SphereEx SQL statement visitor for kernel DistSQL. + */ +public final class SphereExKernelDistSQLStatementVisitor extends KernelDistSQLStatementBaseVisitor<ASTNode> implements SQLVisitor<ASTNode> { + + @Override + public ASTNode visitShowSeriesNumber(final ShowSeriesNumberContext ctx) { + return new ShowSeriesNumberStatement(); + } + + @Override + public ASTNode visitShowDistLocks(final ShowDistLocksContext ctx) { + return new ShowDistLocksStatement(); + } + + @Override + public ASTNode visitUnlockDistLock(final UnlockDistLockContext ctx) { + return new UnlockDistLockStatement(getIdentifierValue(ctx.lockKey())); + } + + @Override + public ASTNode visitShowLastExecuteFailedNodes(final ShowLastExecuteFailedNodesContext ctx) { + return new ShowLastExecuteFailedNodesStatement(); + } + + @Override + public ASTNode visitDropLastExecuteFailedNode(final DropLastExecuteFailedNodeContext ctx) { + return new DropLastExecuteFailedNodeStatement(ctx.instanceId().stream().map(this::getIdentifierValue).collect(Collectors.toList())); + } + + private String getIdentifierValue(final ParseTree context) { + return null == context ? null : new IdentifierValue(context.getText()).getValue(); + } +} diff --git a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementParserEngine.java b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementParserEngine.java index d89e13d9087..a15d210133b 100644 --- a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementParserEngine.java +++ b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementParserEngine.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.distsql.parser.core.kernel; +import com.sphereex.dbplusengine.distsql.parser.kernel.SphereExKernelDistSQLStatementVisitor; import org.antlr.v4.runtime.tree.ErrorNode; import org.apache.shardingsphere.sql.parser.api.ASTNode; import org.apache.shardingsphere.sql.parser.core.ParseASTNode; @@ -44,6 +45,9 @@ public final class KernelDistSQLStatementParserEngine { if (parseASTNode.getRootNode() instanceof ErrorNode) { throw new SQLParsingException(sql); } - return (SQLStatement) (new KernelDistSQLStatementVisitor()).visit(parseASTNode.getRootNode()); + // SPEX CHANGED: BEGIN + SQLStatement result = (SQLStatement) (new KernelDistSQLStatementVisitor()).visit(parseASTNode.getRootNode()); + return null == result ? (SQLStatement) (new SphereExKernelDistSQLStatementVisitor()).visit(parseASTNode.getRootNode()) : result; + // SPEX CHANGED: END } } diff --git a/parser/distsql/statement/src/main/java/com/sphereex/dbplusengine/distsql/statement/ral/queryable/ShowSeriesNumberStatement.java b/parser/distsql/statement/src/main/java/com/sphereex/dbplusengine/distsql/statement/ral/queryable/ShowSeriesNumberStatement.java new file mode 100644 index 00000000000..42c08e27d92 --- /dev/null +++ b/parser/distsql/statement/src/main/java/com/sphereex/dbplusengine/distsql/statement/ral/queryable/ShowSeriesNumberStatement.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sphereex.dbplusengine.distsql.statement.ral.queryable; + +import org.apache.shardingsphere.distsql.statement.ral.queryable.QueryableRALStatement; + +/** + * Show series number statement. + */ +public final class ShowSeriesNumberStatement extends QueryableRALStatement { +} diff --git a/proxy/backend/core/src/main/java/com/sphereex/dbplusengine/proxy/backend/handler/distsql/ral/queryable/ShowSeriesNumberExecutor.java b/proxy/backend/core/src/main/java/com/sphereex/dbplusengine/proxy/backend/handler/distsql/ral/queryable/ShowSeriesNumberExecutor.java new file mode 100644 index 00000000000..4414b2fced9 --- /dev/null +++ b/proxy/backend/core/src/main/java/com/sphereex/dbplusengine/proxy/backend/handler/distsql/ral/queryable/ShowSeriesNumberExecutor.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 com.sphereex.dbplusengine.proxy.backend.handler.distsql.ral.queryable; + +import com.sphereex.dbplusengine.distsql.statement.ral.queryable.ShowSeriesNumberStatement; +import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor; +import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion; +import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; +import org.apache.shardingsphere.mode.manager.ContextManager; + +import java.util.Collection; +import java.util.Collections; + +/** + * Show series number executor. + */ +public final class ShowSeriesNumberExecutor implements DistSQLQueryExecutor<ShowSeriesNumberStatement> { + + @Override + public Collection<String> getColumnNames(final ShowSeriesNumberStatement sqlStatement) { + return Collections.singleton("series_number"); + } + + @Override + public Collection<LocalDataQueryResultRow> getRows(final ShowSeriesNumberStatement sqlStatement, final ContextManager contextManager) { + return Collections.singleton(new LocalDataQueryResultRow(ShardingSphereVersion.BUILD_GIT_COMMIT_ID)); + } + + @Override + public Class<ShowSeriesNumberStatement> getType() { + return ShowSeriesNumberStatement.class; + } +} diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java index cceba192459..771beefa2d4 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java @@ -182,6 +182,11 @@ public final class ProxyBackendHandlerFactory { } private static void checkUnsupportedSQLStatement(final SQLStatement sqlStatement) { + // SPEX ADDED: BEGIN + if (sqlStatement instanceof DistSQLStatement) { + return; + } + // SPEX ADDED: END if (sqlStatement instanceof DCLStatement || sqlStatement instanceof FlushStatement || sqlStatement instanceof MySQLShowCreateUserStatement || sqlStatement instanceof RenameTableStatement) { throw new UnsupportedSQLOperationException(String.format("unsupported SQL statement `%s`", sqlStatement.getClass().getSimpleName())); } diff --git a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor index 07b94c2aaab..af17e53ba37 100644 --- a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor +++ b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor @@ -29,5 +29,6 @@ org.apache.shardingsphere.proxy.backend.handler.distsql.rul.FormatSQLExecutor org.apache.shardingsphere.proxy.backend.handler.distsql.rul.ParseDistSQLExecutor org.apache.shardingsphere.proxy.backend.handler.distsql.rul.PreviewExecutor +com.sphereex.dbplusengine.proxy.backend.handler.distsql.ral.queryable.ShowSeriesNumberExecutor com.sphereex.dbplusengine.proxy.backend.handler.distsql.ral.lock.ShowDistLocksExecutor com.sphereex.dbplusengine.proxy.backend.handler.distsql.ral.queryable.ShowLastExecuteFailedNodesExecutor
