From af0287f38b95f8c1ea3581ba5a58bdf7d454545d Mon Sep 17 00:00:00 2001 From: morrySnow Date: Mon, 22 Apr 2024 18:08:01 +0800 Subject: [PATCH] [feature](Nereids) support set and use statement syntax only 1. add a new Command type: UnsupportedCommand to handle the statement only support parse but could not execute. 2. support syntax about set and use --- .../org/apache/doris/nereids/DorisLexer.g4 | 1 + .../org/apache/doris/nereids/DorisParser.g4 | 35 +++++++++++++- .../nereids/parser/LogicalPlanBuilder.java | 7 +++ .../doris/nereids/trees/plans/PlanType.java | 4 +- .../plans/commands/UnsupportedCommand.java | 47 +++++++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 5 ++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UnsupportedCommand.java diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 index 33354199e67abdf..a976710afc2ae07 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 @@ -549,6 +549,7 @@ VALUES: 'VALUES'; VARCHAR: 'VARCHAR'; VARIABLES: 'VARIABLES'; VARIANT: 'VARIANT'; +VAULT: 'VAULT'; VERBOSE: 'VERBOSE'; VERSION: 'VERSION'; VIEW: 'VIEW'; diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 74870648786d1aa..c9faacba0ce3f7a 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -113,7 +113,40 @@ statementBase constraint #addConstraint | ALTER TABLE table=multipartIdentifier DROP CONSTRAINT constraintName=errorCapturingIdentifier #dropConstraint - | SHOW CONSTRAINTS FROM table=multipartIdentifier #showConstraint + | SHOW CONSTRAINTS FROM table=multipartIdentifier #showConstraint + | unsupportedStatement #unsupported + ; + +unsupportedStatement + : SET identifier AS DEFAULT STORAGE VAULT #setDefaultStorageVault + | SET PROPERTY (FOR user=identifierOrText)? propertyItemList #setUserProperties + | SET (GLOBAL | LOCAL | SESSION)? identifier EQ (expression | DEFAULT) #setSystemVariableWithType + | SET variable #setSystemVariableWithoutType + | SET (CHAR SET | CHARSET) (charsetName=identifierOrText | DEFAULT) #setCharset + | SET NAMES EQ expression #setNames + | SET (GLOBAL | LOCAL | SESSION)? TRANSACTION + ( transactionAccessMode + | isolationLevel + | transactionAccessMode COMMA isolationLevel + | isolationLevel COMMA transactionAccessMode) #setTransaction + | SET NAMES (charsetName=identifierOrText | DEFAULT) (COLLATE collateName=identifierOrText | DEFAULT)? #setCollate + | SET PASSWORD (FOR userIdentify)? EQ (STRING_LITERAL | (PASSWORD LEFT_PAREN STRING_LITERAL RIGHT_PAREN)) #setPassword + | SET LDAP_ADMIN_PASSWORD EQ (STRING_LITERAL | (PASSWORD LEFT_PAREN STRING_LITERAL RIGHT_PAREN)) #setLdapAdminPassword + | USE (catalog=identifier DOT)? database=identifier #useDatabase + | USE ((catalog=identifier DOT)? database=identifier)? ATSIGN cluster=identifier #useCloudCluster + ; + +variable + : (ATSIGN ATSIGN (GLOBAL | LOCAL | SESSION)?)? identifier EQ (expression | DEFAULT) #setSystemVariable + | ATSIGN identifier EQ expression #setUserVariable + ; + +transactionAccessMode + : READ (ONLY | WRITE) + ; + +isolationLevel + : ISOLATION LEVEL ((READ UNCOMMITTED) | (READ COMMITTED) | (REPEATABLE READ) | (SERIALIZABLE)) ; constraint diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 5e3a5b70db80f86..47910e4babc6e76 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -188,6 +188,7 @@ import org.apache.doris.nereids.DorisParser.TimestampdiffContext; import org.apache.doris.nereids.DorisParser.TypeConstructorContext; import org.apache.doris.nereids.DorisParser.UnitIdentifierContext; +import org.apache.doris.nereids.DorisParser.UnsupportedContext; import org.apache.doris.nereids.DorisParser.UpdateAssignmentContext; import org.apache.doris.nereids.DorisParser.UpdateAssignmentSeqContext; import org.apache.doris.nereids.DorisParser.UpdateContext; @@ -377,6 +378,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand; +import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand; import org.apache.doris.nereids.trees.plans.commands.UpdateCommand; import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVInfo; import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVPropertyInfo; @@ -3480,4 +3482,9 @@ public LogicalPlan visitShowCreateProcedure(ShowCreateProcedureContext ctx) { FuncNameInfo procedureName = new FuncNameInfo(nameParts); return ParserUtils.withOrigin(ctx, () -> new ShowCreateProcedureCommand(procedureName)); } + + @Override + public Object visitUnsupported(UnsupportedContext ctx) { + return UnsupportedCommand.INSTANCE; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java index 165dcd5e3cab7f1..cfea8006ae1f749 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java @@ -151,5 +151,7 @@ public enum PlanType { DROP_PROCEDURE_COMMAND, SHOW_PROCEDURE_COMMAND, SHOW_CREATE_PROCEDURE_COMMAND, - CREATE_VIEW_COMMAND + CREATE_VIEW_COMMAND, + + UNSUPPORTED_COMMAND } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UnsupportedCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UnsupportedCommand.java new file mode 100644 index 000000000000000..9f2d59342aca772 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UnsupportedCommand.java @@ -0,0 +1,47 @@ +// 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.doris.nereids.trees.plans.commands; + +import org.apache.doris.common.AnalysisException; +import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.StmtExecutor; + +/** + * all Nereids' unsupported command + */ +public class UnsupportedCommand extends Command implements ForwardWithSync { + + public static UnsupportedCommand INSTANCE = new UnsupportedCommand(); + + public UnsupportedCommand() { + super(PlanType.UNSUPPORTED_COMMAND); + } + + @Override + public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { + ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce(); + throw new AnalysisException("unsupported command"); + } + + @Override + public R accept(PlanVisitor visitor, C context) { + return visitor.visitUnsupportedCommand(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java index 527ccb1ffe080b8..546d1ed352dc071 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java @@ -41,6 +41,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand; +import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand; import org.apache.doris.nereids.trees.plans.commands.UpdateCommand; import org.apache.doris.nereids.trees.plans.commands.insert.BatchInsertIntoTableCommand; import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand; @@ -161,4 +162,8 @@ default R visitShowCreateProcedureCommand(ShowCreateProcedureCommand showCreateP default R visitCreateViewCommand(CreateViewCommand createViewCommand, C context) { return visitCommand(createViewCommand, context); } + + default R visitUnsupportedCommand(UnsupportedCommand unsupportedCommand, C context) { + return visitCommand(unsupportedCommand, context); + } }