[fix](Nereids) throw IndexOutOfBoundsException in DistributionSpecHash#equalsSatisfy (#12446)

In earlier PR #11976 , we changed DistributionSpecHash#equalsSatisfy, and forgot to check whether the length of both side are same. When required's shuffle slot size longer than current one, exception will be thrown.
This commit is contained in:
morrySnow
2022-09-08 11:41:48 +08:00
committed by GitHub
parent dd2f834c79
commit a6880ca573
2 changed files with 34 additions and 8 deletions

View File

@ -168,14 +168,6 @@ public class DistributionSpecHash extends DistributionSpec {
return containsSatisfy(requiredHash.getOrderedShuffledColumns());
}
// if (requiredHash.shuffleType == ShuffleType.JOIN) {
// return equalsSatisfy(requiredHash.getOrderedShuffledColumns());
// }
//
// if (!this.shuffleType.equals(requiredHash.shuffleType)) {
// return false;
// }
return equalsSatisfy(requiredHash.getOrderedShuffledColumns());
}
@ -190,6 +182,9 @@ public class DistributionSpecHash extends DistributionSpec {
}
private boolean equalsSatisfy(List<ExprId> required) {
if (equivalenceExprIds.size() != required.size()) {
return false;
}
for (int i = 0; i < required.size(); i++) {
if (!equivalenceExprIds.get(i).contains(required.get(i))) {
return false;

View File

@ -450,4 +450,35 @@ public class DistributionSpecHashTest {
Assertions.assertTrue(aggregate.satisfy(enforce2));
Assertions.assertTrue(natural.satisfy(enforce2));
}
@Test
public void testHashEqualSatisfyWithDifferentLength() {
Map<ExprId, Integer> enforce1Map = Maps.newHashMap();
enforce1Map.put(new ExprId(0), 0);
enforce1Map.put(new ExprId(1), 1);
enforce1Map.put(new ExprId(2), 2);
DistributionSpecHash enforce1 = new DistributionSpecHash(
Lists.newArrayList(new ExprId(0), new ExprId(1), new ExprId(2)),
ShuffleType.ENFORCE,
0,
Sets.newHashSet(0L),
Lists.newArrayList(Sets.newHashSet(new ExprId(0)), Sets.newHashSet(new ExprId(1)), Sets.newHashSet(new ExprId(2))),
enforce1Map
);
Map<ExprId, Integer> enforce2Map = Maps.newHashMap();
enforce2Map.put(new ExprId(0), 0);
enforce2Map.put(new ExprId(1), 1);
DistributionSpecHash enforce2 = new DistributionSpecHash(
Lists.newArrayList(new ExprId(0), new ExprId(1)),
ShuffleType.ENFORCE,
1,
Sets.newHashSet(1L),
Lists.newArrayList(Sets.newHashSet(new ExprId(0)), Sets.newHashSet(new ExprId(1))),
enforce2Map
);
Assertions.assertFalse(enforce1.satisfy(enforce2));
Assertions.assertFalse(enforce2.satisfy(enforce1));
}
}