[test](Nereids): add more plan equals test for Nereids (#12127)

- add more plan equals test for Nereids
- fix join equals bugs
This commit is contained in:
jakevin
2022-08-29 11:46:30 +08:00
committed by GitHub
parent ac425d4bf3
commit eb3e0b2f7d
9 changed files with 196 additions and 132 deletions

View File

@ -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()) {

View File

@ -67,11 +67,11 @@ public class RewriteTopDownJob extends Job {
List<Rule> 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<Plan> afters = rule.transform(before, context.getPlannerContext());
Preconditions.checkArgument(afters.size() == 1);
@ -80,8 +80,8 @@ public class RewriteTopDownJob extends Job {
Pair<Boolean, GroupExpression> 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;
}

View File

@ -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() {

View File

@ -44,7 +44,7 @@ public class Memo {
private final List<Group> groups = Lists.newArrayList();
// we could not use Set, because Set does not have get method.
private final Map<GroupExpression, GroupExpression> groupExpressions = Maps.newHashMap();
private Group root;
private final Group root;
public Memo(Plan plan) {
root = copyIn(plan, null, false).second.getOwnerGroup();

View File

@ -42,7 +42,7 @@ public class FilterSelectivityCalculator extends ExpressionVisitor<Double, Void>
private final Map<Slot, ColumnStats> slotRefToStats;
public FilterSelectivityCalculator(Map<Slot, ColumnStats> slotRefToStats) {
Preconditions.checkState(slotRefToStats != null);
Preconditions.checkNotNull(slotRefToStats);
this.slotRefToStats = slotRefToStats;
}

View File

@ -184,6 +184,8 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
return sb.toString();
}
//TODO:
// 1. consider the order of conjucts in otherJoinCondition and hashJoinConditions
@Override
public boolean equals(Object o) {
if (this == o) {
@ -195,6 +197,7 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
LogicalJoin that = (LogicalJoin) o;
return joinType == that.joinType
// TODO: why use containsAll?
&& that.getHashJoinConjuncts().containsAll(hashJoinConjuncts)
&& hashJoinConjuncts.containsAll(that.getHashJoinConjuncts())
&& Objects.equals(otherJoinCondition, that.otherJoinCondition);

View File

@ -78,9 +78,8 @@ public abstract class AbstractPhysicalJoin<
return otherJoinCondition.<List<Expression>>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<Expression> getOnClauseCondition() {

View File

@ -42,7 +42,7 @@ public class PhysicalHashJoin<
public PhysicalHashJoin(JoinType joinType, List<Expression> hashJoinConjuncts,
Optional<Expression> 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<Expression> hashJoinConjuncts, Optional<Expression> condition,
Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties,
LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) {
Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties,
LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) {
super(PlanType.PHYSICAL_HASH_JOIN, joinType, hashJoinConjuncts, condition,
groupExpression, logicalProperties, leftChild, rightChild);
}

View File

@ -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<Expression> groupByExprList = Lists.newArrayList();
List<NamedExpression> outputExpressionList = ImmutableList.of(
new SlotReference("a", new BigIntType(), true, Lists.newArrayList())
);
LogicalAggregate<Plan> 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<Plan> expected = new LogicalAggregate<>(Lists.newArrayList(), ImmutableList.of(
new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())),
child);
Assertions.assertEquals(expected, actual);
List<Expression> groupByExprList1 = Lists.newArrayList();
List<NamedExpression> outputExpressionList1 = ImmutableList.of(
new SlotReference("b", new BigIntType(), true, Lists.newArrayList())
);
LogicalAggregate two = new LogicalAggregate(groupByExprList1, outputExpressionList1, child);
Assertions.assertNotEquals(one, two);
LogicalAggregate<Plan> 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<Plan> 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<Plan> expected = new LogicalFilter<>(new EqualTo(Literal.of(1), Literal.of(1)), child);
Assertions.assertEquals(expected, actual);
LogicalFilter<Plan> 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<Plan, Plan> 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<Plan, Plan> 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<Plan, Plan> 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<NamedExpression> projects = ImmutableList.of(aSlot);
LogicalProject logicalProject = new LogicalProject(projects, child);
Assertions.assertEquals(logicalProject, logicalProject);
LogicalProject<Plan> 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<Plan> 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<Plan> 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<Plan> 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<OrderKey> Equals
List<OrderKey> orderKeyList = Lists.newArrayList();
LogicalSort logicalSort = new LogicalSort(orderKeyList, child);
Assertions.assertEquals(logicalSort, logicalSort);
LogicalSort<Plan> actual = new LogicalSort<>(
ImmutableList.of(new OrderKey(
new SlotReference(new ExprId(1), "b", new BigIntType(), true, Lists.newArrayList()), true,
true)),
child);
List<OrderKey> orderKeyListClone = Lists.newArrayList();
LogicalSort logicalSortClone = new LogicalSort(orderKeyListClone, child);
Assertions.assertEquals(logicalSort, logicalSortClone);
LogicalSort<Plan> 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<Plan> 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<Expression> groupByExprList = Lists.newArrayList();
SlotReference slotReference = new SlotReference("a", new BigIntType(), true, Lists.newArrayList());
List<NamedExpression> outputExpressionList = ImmutableList.of(slotReference);
List<Expression> partitionExprList = Lists.newArrayList();
AggPhase aggPhase = AggPhase.LOCAL;
boolean usingStream = true;
List<NamedExpression> outputExpressionList = ImmutableList.of(
new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()));
PhysicalAggregate<Plan> 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<NamedExpression> outputExpressionList1 = ImmutableList.of(
new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()));
PhysicalAggregate<Plan> expected = new PhysicalAggregate<>(Lists.newArrayList(),
outputExpressionList1,
Lists.newArrayList(), AggPhase.LOCAL, true, logicalProperties, child);
Assertions.assertEquals(expected, actual);
List<NamedExpression> outputExpressionList2 = ImmutableList.of(
new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList()));
PhysicalAggregate<Plan> 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<Plan> 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<Plan> expected = new PhysicalFilter<>(new EqualTo(Literal.of(1), Literal.of(2)),
logicalProperties, child);
Assertions.assertEquals(expected, actual);
PhysicalFilter<Plan> 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<Plan, Plan> 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<Plan, Plan> 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<Plan, Plan> 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<String> qualifier = Lists.newArrayList();
ArrayList<Long> selectedTabletId = Lists.newArrayList();
List<Long> 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<NamedExpression> projects = ImmutableList.of(aSlot);
PhysicalProject physicalProject = new PhysicalProject(projects, logicalProperties, child);
Assertions.assertEquals(physicalProject, physicalProject);
PhysicalProject physicalProjectWithSameSlot = new PhysicalProject(ImmutableList.of(aSlot), logicalProperties,
PhysicalProject<Plan> 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<Plan> expected = new PhysicalProject<>(
ImmutableList.of(new SlotReference(new ExprId(0), "a", new BigIntType(), true, Lists.newArrayList())),
logicalProperties,
child);
Assertions.assertEquals(expected, actual);
PhysicalProject<Plan> unexpected1 = new PhysicalProject<>(
ImmutableList.of(new SlotReference(new ExprId(1), "a", new BigIntType(), true, Lists.newArrayList())),
logicalProperties,
child);
Assertions.assertNotEquals(unexpected1, actual);
PhysicalProject<Plan> 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<OrderKey> Equals
List<OrderKey> orderKeyList = Lists.newArrayList();
PhysicalQuickSort physicalQuickSort = new PhysicalQuickSort(orderKeyList, logicalProperties, child);
Assertions.assertEquals(physicalQuickSort, physicalQuickSort);
List<OrderKey> orderKeyListClone = Lists.newArrayList();
PhysicalQuickSort physicalQuickSortClone = new PhysicalQuickSort(orderKeyListClone, logicalProperties,
PhysicalQuickSort<Plan> 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<Plan> 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<Plan> 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);
}
}