branch-2.1: [fix](nereids) fix bug in PhysicalTopN.equals() #46547 (#46633)

Cherry-picked from #46547

Co-authored-by: minghong <zhouminghong@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-01-09 10:28:40 +08:00
committed by GitHub
parent 52fd9349f0
commit afeff5daee
2 changed files with 58 additions and 1 deletions

View File

@ -92,7 +92,9 @@ public class PhysicalTopN<CHILD_TYPE extends Plan> 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

View File

@ -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<OrderKey> 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<OrderKey> 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);
}
}