Skip to content

Commit

Permalink
[refactor](nereids)make Forward/NoForward extends Redirect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 committed Nov 12, 2024
1 parent c2ac2cb commit 19a464a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -716,8 +717,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) {
Expand Down

0 comments on commit 19a464a

Please sign in to comment.