diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopN.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopN.java index 96dc709bbd..0f2d318658 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopN.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopN.java @@ -92,7 +92,9 @@ public class PhysicalTopN extends AbstractPhysicalSort< return false; } PhysicalTopN that = (PhysicalTopN) o; - return limit == that.limit && offset == that.offset; + return limit == that.limit && offset == that.offset + && this.phase == that.phase + && Objects.equals(that.getOrderKeys(), getOrderKeys()); } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopNTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopNTest.java new file mode 100644 index 0000000000..c411ad4461 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/physical/PhysicalTopNTest.java @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.plans.physical; + +import org.apache.doris.nereids.properties.OrderKey; +import org.apache.doris.nereids.trees.expressions.ExprId; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.SortPhase; +import org.apache.doris.nereids.types.BigIntType; + +import com.google.common.collect.Lists; +import mockit.Mocked; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class PhysicalTopNTest { + @Test + public void testEquals(@Mocked Plan child) { + SlotReference a = new SlotReference(new ExprId(0), "a", + BigIntType.INSTANCE, true, Lists.newArrayList()); + List orderKeysA = Lists.newArrayList(); + orderKeysA.add(new OrderKey(a, true, true)); + PhysicalTopN topn1 = new PhysicalTopN(orderKeysA, 1, 1, SortPhase.LOCAL_SORT, + null, child); + PhysicalTopN topn2 = new PhysicalTopN(orderKeysA, 1, 1, SortPhase.GATHER_SORT, + null, child); + Assertions.assertNotEquals(topn1, topn2); + + SlotReference b = new SlotReference(new ExprId(0), "b", + BigIntType.INSTANCE, true, Lists.newArrayList()); + List orderKeysB = Lists.newArrayList(); + orderKeysB.add(new OrderKey(b, true, true)); + PhysicalTopN topn3 = new PhysicalTopN(orderKeysB, 1, 1, SortPhase.LOCAL_SORT, + null, child); + Assertions.assertNotEquals(topn2, topn3); + } +}