yujun777 commented on code in PR #65472:
URL: https://github.com/apache/doris/pull/65472#discussion_r3584912389


##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnionAllTest.java:
##########
@@ -0,0 +1,456 @@
+// 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.rules.rewrite;
+
+import org.apache.doris.analysis.TableScanParams;
+import org.apache.doris.analysis.TableSnapshot;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OdbcTable;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.catalog.stream.OlapTableStreamWrapper;
+import org.apache.doris.catalog.stream.StreamReadMode;
+import org.apache.doris.common.Pair;
+import org.apache.doris.datasource.ExternalTable;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFileScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOdbcScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOlapTableStreamScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.LogicalSchemaScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalTestScan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalUnion;
+import org.apache.doris.nereids.util.MemoTestUtils;
+import org.apache.doris.nereids.util.PlanChecker;
+import org.apache.doris.nereids.util.PlanConstructor;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+class PullUpJoinFromUnionAllTest {
+
+    @Test
+    void comparatorRejectsDifferentProjectOutputSizes() {
+        LogicalOlapScan smallScan = newScan(1, "common_small");
+        LogicalOlapScan largeScan = newScan(1, "common_large");
+        LogicalProject<LogicalOlapScan> smallProject = 
project(selectSlots(smallScan.getOutput(), 0), smallScan);
+        LogicalProject<LogicalOlapScan> largeProject = 
project(selectSlots(largeScan.getOutput(), 0, 1), largeScan);
+
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        Assertions.assertFalse(comparator.isLogicalEqual(largeProject, 
smallProject));
+    }
+
+    @Test
+    void comparatorRejectsDifferentFilterChildOutputSizes() {
+        LogicalFilter<LogicalOlapScan> smallFilter = 
filter(newCachedOutputScan(1, "common_filter", 0));
+        LogicalFilter<LogicalOlapScan> largeFilter = 
filter(newCachedOutputScan(1, "common_filter", 0, 1));
+
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        Assertions.assertFalse(comparator.isLogicalEqual(largeFilter, 
smallFilter));
+    }
+
+    @Test
+    void comparatorRejectsDifferentMaterializedIndexSelections() {
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        LogicalOlapScan baseScan = newScanWithExtraIndex(11, "common_index", 
101);
+        LogicalOlapScan indexScan = 
baseScan.withMaterializedIndexSelected(101);
+
+        Assertions.assertFalse(comparator.isLogicalEqual(baseScan, indexScan));
+    }
+
+    @Test
+    void comparatorRejectsDifferentManuallySpecifiedPartitions() {
+        LogicalOlapScan firstPartitionScan = 
PlanConstructor.newLogicalOlapScanWithSameId(
+                12, "common_partition", 0, ImmutableList.of(1L));
+        LogicalOlapScan secondPartitionScan = 
PlanConstructor.newLogicalOlapScanWithSameId(
+                12, "common_partition", 0, ImmutableList.of(2L));
+
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        Assertions.assertFalse(comparator.isLogicalEqual(firstPartitionScan, 
secondPartitionScan));
+    }
+
+    @Test
+    void comparatorRejectsDifferentTableSamples() {
+        LogicalOlapScan sampleOneScan = newScanWithTableSample(43, 
"common_sample",
+                new org.apache.doris.nereids.trees.TableSample(10, true, 0));
+        LogicalOlapScan sampleTwoScan = newScanWithTableSample(43, 
"common_sample",
+                new org.apache.doris.nereids.trees.TableSample(20, true, 0));
+
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        Assertions.assertFalse(comparator.isLogicalEqual(sampleOneScan, 
sampleTwoScan));
+    }
+
+    @Test
+    void comparatorRejectsDifferentOlapScanParams() {
+        LogicalOlapScan incrementalScan = newScanWithScanParams(44, 
"common_params",
+                new TableScanParams(TableScanParams.INCREMENTAL_READ,
+                        ImmutableMap.of("end_ts", "10"), ImmutableList.of()));
+        LogicalOlapScan differentIncrementalScan = newScanWithScanParams(44, 
"common_params",
+                new TableScanParams(TableScanParams.INCREMENTAL_READ,
+                        ImmutableMap.of("end_ts", "20"), ImmutableList.of()));
+
+        PullUpJoinFromUnionAll.LogicalPlanComparator comparator =
+                new PullUpJoinFromUnionAll().new LogicalPlanComparator();
+        Assertions.assertFalse(comparator.isLogicalEqual(incrementalScan, 
differentIncrementalScan));
+    }
+
+    @Test
+    void comparatorRejectsDifferentStreamReadModes() {
+        LogicalOlapTableStreamScan incrementalScan = newStreamScan(15, 
"common_stream");

Review Comment:
   Updated the test in the latest commit.
   
   `comparatorRejectsDifferentStreamReadModes()` now builds a fully stubbed 
stream scan with `newStreamScanWithOffsets(...)` and compares `SNAPSHOT` vs 
`RESET`, so both sides keep the same output arity and stream identity. The 
assertion now fails specifically on the `readMode` difference instead of the 
generic output-size guard.
   
   I also reran `PullUpJoinFromUnionAllTest` after the change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to