[fix](Nereids) explain should fallback too if Nereids is not enable (#28475)
This commit is contained in:
@ -69,6 +69,14 @@ public class BatchInsertIntoTableCommand extends Command implements ForwardWithS
|
||||
|
||||
@Override
|
||||
public Plan getExplainPlan(ConnectContext ctx) throws Exception {
|
||||
if (!ctx.getSessionVariable().isEnableNereidsDML()) {
|
||||
try {
|
||||
ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
|
||||
} catch (Exception e) {
|
||||
throw new AnalysisException("failed to set fallback to original planner to true", e);
|
||||
}
|
||||
throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
|
||||
}
|
||||
return InsertExecutor.normalizePlan(this.logicalQuery, InsertExecutor.getTargetTable(this.logicalQuery, ctx));
|
||||
}
|
||||
|
||||
|
||||
@ -19,9 +19,9 @@ package org.apache.doris.nereids.trees.plans.commands;
|
||||
|
||||
import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.OlapTable;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.nereids.analyzer.UnboundSlot;
|
||||
import org.apache.doris.nereids.analyzer.UnboundTableSink;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
import org.apache.doris.nereids.trees.expressions.NamedExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
|
||||
@ -123,6 +123,14 @@ public class DeleteFromUsingCommand extends Command implements ForwardWithSync,
|
||||
|
||||
@Override
|
||||
public Plan getExplainPlan(ConnectContext ctx) {
|
||||
if (!ctx.getSessionVariable().isEnableNereidsDML()) {
|
||||
try {
|
||||
ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
|
||||
} catch (Exception e) {
|
||||
throw new AnalysisException("failed to set fallback to original planner to true", e);
|
||||
}
|
||||
throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
|
||||
}
|
||||
return completeQueryPlan(ctx, logicalQuery);
|
||||
}
|
||||
|
||||
|
||||
@ -232,6 +232,14 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
|
||||
@Override
|
||||
public Plan getExplainPlan(ConnectContext ctx) {
|
||||
if (!ctx.getSessionVariable().isEnableNereidsDML()) {
|
||||
try {
|
||||
ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
|
||||
} catch (Exception e) {
|
||||
throw new AnalysisException("failed to set fallback to original planner to true", e);
|
||||
}
|
||||
throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
|
||||
}
|
||||
return InsertExecutor.normalizePlan(this.logicalQuery, InsertExecutor.getTargetTable(this.logicalQuery, ctx));
|
||||
}
|
||||
|
||||
|
||||
@ -278,6 +278,14 @@ public class InsertOverwriteTableCommand extends Command implements ForwardWithS
|
||||
|
||||
@Override
|
||||
public Plan getExplainPlan(ConnectContext ctx) {
|
||||
if (!ctx.getSessionVariable().isEnableNereidsDML()) {
|
||||
try {
|
||||
ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
|
||||
} catch (Exception e) {
|
||||
throw new AnalysisException("failed to set fallback to original planner to true", e);
|
||||
}
|
||||
throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
|
||||
}
|
||||
return InsertExecutor.normalizePlan(this.logicalQuery, InsertExecutor.getTargetTable(this.logicalQuery, ctx));
|
||||
}
|
||||
|
||||
|
||||
@ -22,9 +22,9 @@ import org.apache.doris.catalog.KeysType;
|
||||
import org.apache.doris.catalog.OlapTable;
|
||||
import org.apache.doris.catalog.Table;
|
||||
import org.apache.doris.catalog.TableIf;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.nereids.analyzer.UnboundSlot;
|
||||
import org.apache.doris.nereids.analyzer.UnboundTableSink;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.parser.NereidsParser;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
import org.apache.doris.nereids.trees.expressions.EqualTo;
|
||||
@ -43,6 +43,7 @@ import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.qe.SessionVariable;
|
||||
import org.apache.doris.qe.StmtExecutor;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@ -96,7 +97,8 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab
|
||||
/**
|
||||
* add LogicalOlapTableSink node, public for test.
|
||||
*/
|
||||
public LogicalPlan completeQueryPlan(ConnectContext ctx, LogicalPlan logicalQuery) throws AnalysisException {
|
||||
@VisibleForTesting
|
||||
public LogicalPlan completeQueryPlan(ConnectContext ctx, LogicalPlan logicalQuery) {
|
||||
checkTable(ctx);
|
||||
|
||||
Map<String, Expression> colNameToExpression = Maps.newHashMap();
|
||||
@ -141,7 +143,7 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab
|
||||
false, ImmutableList.of(), isPartialUpdate, DMLCommandType.UPDATE, logicalQuery);
|
||||
}
|
||||
|
||||
private void checkTable(ConnectContext ctx) throws AnalysisException {
|
||||
private void checkTable(ConnectContext ctx) {
|
||||
if (ctx.getSessionVariable().isInDebugMode()) {
|
||||
throw new AnalysisException("Update is forbidden since current session is in debug mode."
|
||||
+ " Please check the following session variables: "
|
||||
@ -160,7 +162,15 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plan getExplainPlan(ConnectContext ctx) throws AnalysisException {
|
||||
public Plan getExplainPlan(ConnectContext ctx) {
|
||||
if (!ctx.getSessionVariable().isEnableNereidsDML()) {
|
||||
try {
|
||||
ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
|
||||
} catch (Exception e) {
|
||||
throw new AnalysisException("failed to set fallback to original planner to true", e);
|
||||
}
|
||||
throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
|
||||
}
|
||||
return completeQueryPlan(ctx, logicalQuery);
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.doris.nereids.trees.plans;
|
||||
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.nereids.parser.NereidsParser;
|
||||
import org.apache.doris.nereids.trees.plans.commands.UpdateCommand;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
@ -69,10 +68,10 @@ public class UpdateCommandTest extends TestWithFeService implements PlanPatternM
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleUpdate() throws AnalysisException {
|
||||
public void testSimpleUpdate() {
|
||||
String sql = "update t1 set v1 = v1 + 2, v2 = v1 * 2 where k1 = 3";
|
||||
LogicalPlan parsed = new NereidsParser().parseSingle(sql);
|
||||
Assertions.assertTrue(parsed instanceof UpdateCommand);
|
||||
Assertions.assertInstanceOf(UpdateCommand.class, parsed);
|
||||
UpdateCommand command = ((UpdateCommand) parsed);
|
||||
LogicalPlan plan = command.completeQueryPlan(connectContext, command.getLogicalQuery());
|
||||
PlanChecker.from(connectContext, plan)
|
||||
@ -90,11 +89,11 @@ public class UpdateCommandTest extends TestWithFeService implements PlanPatternM
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromClauseUpdate() throws AnalysisException {
|
||||
public void testFromClauseUpdate() {
|
||||
String sql = "update t1 a set v1 = t2.v1 + 2, v2 = a.v1 * 2 "
|
||||
+ "from src join t2 on src.k1 = t2.k1 where t2.k1 = a.k1";
|
||||
LogicalPlan parsed = new NereidsParser().parseSingle(sql);
|
||||
Assertions.assertTrue(parsed instanceof UpdateCommand);
|
||||
Assertions.assertInstanceOf(UpdateCommand.class, parsed);
|
||||
UpdateCommand command = ((UpdateCommand) parsed);
|
||||
LogicalPlan plan = command.completeQueryPlan(connectContext, command.getLogicalQuery());
|
||||
PlanChecker.from(connectContext, plan)
|
||||
|
||||
Reference in New Issue
Block a user