Skip to content

Commit 57e0a1c

Browse files
authored
[fix](nereids) fix bug in PhysicalTopN.equals() (#46547)
1 parent 5a28a4b commit 57e0a1c

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

Diff for: fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopN.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public boolean equals(Object o) {
9393
return false;
9494
}
9595
PhysicalTopN<?> that = (PhysicalTopN<?>) o;
96-
return limit == that.limit && offset == that.offset;
96+
return limit == that.limit && offset == that.offset
97+
&& this.phase == that.phase
98+
&& Objects.equals(that.getOrderKeys(), getOrderKeys());
9799
}
98100

99101
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.nereids.trees.plans.physical;
19+
20+
import org.apache.doris.nereids.properties.OrderKey;
21+
import org.apache.doris.nereids.trees.expressions.ExprId;
22+
import org.apache.doris.nereids.trees.expressions.SlotReference;
23+
import org.apache.doris.nereids.trees.plans.Plan;
24+
import org.apache.doris.nereids.trees.plans.SortPhase;
25+
import org.apache.doris.nereids.types.BigIntType;
26+
27+
import com.google.common.collect.Lists;
28+
import mockit.Mocked;
29+
import org.junit.jupiter.api.Assertions;
30+
import org.junit.jupiter.api.Test;
31+
32+
import java.util.List;
33+
34+
public class PhysicalTopNTest {
35+
@Test
36+
public void testEquals(@Mocked Plan child) {
37+
SlotReference a = new SlotReference(new ExprId(0), "a",
38+
BigIntType.INSTANCE, true, Lists.newArrayList());
39+
List<OrderKey> orderKeysA = Lists.newArrayList();
40+
orderKeysA.add(new OrderKey(a, true, true));
41+
PhysicalTopN topn1 = new PhysicalTopN(orderKeysA, 1, 1, SortPhase.LOCAL_SORT,
42+
null, child);
43+
PhysicalTopN topn2 = new PhysicalTopN(orderKeysA, 1, 1, SortPhase.GATHER_SORT,
44+
null, child);
45+
Assertions.assertNotEquals(topn1, topn2);
46+
47+
SlotReference b = new SlotReference(new ExprId(0), "b",
48+
BigIntType.INSTANCE, true, Lists.newArrayList());
49+
List<OrderKey> orderKeysB = Lists.newArrayList();
50+
orderKeysB.add(new OrderKey(b, true, true));
51+
PhysicalTopN topn3 = new PhysicalTopN(orderKeysB, 1, 1, SortPhase.LOCAL_SORT,
52+
null, child);
53+
Assertions.assertNotEquals(topn2, topn3);
54+
}
55+
}

0 commit comments

Comments
 (0)