This is an automated email from the ASF dual-hosted git repository.
jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new a2fd488438 [chore](Nereids): polish StatsCalculatorTest (#22884)
a2fd488438 is described below
commit a2fd4884386fa0eb87aa10dc727e61e14f0845c8
Author: jakevin <[email protected]>
AuthorDate: Fri Aug 11 18:08:18 2023 +0800
[chore](Nereids): polish StatsCalculatorTest (#22884)
---
.../doris/nereids/stats/StatsCalculatorTest.java | 68 ++++++++--------------
1 file changed, 25 insertions(+), 43 deletions(-)
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
index 0fa8a17863..988b55e054 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
@@ -31,7 +31,6 @@ import org.apache.doris.nereids.trees.expressions.Or;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
-import org.apache.doris.nereids.trees.plans.FakePlan;
import org.apache.doris.nereids.trees.plans.GroupPlan;
import org.apache.doris.nereids.trees.plans.LimitPhase;
import org.apache.doris.nereids.trees.plans.Plan;
@@ -41,7 +40,6 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.util.PlanConstructor;
-import org.apache.doris.qe.ConnectContext;
import org.apache.doris.statistics.ColumnStatistic;
import org.apache.doris.statistics.ColumnStatisticBuilder;
import org.apache.doris.statistics.Statistics;
@@ -49,11 +47,9 @@ import org.apache.doris.statistics.Statistics;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
-import mockit.Mocked;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -61,11 +57,12 @@ import java.util.Map;
import java.util.Optional;
public class StatsCalculatorTest {
+ private final LogicalOlapScan scan = PlanConstructor.newLogicalOlapScan(0,
"t1", 0);
- private Group newGroup() {
- GroupExpression groupExpression = new GroupExpression(new FakePlan());
- Group group = new Group(null, groupExpression, null);
- group.getPhysicalExpressions().remove(0);
+ private Group newFakeGroup() {
+ GroupExpression groupExpression = new GroupExpression(scan);
+ Group group = new Group(null, groupExpression, new
LogicalProperties(Collections::emptyList));
+ group.getLogicalExpressions().remove(0);
return group;
}
@@ -138,22 +135,19 @@ public class StatsCalculatorTest {
ImmutableSet and = ImmutableSet.of(eq1, eq2);
ImmutableSet or = ImmutableSet.of(new Or(eq1, eq2));
- Group childGroup = newGroup();
- childGroup.setLogicalProperties(new
LogicalProperties(Collections::emptyList));
+ Group childGroup = newFakeGroup();
GroupPlan groupPlan = new GroupPlan(childGroup);
childGroup.setStatistics(childStats);
LogicalFilter<GroupPlan> logicalFilter = new LogicalFilter<>(and,
groupPlan);
GroupExpression groupExpression = new GroupExpression(logicalFilter,
ImmutableList.of(childGroup));
- Group ownerGroup = newGroup();
- groupExpression.setOwnerGroup(ownerGroup);
+ Group ownerGroup = new Group(null, groupExpression, null);
StatsCalculator.estimate(groupExpression, null);
Assertions.assertEquals((10000 * 0.1 * 0.05),
ownerGroup.getStatistics().getRowCount(), 0.001);
LogicalFilter<GroupPlan> logicalFilterOr = new LogicalFilter<>(or,
groupPlan);
GroupExpression groupExpressionOr = new
GroupExpression(logicalFilterOr, ImmutableList.of(childGroup));
- Group ownerGroupOr = newGroup();
- groupExpressionOr.setOwnerGroup(ownerGroupOr);
+ Group ownerGroupOr = new Group(null, groupExpressionOr, null);
StatsCalculator.estimate(groupExpressionOr, null);
Assertions.assertEquals((long) (10000 * (0.1 + 0.05 - 0.1 * 0.05)),
ownerGroupOr.getStatistics().getRowCount(), 0.001);
@@ -163,9 +157,7 @@ public class StatsCalculatorTest {
// a=200 and b=300 => output: 0 rows
@org.junit.Test
public void testFilterOutofRange() {
- List<String> qualifier = Lists.newArrayList();
- qualifier.add("test");
- qualifier.add("t");
+ List<String> qualifier = ImmutableList.of("test", "t");
SlotReference slot1 = new SlotReference("c1", IntegerType.INSTANCE,
true, qualifier);
SlotReference slot2 = new SlotReference("c2", IntegerType.INSTANCE,
true, qualifier);
@@ -191,21 +183,20 @@ public class StatsCalculatorTest {
ImmutableSet and = ImmutableSet.of(new And(eq1, eq2));
ImmutableSet or = ImmutableSet.of(new Or(eq1, eq2));
- Group childGroup = newGroup();
- childGroup.setLogicalProperties(new
LogicalProperties(Collections::emptyList));
+ Group childGroup = newFakeGroup();
GroupPlan groupPlan = new GroupPlan(childGroup);
childGroup.setStatistics(childStats);
LogicalFilter<GroupPlan> logicalFilter = new LogicalFilter<>(and,
groupPlan);
GroupExpression groupExpression = new GroupExpression(logicalFilter,
ImmutableList.of(childGroup));
- Group ownerGroup = newGroup();
+ Group ownerGroup = new Group(null, groupExpression, null);
groupExpression.setOwnerGroup(ownerGroup);
StatsCalculator.estimate(groupExpression, null);
Assertions.assertEquals(0, ownerGroup.getStatistics().getRowCount(),
0.001);
LogicalFilter<GroupPlan> logicalFilterOr = new LogicalFilter<>(or,
groupPlan);
GroupExpression groupExpressionOr = new
GroupExpression(logicalFilterOr, ImmutableList.of(childGroup));
- Group ownerGroupOr = newGroup();
+ Group ownerGroupOr = new Group(null, groupExpressionOr, null);
groupExpressionOr.setOwnerGroup(ownerGroupOr);
StatsCalculator.estimate(groupExpressionOr, null);
Assertions.assertEquals(0, ownerGroupOr.getStatistics().getRowCount(),
0.001);
@@ -249,20 +240,20 @@ public class StatsCalculatorTest {
// }
@Test
- public void testOlapScan(@Mocked ConnectContext context) {
+ public void testOlapScan() {
long tableId1 = 0;
List<String> qualifier = ImmutableList.of("test", "t");
SlotReference slot1 = new SlotReference(new ExprId(0),
"c1", IntegerType.INSTANCE, true, qualifier, new Column("c1",
PrimitiveType.INT));
OlapTable table1 = PlanConstructor.newOlapTable(tableId1, "t1", 0);
- LogicalOlapScan logicalOlapScan1 = (LogicalOlapScan) new
LogicalOlapScan(StatementScopeIdGenerator.newRelationId(), table1,
+ LogicalOlapScan logicalOlapScan1 = (LogicalOlapScan) new
LogicalOlapScan(
+ StatementScopeIdGenerator.newRelationId(), table1,
Collections.emptyList()).withGroupExprLogicalPropChildren(Optional.empty(),
Optional.of(new LogicalProperties(() ->
ImmutableList.of(slot1))), ImmutableList.of());
- Group childGroup = newGroup();
- GroupExpression groupExpression = new
GroupExpression(logicalOlapScan1, ImmutableList.of(childGroup));
- Group ownerGroup = newGroup();
- groupExpression.setOwnerGroup(ownerGroup);
+
+ GroupExpression groupExpression = new
GroupExpression(logicalOlapScan1, ImmutableList.of());
+ Group ownerGroup = new Group(null, groupExpression, null);
StatsCalculator.estimate(groupExpression, null);
Statistics stats = ownerGroup.getStatistics();
Assertions.assertEquals(1, stats.columnStatistics().size());
@@ -271,9 +262,7 @@ public class StatsCalculatorTest {
@Test
public void testLimit() {
- List<String> qualifier = new ArrayList<>();
- qualifier.add("test");
- qualifier.add("t");
+ List<String> qualifier = ImmutableList.of("test", "t");
SlotReference slot1 = new SlotReference(new ExprId(0),
"c1", IntegerType.INSTANCE, true, qualifier, new Column("c1",
PrimitiveType.INT));
ColumnStatisticBuilder columnStat1 = new ColumnStatisticBuilder();
@@ -283,17 +272,14 @@ public class StatsCalculatorTest {
slotColumnStatsMap.put(slot1, columnStat1.build());
Statistics childStats = new Statistics(10, slotColumnStatsMap);
- Group childGroup = newGroup();
- childGroup.setLogicalProperties(new
LogicalProperties(Collections::emptyList));
+ Group childGroup = newFakeGroup();
GroupPlan groupPlan = new GroupPlan(childGroup);
childGroup.setStatistics(childStats);
LogicalLimit<? extends Plan> logicalLimit = new LogicalLimit<>(1, 2,
- LimitPhase.GLOBAL, new LogicalLimit<>(1, 2, LimitPhase.LOCAL,
groupPlan)
- );
+ LimitPhase.GLOBAL, new LogicalLimit<>(1, 2, LimitPhase.LOCAL,
groupPlan));
GroupExpression groupExpression = new GroupExpression(logicalLimit,
ImmutableList.of(childGroup));
- Group ownerGroup = newGroup();
- ownerGroup.addGroupExpression(groupExpression);
+ Group ownerGroup = new Group(null, groupExpression, null);
StatsCalculator.estimate(groupExpression, null);
Statistics limitStats = ownerGroup.getStatistics();
Assertions.assertEquals(1, limitStats.getRowCount());
@@ -304,9 +290,7 @@ public class StatsCalculatorTest {
@Test
public void testTopN() {
- List<String> qualifier = new ArrayList<>();
- qualifier.add("test");
- qualifier.add("t");
+ List<String> qualifier = ImmutableList.of("test", "t");
SlotReference slot1 = new SlotReference("c1", IntegerType.INSTANCE,
true, qualifier);
ColumnStatisticBuilder columnStat1 = new ColumnStatisticBuilder();
columnStat1.setNdv(10);
@@ -315,15 +299,13 @@ public class StatsCalculatorTest {
slotColumnStatsMap.put(slot1, columnStat1.build());
Statistics childStats = new Statistics(10, slotColumnStatsMap);
- Group childGroup = newGroup();
- childGroup.setLogicalProperties(new
LogicalProperties(Collections::emptyList));
+ Group childGroup = newFakeGroup();
GroupPlan groupPlan = new GroupPlan(childGroup);
childGroup.setStatistics(childStats);
LogicalTopN<GroupPlan> logicalTopN = new
LogicalTopN<>(Collections.emptyList(), 1, 2, groupPlan);
GroupExpression groupExpression = new GroupExpression(logicalTopN,
ImmutableList.of(childGroup));
- Group ownerGroup = newGroup();
- ownerGroup.addGroupExpression(groupExpression);
+ Group ownerGroup = new Group(null, groupExpression, null);
StatsCalculator.estimate(groupExpression, null);
Statistics topNStats = ownerGroup.getStatistics();
Assertions.assertEquals(1, topNStats.getRowCount());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]