[Fix](Nereids) fix except and intersect error for statsCalculator (#15557)
When calculating the statsCalculator of except and intersect, the slotId of the corresponding column was not replaced with the slotId of output, resulting in NPE.
This commit is contained in:
@ -220,7 +220,7 @@ public class StatsCalculator extends DefaultPlanVisitor<StatsDeriveResult, Void>
|
||||
@Override
|
||||
public StatsDeriveResult visitLogicalExcept(
|
||||
LogicalExcept except, Void context) {
|
||||
return computeExcept();
|
||||
return computeExcept(except);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -339,7 +339,7 @@ public class StatsCalculator extends DefaultPlanVisitor<StatsDeriveResult, Void>
|
||||
|
||||
@Override
|
||||
public StatsDeriveResult visitPhysicalExcept(PhysicalExcept except, Void context) {
|
||||
return computeExcept();
|
||||
return computeExcept(except);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -564,8 +564,10 @@ public class StatsCalculator extends DefaultPlanVisitor<StatsDeriveResult, Void>
|
||||
: newColumnStatsMap.get(leftSlot.getExprId());
|
||||
}
|
||||
|
||||
private StatsDeriveResult computeExcept() {
|
||||
return groupExpression.childStatistics(0);
|
||||
private StatsDeriveResult computeExcept(SetOperation setOperation) {
|
||||
StatsDeriveResult leftStatsResult = groupExpression.childStatistics(0);
|
||||
return new StatsDeriveResult(leftStatsResult.getRowCount(),
|
||||
replaceExprIdWithCurrentOutput(setOperation, leftStatsResult));
|
||||
}
|
||||
|
||||
private StatsDeriveResult computeIntersect(SetOperation setOperation) {
|
||||
@ -574,8 +576,19 @@ public class StatsCalculator extends DefaultPlanVisitor<StatsDeriveResult, Void>
|
||||
for (int i = 1; i < setOperation.getArity(); ++i) {
|
||||
rowCount = Math.min(rowCount, groupExpression.childStatistics(i).getRowCount());
|
||||
}
|
||||
return new StatsDeriveResult(
|
||||
rowCount, leftStatsResult.getSlotIdToColumnStats());
|
||||
return new StatsDeriveResult(rowCount, replaceExprIdWithCurrentOutput(setOperation, leftStatsResult));
|
||||
}
|
||||
|
||||
private Map<Id, ColumnStatistic> replaceExprIdWithCurrentOutput(
|
||||
SetOperation setOperation, StatsDeriveResult leftStatsResult) {
|
||||
Map<Id, ColumnStatistic> newColumnStatsMap = new HashMap<>();
|
||||
for (int i = 0; i < setOperation.getOutputs().size(); i++) {
|
||||
NamedExpression namedExpression = setOperation.getOutputs().get(i);
|
||||
Slot childSlot = setOperation.getChildOutput(0).get(i);
|
||||
newColumnStatsMap.put(namedExpression.getExprId(),
|
||||
leftStatsResult.getSlotIdToColumnStats().get(childSlot.getExprId()));
|
||||
}
|
||||
return newColumnStatsMap;
|
||||
}
|
||||
|
||||
private StatsDeriveResult computeGenerate(Generate generate) {
|
||||
|
||||
@ -464,3 +464,16 @@ hell0
|
||||
3
|
||||
3
|
||||
3
|
||||
|
||||
-- !union40 --
|
||||
1
|
||||
2
|
||||
|
||||
-- !union41 --
|
||||
1
|
||||
2
|
||||
|
||||
-- !union42 --
|
||||
1
|
||||
2
|
||||
|
||||
|
||||
@ -214,4 +214,32 @@ suite("test_nereids_set_operation") {
|
||||
}
|
||||
}
|
||||
qt_union39 """(select k1 from setOperationTable order by k1) union all (select k1 from setOperationTableNotNullable order by k1) order by k1;"""
|
||||
|
||||
qt_union40 """
|
||||
SELECT k1 FROM setOperationTable WHERE k2 = 2
|
||||
INTERSECT
|
||||
SELECT k1 FROM setOperationTable WHERE k1 = 1
|
||||
UNION
|
||||
SELECT k1 FROM setOperationTable WHERE k3 = 2
|
||||
"""
|
||||
|
||||
qt_union41 """
|
||||
SELECT k1 FROM setOperationTable WHERE k2 = 1
|
||||
EXCEPT
|
||||
SELECT k1 FROM setOperationTable WHERE k3 = 2
|
||||
UNION
|
||||
(SELECT k1 FROM setOperationTable WHERE k3 = 2
|
||||
INTERSECT
|
||||
SELECT k1 FROM setOperationTable WHERE k2 > 0)
|
||||
"""
|
||||
|
||||
qt_union42 """
|
||||
SELECT k1 FROM setOperationTable WHERE k2 = 1
|
||||
EXCEPT
|
||||
SELECT k1 FROM setOperationTable WHERE k3 = 2
|
||||
UNION ALL
|
||||
(SELECT k1 FROM setOperationTable WHERE k3 = 2
|
||||
INTERSECT
|
||||
SELECT k1 FROM setOperationTable WHERE k2 > 0)
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user