From 153c98ad1e2fdf0220995a58b8f17d62fbf6fbba Mon Sep 17 00:00:00 2001 From: starocean999 Date: Wed, 13 Nov 2024 11:45:10 +0800 Subject: [PATCH] [refactor](nereids)make Forward/NoForward extends Redirect interface (#43714) Some command can't be simply classified as Forward/NoForward, it should rewrite toRedirectStatus method to do correct job. So we add a new Redirect interface to meet the requirement. --- .../nereids/trees/plans/commands/Forward.java | 5 +--- .../trees/plans/commands/NoForward.java | 8 +++++- .../trees/plans/commands/Redirect.java | 27 +++++++++++++++++++ .../trees/plans/commands/ShowCommand.java | 8 +++++- .../org/apache/doris/qe/StmtExecutor.java | 5 ++-- 5 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Redirect.java diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Forward.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Forward.java index c175ccc820e28b..b5fd978e02c141 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Forward.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Forward.java @@ -17,14 +17,11 @@ package org.apache.doris.nereids.trees.plans.commands; -import org.apache.doris.analysis.RedirectStatus; import org.apache.doris.qe.ConnectContext; /** * forward to master. */ -public interface Forward { - RedirectStatus toRedirectStatus(); - +public interface Forward extends Redirect { default void afterForwardToMaster(ConnectContext ctx) throws Exception {} } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NoForward.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NoForward.java index 9ca64d73aa4839..e4d7d299f3fba3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NoForward.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NoForward.java @@ -17,8 +17,14 @@ package org.apache.doris.nereids.trees.plans.commands; +import org.apache.doris.analysis.RedirectStatus; + /** * not forward to master. */ -public interface NoForward { +public interface NoForward extends Redirect { + @Override + default RedirectStatus toRedirectStatus() { + return RedirectStatus.NO_FORWARD; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Redirect.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Redirect.java new file mode 100644 index 00000000000000..e8a370b3981c55 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Redirect.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.doris.nereids.trees.plans.commands; + +import org.apache.doris.analysis.RedirectStatus; + +/** + * Redirect. + */ +public interface Redirect { + RedirectStatus toRedirectStatus(); +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java index 3ce40cdd04d607..55555ec47522c8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java @@ -17,6 +17,7 @@ package org.apache.doris.nereids.trees.plans.commands; +import org.apache.doris.analysis.RedirectStatus; import org.apache.doris.analysis.StmtType; import org.apache.doris.nereids.trees.plans.PlanType; import org.apache.doris.qe.ConnectContext; @@ -26,7 +27,7 @@ /** * base class for all show commands */ -public abstract class ShowCommand extends Command implements NoForward { +public abstract class ShowCommand extends Command implements Redirect { public ShowCommand(PlanType type) { super(type); } @@ -48,6 +49,11 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { } } + @Override + public RedirectStatus toRedirectStatus() { + return RedirectStatus.NO_FORWARD; + } + public abstract ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 8b76933e9e0238..52573e88f9fe26 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -155,6 +155,7 @@ import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand; import org.apache.doris.nereids.trees.plans.commands.Forward; import org.apache.doris.nereids.trees.plans.commands.PrepareCommand; +import org.apache.doris.nereids.trees.plans.commands.Redirect; 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; @@ -719,8 +720,8 @@ private void executeByNereids(TUniqueId queryId) throws Exception { } } if (logicalPlan instanceof Command) { - if (logicalPlan instanceof Forward) { - redirectStatus = ((Forward) logicalPlan).toRedirectStatus(); + if (logicalPlan instanceof Redirect) { + redirectStatus = ((Redirect) logicalPlan).toRedirectStatus(); if (isForwardToMaster()) { // before forward to master, we also need to set profileType in this node if (logicalPlan instanceof InsertIntoTableCommand) {