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,6 +20,8 @@
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalCatalogRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.util.Utils;

Expand All @@ -33,11 +35,17 @@ public class LogicalSubQueryAliasToLogicalProject extends OneRewriteRuleFactory
@Override
public Rule build() {
return RuleType.LOGICAL_SUB_QUERY_ALIAS_TO_LOGICAL_PROJECT.build(
logicalSubQueryAlias().then(subQueryAlias ->
new LogicalProject<>(
Utils.fastToImmutableList(subQueryAlias.getOutput()), subQueryAlias.child()
)
)
);
logicalSubQueryAlias().then(subQueryAlias -> {
Plan child = subQueryAlias.child();
String alias = subQueryAlias.getAlias();

// If child is a LogicalCatalogRelation, set the tableAlias
if (child instanceof LogicalCatalogRelation) {
child = ((LogicalCatalogRelation) child).withTableAlias(alias);
}

return new LogicalProject<>(
Utils.fastToImmutableList(subQueryAlias.getOutput()), child);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
public class LogicalEsScanToPhysicalEsScan extends OneImplementationRuleFactory {
@Override
public Rule build() {
return logicalEsScan().then(esScan ->
new PhysicalEsScan(
return logicalEsScan().then(esScan -> new PhysicalEsScan(
esScan.getRelationId(),
esScan.getTable(),
esScan.getQualifier(),
DistributionSpecAny.INSTANCE,
Optional.empty(),
esScan.getLogicalProperties())
).toRule(RuleType.LOGICAL_ES_SCAN_TO_PHYSICAL_ES_SCAN_RULE);
esScan.getLogicalProperties(),
null,
null,
esScan.getTableAlias())).toRule(RuleType.LOGICAL_ES_SCAN_TO_PHYSICAL_ES_SCAN_RULE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
public class LogicalJdbcScanToPhysicalJdbcScan extends OneImplementationRuleFactory {
@Override
public Rule build() {
return logicalJdbcScan().then(jdbcScan ->
new PhysicalJdbcScan(
return logicalJdbcScan().then(jdbcScan -> new PhysicalJdbcScan(
jdbcScan.getRelationId(),
jdbcScan.getTable(),
jdbcScan.getQualifier(),
Optional.empty(),
jdbcScan.getLogicalProperties())
).toRule(RuleType.LOGICAL_JDBC_SCAN_TO_PHYSICAL_JDBC_SCAN_RULE);
jdbcScan.getLogicalProperties(),
null,
null,
jdbcScan.getOperativeSlots(),
jdbcScan.getTableAlias())).toRule(RuleType.LOGICAL_JDBC_SCAN_TO_PHYSICAL_JDBC_SCAN_RULE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
public class LogicalOdbcScanToPhysicalOdbcScan extends OneImplementationRuleFactory {
@Override
public Rule build() {
return logicalOdbcScan().then(odbcScan ->
new PhysicalOdbcScan(
return logicalOdbcScan().then(odbcScan -> new PhysicalOdbcScan(
odbcScan.getRelationId(),
odbcScan.getTable(),
odbcScan.getQualifier(),
Optional.empty(),
odbcScan.getLogicalProperties())
).toRule(RuleType.LOGICAL_ODBC_SCAN_TO_PHYSICAL_ODBC_SCAN_RULE);
odbcScan.getLogicalProperties(),
null,
null,
odbcScan.getOperativeSlots(),
odbcScan.getTableAlias())).toRule(RuleType.LOGICAL_ODBC_SCAN_TO_PHYSICAL_ODBC_SCAN_RULE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ public Rule build() {
olapScan.getOutputByIndex(olapScan.getTable().getBaseIndexId()),
Optional.empty(),
olapScan.getLogicalProperties(),
null,
null,
olapScan.getTableSample(),
olapScan.getOperativeSlots(),
olapScan.getVirtualColumns(),
olapScan.getScoreOrderKeys(),
olapScan.getScoreLimit(),
olapScan.getAnnOrderKeys(),
olapScan.getAnnLimit())
olapScan.getAnnLimit(),
olapScan.getTableAlias())
).toRule(RuleType.LOGICAL_OLAP_SCAN_TO_PHYSICAL_OLAP_SCAN_RULE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,54 @@ public abstract class LogicalCatalogRelation extends LogicalRelation implements
// use for virtual slot
protected final List<NamedExpression> virtualColumns;

/**
* Table alias for this relation, empty string if no alias.
*/
protected final String tableAlias;

public LogicalCatalogRelation(RelationId relationId, PlanType type, TableIf table, List<String> qualifier) {
this(relationId, type, table, qualifier, Optional.empty(), Optional.empty());
this(relationId, type, table, qualifier, Optional.empty(), Optional.empty(), "");
}

public LogicalCatalogRelation(RelationId relationId, PlanType type, TableIf table, List<String> qualifier,
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties) {
this(relationId, type, table, qualifier, ImmutableList.of(), ImmutableList.of(),
groupExpression, logicalProperties);
groupExpression, logicalProperties, "");
}

public LogicalCatalogRelation(RelationId relationId, PlanType type, TableIf table, List<String> qualifier,
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties,
String tableAlias) {
this(relationId, type, table, qualifier, ImmutableList.of(), ImmutableList.of(),
groupExpression, logicalProperties, tableAlias);
}

/**
* Constructs a LogicalCatalogRelation with specified parameters.
*
* @param relationId Unique identifier for this relation
* @param type Plan type
* @param table Table object associated with this relation
* @param qualifier List of qualifiers, typically [catalogName, databaseName]
* @param operativeSlots Collection of operative slots
* @param virtualColumns List of virtual columns
* @param groupExpression Optional group expression
* @param relationId Unique identifier for this relation
* @param type Plan type
* @param table Table object associated with this relation
* @param qualifier List of qualifiers, typically [catalogName,
* databaseName]
* @param operativeSlots Collection of operative slots
* @param virtualColumns List of virtual columns
* @param groupExpression Optional group expression
* @param logicalProperties Optional logical properties
* @param tableAlias Table alias for this relation, empty string if no
* alias
*/
public LogicalCatalogRelation(RelationId relationId, PlanType type, TableIf table, List<String> qualifier,
Collection<Slot> operativeSlots, List<NamedExpression> virtualColumns,
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties) {
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties,
String tableAlias) {
super(relationId, type, groupExpression, logicalProperties);
this.table = Objects.requireNonNull(table, "table can not be null");
this.qualifier = Utils.fastToImmutableList(Objects.requireNonNull(qualifier, "qualifier can not be null"));
this.operativeSlots = Utils.fastToImmutableList(operativeSlots);
this.virtualColumns = Utils.fastToImmutableList(Objects.requireNonNull(virtualColumns,
"virtualColumns can not be null"));
this.tableAlias = Objects.requireNonNull(tableAlias, "tableAlias can not be null");
}

@Override
Expand Down Expand Up @@ -173,6 +190,10 @@ public List<NamedExpression> getVirtualColumns() {
return virtualColumns;
}

public String getTableAlias() {
return tableAlias;
}

@Override
public void computeUnique(DataTrait.Builder builder) {
Set<Slot> outputSet = Utils.fastToImmutableSet(getOutputSet());
Expand Down Expand Up @@ -252,6 +273,14 @@ public LogicalCatalogRelation withVirtualColumns(List<NamedExpression> virtualCo

public abstract LogicalCatalogRelation withRelationId(RelationId relationId);

/**
* Return a new LogicalCatalogRelation with the specified table alias.
*
* @param tableAlias the table alias to set
* @return a new LogicalCatalogRelation with the specified table alias
*/
public abstract LogicalCatalogRelation withTableAlias(String tableAlias);

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public LogicalDeferMaterializeOlapScan(LogicalOlapScan logicalOlapScan,
Set<ExprId> deferMaterializeSlotIds, SlotReference columnIdSlot,
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties) {
super(logicalOlapScan.getRelationId(), logicalOlapScan.getType(), logicalOlapScan.getTable(),
logicalOlapScan.getQualifier(), groupExpression, logicalProperties);
logicalOlapScan.getQualifier(), groupExpression, logicalProperties, logicalOlapScan.getTableAlias());
this.logicalOlapScan = Objects.requireNonNull(logicalOlapScan, "logicalOlapScan can not be null");
this.deferMaterializeSlotIds = ImmutableSet.copyOf(Objects.requireNonNull(deferMaterializeSlotIds,
"deferMaterializeSlotIds can not be null"));
Expand Down Expand Up @@ -136,6 +136,14 @@ public LogicalDeferMaterializeOlapScan withRelationId(RelationId relationId) {
throw new RuntimeException("should not call LogicalDeferMaterializeOlapScan's withRelationId method");
}

@Override
public LogicalDeferMaterializeOlapScan withTableAlias(String tableAlias) {
// Update the wrapped LogicalOlapScan with the new alias
LogicalOlapScan newOlapScan = logicalOlapScan.withTableAlias(tableAlias);
return new LogicalDeferMaterializeOlapScan(newOlapScan, deferMaterializeSlotIds, columnIdSlot,
Optional.empty(), Optional.of(getLogicalProperties()));
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitLogicalDeferMaterializeOlapScan(this, context);
Expand Down Expand Up @@ -167,9 +175,9 @@ public int hashCode() {
public String toString() {
return Utils.toSqlStringSkipNull("LogicalDeferMaterializeOlapScan[" + id.asInt() + "]",
"olapScan", logicalOlapScan,
"alias", tableAlias,
"deferMaterializeSlotIds", deferMaterializeSlotIds,
"columnIdSlot", columnIdSlot,
"stats", statistics
);
"stats", statistics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,60 @@ public class LogicalEsScan extends LogicalCatalogRelation {
* Constructor for LogicalEsScan.
*/
public LogicalEsScan(RelationId id, TableIf table, List<String> qualifier,
List<NamedExpression> virtualColumns,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
List<NamedExpression> virtualColumns,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties, String tableAlias) {
super(id, PlanType.LOGICAL_ES_SCAN, table, qualifier,
ImmutableList.of(), virtualColumns, groupExpression, logicalProperties);
ImmutableList.of(), virtualColumns, groupExpression, logicalProperties, tableAlias);
}

public LogicalEsScan(RelationId id, TableIf table, List<String> qualifier,
List<NamedExpression> virtualColumns,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
this(id, table, qualifier, virtualColumns, groupExpression, logicalProperties, "");
}

public LogicalEsScan(RelationId id, TableIf table, List<String> qualifier) {
this(id, table, qualifier, ImmutableList.of(), Optional.empty(), Optional.empty());
this(id, table, qualifier, ImmutableList.of(), Optional.empty(), Optional.empty(), "");
}

@Override
public String toString() {
return Utils.toSqlStringSkipNull("LogicalEsScan",
"qualified", qualifiedName(),
"output", getOutput(), "stats", statistics
);
"qualified", qualifiedName(),
"alias", tableAlias,
"output", getOutput(), "stats", statistics);
}

@Override
public LogicalEsScan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new LogicalEsScan(relationId, table, qualifier, virtualColumns,
groupExpression, Optional.of(getLogicalProperties()));
groupExpression, Optional.of(getLogicalProperties()), tableAlias);
}

@Override
public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties, List<Plan> children) {
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, groupExpression, logicalProperties);
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, groupExpression, logicalProperties,
tableAlias);
}

@Override
public LogicalEsScan withRelationId(RelationId relationId) {
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, Optional.empty(), Optional.empty());
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, Optional.empty(), Optional.empty(),
tableAlias);
}

@Override
public LogicalEsScan withVirtualColumns(List<NamedExpression> virtualColumns) {
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, Optional.empty(), Optional.empty());
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, Optional.empty(), Optional.empty(),
tableAlias);
}

public LogicalEsScan withTableAlias(String tableAlias) {
return new LogicalEsScan(relationId, table, qualifier, virtualColumns, Optional.empty(),
Optional.of(getLogicalProperties()), tableAlias);
}

@Override
Expand Down
Loading
Loading