[feature](Nereids) add relation id to unboundTVFRelation to avoid incorrect group expression comparison (#15740)

This commit is contained in:
mch_ucchi
2023-01-11 12:49:14 +08:00
committed by GitHub
parent af3416ede0
commit 7f2c433e08
6 changed files with 45 additions and 10 deletions

View File

@ -62,6 +62,10 @@ public class UnboundOneRowRelation extends LogicalLeaf implements Unbound, OneRo
this.projects = ImmutableList.copyOf(projects);
}
public RelationId getId() {
return id;
}
@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitUnboundOneRowRelation(this, context);

View File

@ -26,6 +26,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.TVFProperties;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalLeaf;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.nereids.util.Utils;
@ -38,14 +39,16 @@ import java.util.Optional;
public class UnboundTVFRelation extends LogicalLeaf implements Relation, Unbound {
private final String functionName;
private final TVFProperties properties;
private final RelationId id;
public UnboundTVFRelation(String functionName, TVFProperties properties) {
this(functionName, properties, Optional.empty(), Optional.empty());
public UnboundTVFRelation(RelationId id, String functionName, TVFProperties properties) {
this(id, functionName, properties, Optional.empty(), Optional.empty());
}
public UnboundTVFRelation(String functionName, TVFProperties properties,
public UnboundTVFRelation(RelationId id, String functionName, TVFProperties properties,
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties) {
super(PlanType.LOGICAL_UNBOUND_TVF_RELATION, groupExpression, logicalProperties);
this.id = id;
this.functionName = Objects.requireNonNull(functionName, "functionName can not be null");
this.properties = Objects.requireNonNull(properties, "properties can not be null");
}
@ -58,6 +61,10 @@ public class UnboundTVFRelation extends LogicalLeaf implements Relation, Unbound
return properties;
}
public RelationId getId() {
return id;
}
@Override
public LogicalProperties computeLogicalProperties() {
return UnboundLogicalProperties.INSTANCE;
@ -80,12 +87,13 @@ public class UnboundTVFRelation extends LogicalLeaf implements Relation, Unbound
@Override
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new UnboundTVFRelation(functionName, properties, groupExpression, Optional.of(getLogicalProperties()));
return new UnboundTVFRelation(id, functionName, properties, groupExpression,
Optional.of(getLogicalProperties()));
}
@Override
public Plan withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
return new UnboundTVFRelation(functionName, properties, Optional.empty(), logicalProperties);
return new UnboundTVFRelation(id, functionName, properties, Optional.empty(), logicalProperties);
}
@Override

View File

@ -479,7 +479,8 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
String value = parseTVFPropertyItem(argument.value);
map.put(key, value);
}
LogicalPlan relation = new UnboundTVFRelation(functionName, new TVFProperties(map.build()));
LogicalPlan relation = new UnboundTVFRelation(RelationUtil.newRelationId(),
functionName, new TVFProperties(map.build()));
return withTableAlias(relation, ctx.tableAlias());
});
}

View File

@ -41,7 +41,6 @@ import org.apache.doris.nereids.trees.expressions.functions.generator.TableGener
import org.apache.doris.nereids.trees.expressions.functions.table.TableValuedFunction;
import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
import org.apache.doris.nereids.trees.plans.GroupPlan;
import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalHaving;
@ -206,9 +205,7 @@ public class BindFunction implements AnalysisRuleFactory {
if (!(function instanceof TableValuedFunction)) {
throw new AnalysisException(function.toSql() + " is not a TableValuedFunction");
}
RelationId relationId = statementContext.getNextRelationId();
return new LogicalTVFRelation(relationId, (TableValuedFunction) function);
return new LogicalTVFRelation(unboundTVFRelation.getId(), (TableValuedFunction) function);
}
/**