Skip to content

Commit

Permalink
[fix](Nereids) explain should fallback too if Nereids is not enable (#…
Browse files Browse the repository at this point in the history
…28475)

pick from master
PR #28475
commit b50bc0d
  • Loading branch information
morrySnow committed Dec 20, 2023
1 parent 8f175f9 commit 536b666
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public LogicalPlan getLogicalQuery() {

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {

@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 this.logicalQuery;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ private void checkTable(ConnectContext ctx) throws AnalysisException {

@Override
public Plan getExplainPlan(ConnectContext ctx) throws AnalysisException {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,26 @@ public void testScalarSubQuery() {
}

@Test
public void testInserInto() {
public void testInsertInto() {
String sql = "INSERT INTO supplier(s_suppkey) SELECT lo_orderkey FROM lineorder";
StatementContext statementContext = MemoTestUtils.createStatementContext(connectContext, sql);
InsertIntoTableCommand insertIntoTableCommand = (InsertIntoTableCommand) parser.parseSingle(sql);
NereidsPlanner planner = new NereidsPlanner(statementContext);
planner.plan(
(LogicalPlan) insertIntoTableCommand.getExplainPlan(connectContext),
PhysicalProperties.ANY
);
CascadesContext cascadesContext = planner.getCascadesContext();
List<TableIf> f = cascadesContext.getTables();
Assertions.assertEquals(2, f.size());
Set<String> tableNames = f.stream().map(TableIf::getName).collect(Collectors.toSet());
Assertions.assertTrue(tableNames.contains("supplier"));
Assertions.assertTrue(tableNames.contains("lineorder"));
boolean originalDML = connectContext.getSessionVariable().enableNereidsDML;
connectContext.getSessionVariable().enableNereidsDML = true;
try {
InsertIntoTableCommand insertIntoTableCommand = (InsertIntoTableCommand) parser.parseSingle(sql);
NereidsPlanner planner = new NereidsPlanner(statementContext);
planner.plan(
(LogicalPlan) insertIntoTableCommand.getExplainPlan(connectContext),
PhysicalProperties.ANY
);
CascadesContext cascadesContext = planner.getCascadesContext();
List<TableIf> f = cascadesContext.getTables();
Assertions.assertEquals(2, f.size());
Set<String> tableNames = f.stream().map(TableIf::getName).collect(Collectors.toSet());
Assertions.assertTrue(tableNames.contains("supplier"));
Assertions.assertTrue(tableNames.contains("lineorder"));
} finally {
connectContext.getSessionVariable().enableNereidsDML = originalDML;
}
}
}

0 comments on commit 536b666

Please sign in to comment.