[fix](nereids) remove unnecessary project above scan node (#18920)
1. remove unnecessary project node above scan node. 2. fix in subquery may be recognized as scalar subquery bug 3. fix some Quantile related functions' return type bug
This commit is contained in:
@ -1454,24 +1454,44 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla
|
||||
tableFunctionNode.setOutputSlotIds(Lists.newArrayList(requiredSlotIdSet));
|
||||
}
|
||||
|
||||
TupleDescriptor tupleDescriptor = generateTupleDesc(slotList, null, context);
|
||||
inputPlanNode.setProjectList(execExprList);
|
||||
inputPlanNode.setOutputTupleDesc(tupleDescriptor);
|
||||
// TODO: this is a temporary scheme to support two phase read when has project.
|
||||
// we need to refactor all topn opt into rbo stage.
|
||||
if (inputPlanNode instanceof OlapScanNode) {
|
||||
ArrayList<SlotDescriptor> slots = context.getTupleDesc(inputPlanNode.getTupleIds().get(0)).getSlots();
|
||||
SlotDescriptor lastSlot = slots.get(slots.size() - 1);
|
||||
if (lastSlot.getColumn() != null && lastSlot.getColumn().getName().equals(Column.ROWID_COL)) {
|
||||
inputPlanNode.getProjectList().add(new SlotRef(lastSlot));
|
||||
injectRowIdColumnSlot(tupleDescriptor);
|
||||
requiredSlotIdSet.add(lastSlot.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (inputPlanNode instanceof ScanNode) {
|
||||
updateChildSlotsMaterialization(inputPlanNode, requiredSlotIdSet, requiredByProjectSlotIdSet, context);
|
||||
return inputFragment;
|
||||
TupleDescriptor tupleDescriptor = null;
|
||||
if (requiredByProjectSlotIdSet.size() != requiredSlotIdSet.size()
|
||||
|| execExprList.stream().collect(Collectors.toSet()).size() != execExprList.size()
|
||||
|| execExprList.stream().anyMatch(expr -> !(expr instanceof SlotRef))) {
|
||||
tupleDescriptor = generateTupleDesc(slotList, null, context);
|
||||
inputPlanNode.setProjectList(execExprList);
|
||||
inputPlanNode.setOutputTupleDesc(tupleDescriptor);
|
||||
} else {
|
||||
for (int i = 0; i < slotList.size(); ++i) {
|
||||
context.addExprIdSlotRefPair(slotList.get(i).getExprId(),
|
||||
(SlotRef) execExprList.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this is a temporary scheme to support two phase read when has project.
|
||||
// we need to refactor all topn opt into rbo stage.
|
||||
if (inputPlanNode instanceof OlapScanNode) {
|
||||
ArrayList<SlotDescriptor> slots =
|
||||
context.getTupleDesc(inputPlanNode.getTupleIds().get(0)).getSlots();
|
||||
SlotDescriptor lastSlot = slots.get(slots.size() - 1);
|
||||
if (lastSlot.getColumn() != null
|
||||
&& lastSlot.getColumn().getName().equals(Column.ROWID_COL)) {
|
||||
if (tupleDescriptor != null) {
|
||||
injectRowIdColumnSlot(tupleDescriptor);
|
||||
SlotRef slotRef = new SlotRef(lastSlot);
|
||||
inputPlanNode.getProjectList().add(slotRef);
|
||||
requiredByProjectSlotIdSet.add(lastSlot.getId());
|
||||
}
|
||||
requiredSlotIdSet.add(lastSlot.getId());
|
||||
}
|
||||
}
|
||||
updateChildSlotsMaterialization(inputPlanNode, requiredSlotIdSet,
|
||||
requiredByProjectSlotIdSet, context);
|
||||
} else {
|
||||
TupleDescriptor tupleDescriptor = generateTupleDesc(slotList, null, context);
|
||||
inputPlanNode.setProjectList(execExprList);
|
||||
inputPlanNode.setOutputTupleDesc(tupleDescriptor);
|
||||
}
|
||||
return inputFragment;
|
||||
}
|
||||
|
||||
@ -20,8 +20,8 @@ package org.apache.doris.nereids.trees.expressions.functions.agg;
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DataType;
|
||||
@ -36,7 +36,7 @@ import java.util.List;
|
||||
* AggregateFunction 'quantile_union'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
public class QuantileUnion extends AggregateFunction
|
||||
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable {
|
||||
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
|
||||
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(QuantileStateType.INSTANCE).args(QuantileStateType.INSTANCE)
|
||||
|
||||
@ -19,8 +19,8 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar;
|
||||
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DoubleType;
|
||||
@ -36,7 +36,7 @@ import java.util.List;
|
||||
* ScalarFunction 'quantile_percent'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
public class QuantilePercent extends ScalarFunction
|
||||
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullable {
|
||||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
|
||||
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(DoubleType.INSTANCE).args(QuantileStateType.INSTANCE, FloatType.INSTANCE)
|
||||
|
||||
@ -20,8 +20,8 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar;
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.FloatType;
|
||||
@ -37,7 +37,7 @@ import java.util.List;
|
||||
* ScalarFunction 'to_quantile_state'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
public class ToQuantileState extends ScalarFunction
|
||||
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullable {
|
||||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
|
||||
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(QuantileStateType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT, FloatType.INSTANCE)
|
||||
|
||||
Reference in New Issue
Block a user