diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java index 061f13c25c..305bb97d87 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java @@ -146,10 +146,10 @@ public class CostAndEnforcerJob extends Job implements Cloneable { GroupExpression lowestCostExpr = lowestCostPlanOpt.get().second; - PhysicalProperties childOutputProperty = lowestCostExpr.getPropertyFromMap(requestChildProperty); - // add childOutputProperty of children into childrenOutputProperty - childrenOutputProperty.add(childOutputProperty); - requestChildrenProperty.set(curChildIndex, childOutputProperty); + PhysicalProperties outputProperties = lowestCostExpr.getOutputProperties(requestChildProperty); + // add outputProperties of children into childrenOutputProperty + childrenOutputProperty.add(outputProperties); + requestChildrenProperty.set(curChildIndex, outputProperties); curTotalCost += lowestCostExpr.getLowestCostTable().get(requestChildProperty).first; if (curTotalCost > context.getCostUpperBound()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java index 0258412e68..51d7f7c07c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java @@ -67,11 +67,11 @@ public class RewriteTopDownJob extends Job { List validRules = getValidRules(logicalExpression, rules); for (Rule rule : validRules) { Preconditions.checkArgument(rule.isRewrite(), - "in top down job, rules must be rewritable"); + "rules must be rewritable in top down job"); GroupExpressionMatching groupExpressionMatching = new GroupExpressionMatching(rule.getPattern(), logicalExpression); - //In topdown job, there must be only one matching plan. - //This `for` loop runs at most once. + // In topdown job, there must be only one matching plan. + // This `for` loop runs at most once. for (Plan before : groupExpressionMatching) { List afters = rule.transform(before, context.getPlannerContext()); Preconditions.checkArgument(afters.size() == 1); @@ -80,8 +80,8 @@ public class RewriteTopDownJob extends Job { Pair pair = context.getPlannerContext() .getMemo().copyIn(after, group, rule.isRewrite()); if (pair.first) { - //new group-expr replaced the origin group-expr in `group`, - //run this rule against this `group` again. + // new group-expr replaced the origin group-expr in `group`, + // run this rule against this `group` again. pushTask(new RewriteTopDownJob(group, rules, context)); return; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java index f58baa7dba..716bbc1ef0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java @@ -69,11 +69,10 @@ public class GroupExpression { this.requestPropertiesMap = Maps.newHashMap(); } - // TODO: rename - public PhysicalProperties getPropertyFromMap(PhysicalProperties requiredPropertySet) { - PhysicalProperties outputProperty = requestPropertiesMap.get(requiredPropertySet); - Preconditions.checkState(outputProperty != null); - return outputProperty; + public PhysicalProperties getOutputProperties(PhysicalProperties requestProperties) { + PhysicalProperties outputProperties = requestPropertiesMap.get(requestProperties); + Preconditions.checkNotNull(outputProperties); + return outputProperties; } public int arity() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java index 867950446d..5ac4b18410 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java @@ -44,7 +44,7 @@ public class Memo { private final List groups = Lists.newArrayList(); // we could not use Set, because Set does not have get method. private final Map groupExpressions = Maps.newHashMap(); - private Group root; + private final Group root; public Memo(Plan plan) { root = copyIn(plan, null, false).second.getOwnerGroup(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterSelectivityCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterSelectivityCalculator.java index 09c2cd46e5..a307c9097f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterSelectivityCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterSelectivityCalculator.java @@ -42,7 +42,7 @@ public class FilterSelectivityCalculator extends ExpressionVisitor private final Map slotRefToStats; public FilterSelectivityCalculator(Map slotRefToStats) { - Preconditions.checkState(slotRefToStats != null); + Preconditions.checkNotNull(slotRefToStats); this.slotRefToStats = slotRefToStats; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java index 7f64840bbb..a6b7e0e47c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java @@ -184,6 +184,8 @@ public class LogicalJoin>map(ImmutableList::of).orElseGet(ImmutableList::of); } - //TODO: - // 1. consider the order of conjucts in otherJoinCondition - // 2. compare hashJoinConditions + // TODO: + // 1. consider the order of conjucts in otherJoinCondition and hashJoinConditions @Override public boolean equals(Object o) { if (this == o) { @@ -89,17 +88,23 @@ public abstract class AbstractPhysicalJoin< if (o == null || getClass() != o.getClass()) { return false; } - AbstractPhysicalJoin that = (AbstractPhysicalJoin) o; - return joinType == that.joinType && Objects.equals(otherJoinCondition, that.otherJoinCondition); + if (!super.equals(o)) { + return false; + } + AbstractPhysicalJoin that = (AbstractPhysicalJoin) o; + return joinType == that.joinType + && hashJoinConjuncts.equals(that.hashJoinConjuncts) + && otherJoinCondition.equals(that.otherJoinCondition); } @Override public int hashCode() { - return Objects.hash(joinType, otherJoinCondition); + return Objects.hash(super.hashCode(), joinType, hashJoinConjuncts, otherJoinCondition); } /** * hashJoinConjuncts and otherJoinCondition + * * @return the combination of hashJoinConjuncts and otherJoinCondition */ public Optional getOnClauseCondition() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalHashJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalHashJoin.java index 131cd81a0a..a714dac003 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalHashJoin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalHashJoin.java @@ -42,7 +42,7 @@ public class PhysicalHashJoin< public PhysicalHashJoin(JoinType joinType, List hashJoinConjuncts, Optional condition, LogicalProperties logicalProperties, - LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { + LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { this(joinType, hashJoinConjuncts, condition, Optional.empty(), logicalProperties, leftChild, rightChild); } @@ -53,8 +53,8 @@ public class PhysicalHashJoin< * @param condition join condition. */ public PhysicalHashJoin(JoinType joinType, List hashJoinConjuncts, Optional condition, - Optional groupExpression, LogicalProperties logicalProperties, - LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { + Optional groupExpression, LogicalProperties logicalProperties, + LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { super(PlanType.PHYSICAL_HASH_JOIN, joinType, hashJoinConjuncts, condition, groupExpression, logicalProperties, leftChild, rightChild); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java index 5f574d8342..3a03741f98 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java @@ -23,7 +23,7 @@ import org.apache.doris.nereids.properties.DistributionSpecHash; import org.apache.doris.nereids.properties.LogicalProperties; import org.apache.doris.nereids.properties.OrderKey; import org.apache.doris.nereids.trees.expressions.EqualTo; -import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.literal.Literal; @@ -48,144 +48,173 @@ import mockit.Mocked; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.List; import java.util.Optional; -// TODO: need more detailed test public class PlanEqualsTest { /* *************************** Logical *************************** */ @Test public void testLogicalAggregate(@Mocked Plan child) { - List groupByExprList = Lists.newArrayList(); - List outputExpressionList = ImmutableList.of( - new SlotReference("a", new BigIntType(), true, Lists.newArrayList()) - ); + LogicalAggregate actual = new LogicalAggregate<>(Lists.newArrayList(), ImmutableList.of( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + child); - LogicalAggregate one = new LogicalAggregate(groupByExprList, outputExpressionList, child); - Assertions.assertEquals(one, one); + LogicalAggregate expected = new LogicalAggregate<>(Lists.newArrayList(), ImmutableList.of( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + child); + Assertions.assertEquals(expected, actual); - List groupByExprList1 = Lists.newArrayList(); - List outputExpressionList1 = ImmutableList.of( - new SlotReference("b", new BigIntType(), true, Lists.newArrayList()) - ); - - LogicalAggregate two = new LogicalAggregate(groupByExprList1, outputExpressionList1, child); - Assertions.assertNotEquals(one, two); + LogicalAggregate unexpected = new LogicalAggregate<>(Lists.newArrayList(), ImmutableList.of( + new SlotReference(new ExprId(0), "b", new BigIntType(), true, Lists.newArrayList())), + child); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testLogicalFilter(@Mocked Plan child) { - Expression predicate = new EqualTo(Literal.of(1), Literal.of(2)); - LogicalFilter logicalFilter = new LogicalFilter(predicate, child); - Assertions.assertEquals(logicalFilter, logicalFilter); + LogicalFilter actual = new LogicalFilter<>(new EqualTo(Literal.of(1), Literal.of(1)), child); - Expression predicate1 = new EqualTo(Literal.of(1), Literal.of(1)); - LogicalFilter logicalFilter1 = new LogicalFilter(predicate1, child); - Assertions.assertNotEquals(logicalFilter, logicalFilter1); + LogicalFilter expected = new LogicalFilter<>(new EqualTo(Literal.of(1), Literal.of(1)), child); + Assertions.assertEquals(expected, actual); + + LogicalFilter unexpected = new LogicalFilter<>(new EqualTo(Literal.of(1), Literal.of(2)), child); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testLogicalJoin(@Mocked Plan left, @Mocked Plan right) { - Expression condition = new EqualTo( - new SlotReference("a", new BigIntType(), true, Lists.newArrayList()), - new SlotReference("b", new BigIntType(), true, Lists.newArrayList()) - ); - LogicalJoin innerJoin = new LogicalJoin(JoinType.INNER_JOIN, Lists.newArrayList(condition), + LogicalJoin actual = new LogicalJoin<>(JoinType.INNER_JOIN, Lists.newArrayList(new EqualTo( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()), + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()))), Optional.empty(), left, right); - Assertions.assertEquals(innerJoin, innerJoin); - // Notice: condition1 != condition, so following is `assertNotEquals`. - // Because SlotReference.exprId is UUID. - Expression condition1 = new EqualTo( - new SlotReference("a", new BigIntType(), true, Lists.newArrayList()), - new SlotReference("b", new BigIntType(), true, Lists.newArrayList()) - ); - LogicalJoin innerJoin1 = new LogicalJoin(JoinType.INNER_JOIN, Lists.newArrayList(condition1), + LogicalJoin expected = new LogicalJoin<>(JoinType.INNER_JOIN, Lists.newArrayList(new EqualTo( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()), + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()))), Optional.empty(), left, right); - Assertions.assertNotEquals(innerJoin, innerJoin1); + Assertions.assertEquals(expected, actual); - Expression condition2 = new EqualTo( + LogicalJoin unexpected = new LogicalJoin<>(JoinType.INNER_JOIN, Lists.newArrayList(new EqualTo( new SlotReference("a", new BigIntType(), false, Lists.newArrayList()), - new SlotReference("b", new BigIntType(), true, Lists.newArrayList()) - ); - LogicalJoin innerJoin2 = new LogicalJoin(JoinType.INNER_JOIN, Lists.newArrayList(condition2), + new SlotReference("b", new BigIntType(), true, Lists.newArrayList()))), Optional.empty(), left, right); - Assertions.assertNotEquals(innerJoin, innerJoin2); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testLogicalOlapScan() { - LogicalOlapScan scan1 = PlanConstructor.newLogicalOlapScan(0, "table", 0); - LogicalOlapScan scan2 = PlanConstructor.newLogicalOlapScan(0, "table", 0); + LogicalOlapScan actual = PlanConstructor.newLogicalOlapScan(0, "table", 0); - Assertions.assertEquals(scan1, scan2); + LogicalOlapScan expected = PlanConstructor.newLogicalOlapScan(0, "table", 0); + Assertions.assertEquals(expected, actual); + + LogicalOlapScan unexpected = PlanConstructor.newLogicalOlapScan(1, "table", 0); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testLogicalProject(@Mocked Plan child) { - // TODO: Depend on NamedExpression Equals - SlotReference aSlot = new SlotReference("a", new BigIntType(), true, Lists.newArrayList()); - List projects = ImmutableList.of(aSlot); - LogicalProject logicalProject = new LogicalProject(projects, child); - Assertions.assertEquals(logicalProject, logicalProject); + LogicalProject actual = new LogicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + child); - LogicalProject logicalProjectWithSameSlot = new LogicalProject(ImmutableList.of(aSlot), child); - Assertions.assertEquals(logicalProject, logicalProjectWithSameSlot); + LogicalProject expected = new LogicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + child); + Assertions.assertEquals(expected, actual); - SlotReference a1Slot = new SlotReference("a", new BigIntType(), true, Lists.newArrayList()); - LogicalProject a1LogicalProject = new LogicalProject(ImmutableList.of(a1Slot), child); - Assertions.assertNotEquals(logicalProject, a1LogicalProject); + LogicalProject unexpected1 = new LogicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(1), "a", new BigIntType(), true, Lists.newArrayList())), + child); + Assertions.assertNotEquals(unexpected1, actual); - SlotReference bSlot = new SlotReference("b", new BigIntType(), true, Lists.newArrayList()); - LogicalProject bLogicalProject1 = new LogicalProject(ImmutableList.of(bSlot), child); - Assertions.assertNotEquals(logicalProject, bLogicalProject1); + LogicalProject unexpected2 = new LogicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList())), + child); + Assertions.assertNotEquals(unexpected2, actual); } @Test public void testLogicalSort(@Mocked Plan child) { - // TODO: Depend on List Equals - List orderKeyList = Lists.newArrayList(); - LogicalSort logicalSort = new LogicalSort(orderKeyList, child); - Assertions.assertEquals(logicalSort, logicalSort); + LogicalSort actual = new LogicalSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()), true, + true)), + child); - List orderKeyListClone = Lists.newArrayList(); - LogicalSort logicalSortClone = new LogicalSort(orderKeyListClone, child); - Assertions.assertEquals(logicalSort, logicalSortClone); + LogicalSort expected = new LogicalSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()), true, + true)), + child); + Assertions.assertEquals(expected, actual); + + LogicalSort unexpected = new LogicalSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "a", new BigIntType(), true, Lists.newArrayList()), true, + true)), + child); + Assertions.assertNotEquals(unexpected, actual); } /* *************************** Physical *************************** */ @Test public void testPhysicalAggregate(@Mocked Plan child, @Mocked LogicalProperties logicalProperties) { - List groupByExprList = Lists.newArrayList(); - SlotReference slotReference = new SlotReference("a", new BigIntType(), true, Lists.newArrayList()); - List outputExpressionList = ImmutableList.of(slotReference); - List partitionExprList = Lists.newArrayList(); - AggPhase aggPhase = AggPhase.LOCAL; - boolean usingStream = true; + List outputExpressionList = ImmutableList.of( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())); + PhysicalAggregate actual = new PhysicalAggregate<>(Lists.newArrayList(), outputExpressionList, + Lists.newArrayList(), AggPhase.LOCAL, true, logicalProperties, child); - PhysicalAggregate physicalAggregate = new PhysicalAggregate(groupByExprList, outputExpressionList, - partitionExprList, aggPhase, usingStream, logicalProperties, child); - Assertions.assertEquals(physicalAggregate, physicalAggregate); + List outputExpressionList1 = ImmutableList.of( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())); + PhysicalAggregate expected = new PhysicalAggregate<>(Lists.newArrayList(), + outputExpressionList1, + Lists.newArrayList(), AggPhase.LOCAL, true, logicalProperties, child); + Assertions.assertEquals(expected, actual); + + List outputExpressionList2 = ImmutableList.of( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())); + PhysicalAggregate unexpected = new PhysicalAggregate<>(Lists.newArrayList(), + outputExpressionList2, + Lists.newArrayList(), AggPhase.LOCAL, false, logicalProperties, child); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testPhysicalFilter(@Mocked Plan child, @Mocked LogicalProperties logicalProperties) { - Expression predicate = new EqualTo(Literal.of(1), Literal.of(2)); + PhysicalFilter actual = new PhysicalFilter<>(new EqualTo(Literal.of(1), Literal.of(2)), + logicalProperties, child); - PhysicalFilter physicalFilter = new PhysicalFilter(predicate, logicalProperties, child); - Assertions.assertEquals(physicalFilter, physicalFilter); + PhysicalFilter expected = new PhysicalFilter<>(new EqualTo(Literal.of(1), Literal.of(2)), + logicalProperties, child); + Assertions.assertEquals(expected, actual); + + PhysicalFilter unexpected = new PhysicalFilter<>(new EqualTo(Literal.of(1), Literal.of(1)), + logicalProperties, child); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testPhysicalJoin(@Mocked Plan left, @Mocked Plan right, @Mocked LogicalProperties logicalProperties) { - Expression expression = new EqualTo(Literal.of(1), Literal.of(2)); + PhysicalHashJoin actual = new PhysicalHashJoin<>(JoinType.INNER_JOIN, + Lists.newArrayList(new EqualTo( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()), + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()))), + Optional.empty(), logicalProperties, left, right); - PhysicalHashJoin innerJoin = new PhysicalHashJoin(JoinType.INNER_JOIN, Lists.newArrayList(expression), - Optional.empty(), - logicalProperties, left, - right); - Assertions.assertEquals(innerJoin, innerJoin); + PhysicalHashJoin expected = new PhysicalHashJoin<>(JoinType.INNER_JOIN, + Lists.newArrayList(new EqualTo( + new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()), + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()))), + Optional.empty(), logicalProperties, left, right); + Assertions.assertEquals(expected, actual); + + PhysicalHashJoin unexpected = new PhysicalHashJoin<>(JoinType.INNER_JOIN, + Lists.newArrayList(new EqualTo( + new SlotReference("a", new BigIntType(), false, Lists.newArrayList()), + new SlotReference("b", new BigIntType(), true, Lists.newArrayList()))), + Optional.empty(), logicalProperties, left, right); + Assertions.assertNotEquals(unexpected, actual); } @Test @@ -193,48 +222,76 @@ public class PlanEqualsTest { @Mocked LogicalProperties logicalProperties, @Mocked OlapTable olapTable, @Mocked DistributionSpecHash distributionSpecHash) { - List qualifier = Lists.newArrayList(); - - ArrayList selectedTabletId = Lists.newArrayList(); + List selectedTabletId = Lists.newArrayList(); for (Partition partition : olapTable.getAllPartitions()) { selectedTabletId.addAll(partition.getBaseIndex().getTabletIdsInOrder()); } - PhysicalOlapScan olapScan = new PhysicalOlapScan(olapTable, qualifier, olapTable.getBaseIndexId(), + + PhysicalOlapScan actual = new PhysicalOlapScan(olapTable, Lists.newArrayList("a"), olapTable.getBaseIndexId(), selectedTabletId, olapTable.getPartitionIds(), distributionSpecHash, Optional.empty(), logicalProperties); - Assertions.assertEquals(olapScan, olapScan); + PhysicalOlapScan expected = new PhysicalOlapScan(olapTable, Lists.newArrayList("a"), + olapTable.getBaseIndexId(), selectedTabletId, olapTable.getPartitionIds(), distributionSpecHash, + Optional.empty(), logicalProperties); + Assertions.assertEquals(expected, actual); + + PhysicalOlapScan unexpected = new PhysicalOlapScan(olapTable, Lists.newArrayList("b"), + olapTable.getBaseIndexId(), selectedTabletId, olapTable.getPartitionIds(), distributionSpecHash, + Optional.empty(), logicalProperties); + Assertions.assertNotEquals(unexpected, actual); } @Test public void testPhysicalProject(@Mocked Plan child, @Mocked LogicalProperties logicalProperties) { - - // TODO: Depend on NamedExpression Equals - SlotReference aSlot = new SlotReference("a", new BigIntType(), true, Lists.newArrayList()); - List projects = ImmutableList.of(aSlot); - PhysicalProject physicalProject = new PhysicalProject(projects, logicalProperties, child); - Assertions.assertEquals(physicalProject, physicalProject); - - PhysicalProject physicalProjectWithSameSlot = new PhysicalProject(ImmutableList.of(aSlot), logicalProperties, + PhysicalProject actual = new PhysicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + logicalProperties, child); - Assertions.assertEquals(physicalProject, physicalProjectWithSameSlot); - SlotReference a1Slot = new SlotReference("a", new BigIntType(), true, Lists.newArrayList()); - PhysicalProject a1PhysicalProject = new PhysicalProject(ImmutableList.of(a1Slot), logicalProperties, child); - Assertions.assertNotEquals(physicalProject, a1PhysicalProject); + PhysicalProject expected = new PhysicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())), + logicalProperties, + child); + Assertions.assertEquals(expected, actual); + + PhysicalProject unexpected1 = new PhysicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(1), "a", new BigIntType(), true, Lists.newArrayList())), + logicalProperties, + child); + Assertions.assertNotEquals(unexpected1, actual); + + PhysicalProject unexpected2 = new PhysicalProject<>( + ImmutableList.of(new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList())), + logicalProperties, + child); + Assertions.assertNotEquals(unexpected2, actual); } @Test public void testPhysicalSort(@Mocked Plan child, @Mocked LogicalProperties logicalProperties) { - // TODO: Depend on List Equals - List orderKeyList = Lists.newArrayList(); - PhysicalQuickSort physicalQuickSort = new PhysicalQuickSort(orderKeyList, logicalProperties, child); - Assertions.assertEquals(physicalQuickSort, physicalQuickSort); - - List orderKeyListClone = Lists.newArrayList(); - PhysicalQuickSort physicalQuickSortClone = new PhysicalQuickSort(orderKeyListClone, logicalProperties, + PhysicalQuickSort actual = new PhysicalQuickSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()), true, + true)), + logicalProperties, child); - Assertions.assertEquals(physicalQuickSort, physicalQuickSortClone); + + PhysicalQuickSort expected = new PhysicalQuickSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()), true, + true)), + logicalProperties, + child); + Assertions.assertEquals(expected, actual); + + PhysicalQuickSort unexpected = new PhysicalQuickSort<>( + ImmutableList.of(new OrderKey( + new SlotReference(new ExprId(1), "a", new BigIntType(), true, Lists.newArrayList()), true, + true)), + logicalProperties, + child); + Assertions.assertNotEquals(unexpected, actual); } }