Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.apache.doris.analysis;

import org.apache.doris.catalog.RecursiveCteTempTable;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.IdGenerator;
import org.apache.doris.thrift.TDescriptorTable;
Expand Down Expand Up @@ -101,10 +100,6 @@ public TDescriptorTable toThrift() {
}

for (TableIf tbl : referencedTbls.values()) {
if (tbl instanceof RecursiveCteTempTable) {
// skip recursive cte temp table
continue;
}
result.addToTableDescriptors(tbl.toThrift());
}
thriftDescTable = result;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ enum TableType {
HUDI, JDBC,
TABLE_VALUED_FUNCTION, HMS_EXTERNAL_TABLE, ES_EXTERNAL_TABLE, MATERIALIZED_VIEW, JDBC_EXTERNAL_TABLE,
ICEBERG_EXTERNAL_TABLE, TEST_EXTERNAL_TABLE, PAIMON_EXTERNAL_TABLE, MAX_COMPUTE_EXTERNAL_TABLE,
HUDI_EXTERNAL_TABLE, TRINO_CONNECTOR_EXTERNAL_TABLE, LAKESOUl_EXTERNAL_TABLE, DICTIONARY, DORIS_EXTERNAL_TABLE,
RECURSIVE_CTE_TEMP_TABLE;
HUDI_EXTERNAL_TABLE, TRINO_CONNECTOR_EXTERNAL_TABLE, LAKESOUl_EXTERNAL_TABLE, DICTIONARY, DORIS_EXTERNAL_TABLE;

public String toEngineName() {
switch (this) {
Expand Down Expand Up @@ -494,8 +493,6 @@ public String toEngineName() {
return "dictionary";
case DORIS_EXTERNAL_TABLE:
return "External_Doris";
case RECURSIVE_CTE_TEMP_TABLE:
return "RecursiveCteTempTable";
default:
return null;
}
Expand Down Expand Up @@ -535,7 +532,6 @@ public String toMysqlType() {
case MATERIALIZED_VIEW:
case TRINO_CONNECTOR_EXTERNAL_TABLE:
case DORIS_EXTERNAL_TABLE:
case RECURSIVE_CTE_TEMP_TABLE:
return "BASE TABLE";
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.CTEId;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
import org.apache.doris.qe.GlobalVariable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
Expand All @@ -38,14 +41,15 @@ public class CTEContext {

private final CTEId cteId;
private final String name;
private List<Slot> recursiveCteOutputs;
// this cache only use once
private LogicalPlan analyzedPlan;

private final Map<String, CTEContext> cteContextMap;

/* build head CTEContext */
public CTEContext() {
this(CTEId.DEFAULT, null, null);
this(CTEId.DEFAULT, null, (CTEContext) null);
}

/**
Expand All @@ -66,6 +70,26 @@ public CTEContext(CTEId cteId, @Nullable LogicalSubQueryAlias<Plan> parsedPlan,
// if inner name same with outer name, use inner name in this scope.
.buildKeepingLast();
this.cteId = cteId;
this.recursiveCteOutputs = ImmutableList.of();
}

/**
* CTEContext for recursive cte
*/
public CTEContext(CTEId cteId, String cteName, List<Slot> recursiveCteOutputs) {
this.cteId = cteId;
this.name = GlobalVariable.lowerCaseTableNames != 0 ? cteName.toLowerCase(Locale.ROOT) : cteName;
this.recursiveCteOutputs = recursiveCteOutputs != null ? ImmutableList.copyOf(recursiveCteOutputs)
: ImmutableList.of();
this.cteContextMap = ImmutableMap.of(name, this);
}

public void setRecursiveCteOutputs(List<Slot> recursiveCteOutputs) {
this.recursiveCteOutputs = recursiveCteOutputs;
}

public List<Slot> getRecursiveCteOutputs() {
return recursiveCteOutputs;
}

public void setAnalyzedPlan(LogicalPlan analyzedPlan) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public class CascadesContext implements ScheduleContext {
private final boolean isEnableExprTrace;

private int groupExpressionCount = 0;
private Optional<String> currentRecursiveCteName;
private List<Slot> recursiveCteOutputs;
private Optional<CTEContext> recursiveCteContext;

/**
* Constructor of OptimizerContext.
Expand All @@ -145,7 +144,7 @@ public class CascadesContext implements ScheduleContext {
private CascadesContext(Optional<CascadesContext> parent, Optional<CTEId> currentTree,
StatementContext statementContext, Plan plan, Memo memo,
CTEContext cteContext, PhysicalProperties requireProperties, boolean isLeadingDisableJoinReorder,
Optional<String> currentRecursiveCteName, List<Slot> recursiveCteOutputs) {
CTEContext recursiveCteContext) {
this.parent = Objects.requireNonNull(parent, "parent should not null");
this.currentTree = Objects.requireNonNull(currentTree, "currentTree should not null");
this.statementContext = Objects.requireNonNull(statementContext, "statementContext should not null");
Expand All @@ -170,8 +169,7 @@ private CascadesContext(Optional<CascadesContext> parent, Optional<CTEId> curren
this.isEnableExprTrace = false;
}
this.isLeadingDisableJoinReorder = isLeadingDisableJoinReorder;
this.currentRecursiveCteName = currentRecursiveCteName;
this.recursiveCteOutputs = recursiveCteOutputs;
this.recursiveCteContext = Optional.ofNullable(recursiveCteContext);
}

/** init a temporary context to rewrite expression */
Expand All @@ -186,7 +184,7 @@ public static CascadesContext initTempContext() {
}
return newContext(Optional.empty(), Optional.empty(),
statementContext, DUMMY_PLAN,
new CTEContext(), PhysicalProperties.ANY, false, Optional.empty(), ImmutableList.of());
new CTEContext(), PhysicalProperties.ANY, false, null);
}

/**
Expand All @@ -195,25 +193,23 @@ public static CascadesContext initTempContext() {
public static CascadesContext initContext(StatementContext statementContext,
Plan initPlan, PhysicalProperties requireProperties) {
return newContext(Optional.empty(), Optional.empty(), statementContext,
initPlan, new CTEContext(), requireProperties, false, Optional.empty(), ImmutableList.of());
initPlan, new CTEContext(), requireProperties, false, null);
}

/**
* use for analyze cte. we must pass CteContext from outer since we need to get right scope of cte
*/
public static CascadesContext newContextWithCteContext(CascadesContext cascadesContext,
Plan initPlan, CTEContext cteContext, Optional<String> currentRecursiveCteName,
List<Slot> recursiveCteOutputs) {
Plan initPlan, CTEContext cteContext, CTEContext recursiveCteContext) {
return newContext(Optional.of(cascadesContext), Optional.empty(),
cascadesContext.getStatementContext(), initPlan, cteContext, PhysicalProperties.ANY,
cascadesContext.isLeadingDisableJoinReorder, currentRecursiveCteName, recursiveCteOutputs);
cascadesContext.isLeadingDisableJoinReorder, recursiveCteContext);
}

public static CascadesContext newCurrentTreeContext(CascadesContext context) {
return CascadesContext.newContext(context.getParent(), context.getCurrentTree(), context.getStatementContext(),
context.getRewritePlan(), context.getCteContext(),
context.getCurrentJobContext().getRequiredProperties(), context.isLeadingDisableJoinReorder,
Optional.empty(), ImmutableList.of());
context.getCurrentJobContext().getRequiredProperties(), context.isLeadingDisableJoinReorder, null);
}

/**
Expand All @@ -222,17 +218,15 @@ public static CascadesContext newCurrentTreeContext(CascadesContext context) {
public static CascadesContext newSubtreeContext(Optional<CTEId> subtree, CascadesContext context,
Plan plan, PhysicalProperties requireProperties) {
return CascadesContext.newContext(Optional.of(context), subtree, context.getStatementContext(),
plan, context.getCteContext(), requireProperties, context.isLeadingDisableJoinReorder, Optional.empty(),
ImmutableList.of());
plan, context.getCteContext(), requireProperties, context.isLeadingDisableJoinReorder, null);
}

private static CascadesContext newContext(Optional<CascadesContext> parent, Optional<CTEId> subtree,
StatementContext statementContext, Plan initPlan, CTEContext cteContext,
PhysicalProperties requireProperties, boolean isLeadingDisableJoinReorder,
Optional<String> currentRecursiveCteName, List<Slot> recursiveCteOutputs) {
CTEContext recursiveCteContext) {
return new CascadesContext(parent, subtree, statementContext, initPlan, null,
cteContext, requireProperties, isLeadingDisableJoinReorder, currentRecursiveCteName,
recursiveCteOutputs);
cteContext, requireProperties, isLeadingDisableJoinReorder, recursiveCteContext);
}

public CascadesContext getRoot() {
Expand All @@ -259,16 +253,17 @@ public synchronized boolean isTimeout() {
return isTimeout;
}

public Optional<String> getCurrentRecursiveCteName() {
return currentRecursiveCteName;
public Optional<CTEContext> getRecursiveCteContext() {
return recursiveCteContext;
}

public List<Slot> getRecursiveCteOutputs() {
return recursiveCteOutputs;
return recursiveCteContext.isPresent() ? recursiveCteContext.get().getRecursiveCteOutputs()
: ImmutableList.of();
}

public boolean isAnalyzingRecursiveCteAnchorChild() {
return currentRecursiveCteName.isPresent() && recursiveCteOutputs.isEmpty();
return recursiveCteContext.isPresent() && recursiveCteContext.get().getRecursiveCteOutputs().isEmpty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ public enum TableFrom {
private List<org.apache.iceberg.FileScanTask> icebergRewriteFileScanTasks = null;
private boolean hasNestedColumns;

private final Set<CTEId> mustInlineCTE = new HashSet<>();

public StatementContext() {
this(ConnectContext.get(), null, 0);
}
Expand Down Expand Up @@ -1057,4 +1059,12 @@ public boolean hasNestedColumns() {
public void setHasNestedColumns(boolean hasNestedColumns) {
this.hasNestedColumns = hasNestedColumns;
}

public void addToMustLineCTEs(CTEId cteId) {
mustInlineCTE.add(cteId);
}

public Set<CTEId> getMustInlineCTEs() {
return mustInlineCTE;
}
}
Loading
Loading