This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 782001c75b [fix](planner) project should be done inside subquery 
(#17630)
782001c75b is described below

commit 782001c75ba3a0226bdd65e1ba76e8b35b3d4913
Author: starocean999 <[email protected]>
AuthorDate: Mon Mar 13 11:10:27 2023 +0800

    [fix](planner) project should be done inside subquery (#17630)
    
    WITH t0 AS(
    SELECT report.date1 AS date2 FROM(
    SELECT DATE_FORMAT(date, '%Y%m%d') AS date1 FROM cir_1756_t1
    ) report GROUP BY report.date1
    ),
    t3 AS(
    SELECT date_format(date, '%Y%m%d') AS date3
    FROM cir_1756_t2
    )
    SELECT row_number() OVER(ORDER BY date2)
    FROM(
    SELECT t0.date2 FROM t0 LEFT JOIN t3 ON t0.date2 = t3.date3
    ) tx;
    
    The DATE_FORMAT(date, '%Y%m%d') was calculated in GROUP BY node, which is 
wrong. This expr should be calculated inside the subquery.
---
 .../apache/doris/planner/NestedLoopJoinNode.java   |   4 +-
 .../org/apache/doris/planner/OlapScanNode.java     |  42 +++
 .../java/org/apache/doris/planner/SelectNode.java  |   5 +-
 .../org/apache/doris/planner/QueryPlanTest.java    |   6 +-
 .../doris/planner/SingleNodePlannerTest.java       | 298 ---------------------
 .../test_inlineview_with_project.out               |   4 +
 .../aggregate_functions/test_aggregate_collect.out |  64 -----
 .../test_inlineview_with_project.groovy            |  80 ++++++
 .../test_aggregate_collect.groovy                  |  28 +-
 9 files changed, 148 insertions(+), 383 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/NestedLoopJoinNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/NestedLoopJoinNode.java
index fffadd7f58..942fb629d4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/NestedLoopJoinNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/NestedLoopJoinNode.java
@@ -70,8 +70,8 @@ public class NestedLoopJoinNode extends JoinNodeBase {
 
     public NestedLoopJoinNode(PlanNodeId id, PlanNode outer, PlanNode inner, 
TableRef innerRef) {
         super(id, "NESTED LOOP JOIN", StatisticalType.NESTED_LOOP_JOIN_NODE, 
outer, inner, innerRef);
-        tupleIds.addAll(outer.getTupleIds());
-        tupleIds.addAll(inner.getTupleIds());
+        tupleIds.addAll(outer.getOutputTupleIds());
+        tupleIds.addAll(inner.getOutputTupleIds());
     }
 
     public boolean canParallelize() {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
index 1821b55829..cb96b42301 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -24,6 +24,7 @@ import org.apache.doris.analysis.CastExpr;
 import org.apache.doris.analysis.CreateMaterializedViewStmt;
 import org.apache.doris.analysis.DescriptorTable;
 import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.ExprSubstitutionMap;
 import org.apache.doris.analysis.InPredicate;
 import org.apache.doris.analysis.IntLiteral;
 import org.apache.doris.analysis.PartitionNames;
@@ -1385,4 +1386,45 @@ public class OlapScanNode extends ScanNode {
             }
         }
     }
+
+    public void setOutputSmap(ExprSubstitutionMap smap, Analyzer analyzer) {
+        if (smap.getRhs().stream().anyMatch(expr -> !(expr instanceof 
SlotRef))) {
+            if (outputTupleDesc == null) {
+                outputTupleDesc = 
analyzer.getDescTbl().createTupleDescriptor("OlapScanNode");
+                outputTupleDesc.setTable(this.olapTable);
+            }
+            if (projectList == null) {
+                projectList = Lists.newArrayList();
+            }
+            List<Expr> newRhs = Lists.newArrayList();
+            List<Expr> newLhs = Lists.newArrayList();
+            for (Expr expr : smap.getRhs()) {
+                if (expr instanceof SlotRef && !((SlotRef) 
expr).getDesc().isMaterialized()) {
+                    continue;
+                }
+                if (outputSmap.mappingForRhsExpr(expr) != null) {
+                    newLhs.add(outputSmap.mappingForRhsExpr(expr));
+                    newRhs.add(expr);
+                } else {
+                    SlotDescriptor slotDesc = 
analyzer.addSlotDescriptor(outputTupleDesc);
+                    slotDesc.initFromExpr(expr);
+                    slotDesc.setIsMaterialized(true);
+                    slotDesc.materializeSrcExpr();
+                    projectList.add(expr);
+                    newLhs.add(smap.mappingForRhsExpr(expr));
+                    newRhs.add(new SlotRef(slotDesc));
+                }
+            }
+            outputSmap = new ExprSubstitutionMap(newLhs, newRhs);
+        } else {
+            outputSmap = smap;
+        }
+    }
+
+    public List<TupleId> getOutputTupleIds() {
+        if (outputTupleDesc != null) {
+            return Lists.newArrayList(outputTupleDesc.getId());
+        }
+        return tupleIds;
+    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SelectNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/SelectNode.java
index c9d2a2daf5..93bd430f2a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SelectNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SelectNode.java
@@ -32,6 +32,7 @@ import org.apache.doris.thrift.TPlanNodeType;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -44,13 +45,13 @@ public class SelectNode extends PlanNode {
      * Used by nereids only.
      */
     public SelectNode(PlanNodeId id, PlanNode child) {
-        super(id, child.getTupleIds(), "SELECT", StatisticalType.SELECT_NODE);
+        super(id, new ArrayList<>(child.getOutputTupleIds()), "SELECT", 
StatisticalType.SELECT_NODE);
         addChild(child);
         this.nullableTupleIds = child.nullableTupleIds;
     }
 
     protected SelectNode(PlanNodeId id, PlanNode child, List<Expr> conjuncts) {
-        super(id, child.getTupleIds(), "SELECT", StatisticalType.SELECT_NODE);
+        super(id, new ArrayList<>(child.getOutputTupleIds()), "SELECT", 
StatisticalType.SELECT_NODE);
         addChild(child);
         this.tblRefIds = child.tblRefIds;
         this.nullableTupleIds = child.nullableTupleIds;
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index 747808494e..206456e188 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -1637,15 +1637,15 @@ public class QueryPlanTest extends TestWithFeService {
 
         sql = "SELECT a.k1, b.k2 FROM (SELECT k1 from baseall) a LEFT OUTER 
JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)";
         explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
-        Assert.assertTrue(explainString.contains("<slot 5>\n" + "    <slot 
7>"));
+        Assert.assertTrue(explainString.contains("<slot 7>\n" + "    <slot 
9>"));
 
         sql = "SELECT a.k1, b.k2 FROM (SELECT 1 as k1 from baseall) a RIGHT 
OUTER JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)";
         explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
-        Assert.assertTrue(explainString.contains("<slot 5>\n" + "    <slot 
7>"));
+        Assert.assertTrue(explainString.contains("<slot 8>\n" + "    <slot 
10>"));
 
         sql = "SELECT a.k1, b.k2 FROM (SELECT 1 as k1 from baseall) a FULL 
JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)";
         explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
-        Assert.assertTrue(explainString.contains("<slot 5>\n" + "    <slot 
7>"));
+        Assert.assertTrue(explainString.contains("<slot 8>\n" + "    <slot 
10>"));
     }
 
     @Test
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/SingleNodePlannerTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/planner/SingleNodePlannerTest.java
index 893ec17c36..d6a107a874 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/planner/SingleNodePlannerTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/planner/SingleNodePlannerTest.java
@@ -700,304 +700,6 @@ public class SingleNodePlannerTest {
         Assert.assertEquals(scanNode3, cheapestJoinNode.getChild(1));
     }
 
-    /*
-    Query: select * from t1,t2 right join t3,t5,t4 left join t6,t7
-    Expect: keep t3, t6 position
-            t2, t1 right join t3, t4,t5 left join t6,t7
-     */
-    @Test
-    public void testKeepMultiOuterJoin(@Injectable PlannerContext context,
-                                       @Injectable Analyzer analyzer,
-                                       @Injectable BaseTableRef tableRef1, 
@Injectable OlapScanNode scanNode1,
-                                       @Injectable BaseTableRef tableRef2, 
@Injectable OlapScanNode scanNode2,
-                                       @Injectable BaseTableRef tableRef3, 
@Injectable OlapScanNode scanNode3,
-                                       @Injectable BaseTableRef tableRef4, 
@Injectable OlapScanNode scanNode4,
-                                       @Injectable BaseTableRef tableRef5, 
@Injectable OlapScanNode scanNode5,
-                                       @Injectable BaseTableRef tableRef6, 
@Injectable OlapScanNode scanNode6,
-                                       @Injectable BaseTableRef tableRef7, 
@Injectable OlapScanNode scanNode7,
-                                       @Injectable TupleDescriptor 
tupleDescriptor1,
-                                       @Injectable TupleDescriptor 
tupleDescriptor2,
-                                       @Injectable TupleDescriptor 
tupleDescriptor3,
-                                       @Injectable TupleDescriptor 
tupleDescriptor4,
-                                       @Injectable TupleDescriptor 
tupleDescriptor5,
-                                       @Injectable TupleDescriptor 
tupleDescriptor6,
-                                       @Injectable TupleDescriptor 
tupleDescriptor7,
-                                       @Injectable SlotDescriptor 
slotDescriptor1,
-                                       @Injectable SlotDescriptor 
slotDescriptor2,
-                                       @Injectable SlotDescriptor 
slotDescriptor3,
-                                       @Injectable SlotDescriptor 
slotDescriptor4,
-                                       @Injectable SlotDescriptor 
slotDescriptor5,
-                                       @Injectable SlotDescriptor 
slotDescriptor6,
-                                       @Injectable SlotDescriptor 
slotDescriptor7,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate1,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate2,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate3,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate4,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate5,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate6,
-                                       @Injectable BinaryPredicate 
eqBinaryPredicate7,
-                                       @Injectable SlotRef eqT1Slot1,
-                                       @Injectable SlotRef eqT2Slot2,
-                                       @Injectable SlotRef eqT3Slot3,
-                                       @Injectable SlotRef eqT4Slot4,
-                                       @Injectable SlotRef eqT5Slot5,
-                                       @Injectable SlotRef eqT6Slot6,
-                                       @Injectable SlotRef eqT7Slot7,
-                                       @Tested ExprSubstitutionMap 
exprSubstitutionMap) {
-        Pair<TableRef, PlanNode> pair1 = Pair.of(tableRef1, scanNode1);
-        Pair<TableRef, PlanNode> pair2 = Pair.of(tableRef2, scanNode2);
-        Pair<TableRef, PlanNode> pair3 = Pair.of(tableRef3, scanNode3);
-        Pair<TableRef, PlanNode> pair4 = Pair.of(tableRef4, scanNode4);
-        Pair<TableRef, PlanNode> pair5 = Pair.of(tableRef5, scanNode5);
-        Pair<TableRef, PlanNode> pair6 = Pair.of(tableRef6, scanNode6);
-        Pair<TableRef, PlanNode> pair7 = Pair.of(tableRef7, scanNode7);
-        List<Pair<TableRef, PlanNode>> refPlans = Lists.newArrayList();
-        refPlans.add(pair1);
-        refPlans.add(pair2);
-        refPlans.add(pair3);
-        refPlans.add(pair5);
-        refPlans.add(pair4);
-        refPlans.add(pair6);
-        refPlans.add(pair7);
-
-        TupleId tupleId1 = new TupleId(1);
-        TupleId tupleId2 = new TupleId(2);
-        TupleId tupleId3 = new TupleId(3);
-        TupleId tupleId4 = new TupleId(4);
-        TupleId tupleId5 = new TupleId(5);
-        TupleId tupleId6 = new TupleId(6);
-        TupleId tupleId7 = new TupleId(7);
-        List<TupleId> tupleIds1 = Lists.newArrayList(tupleId1);
-        List<TupleId> tupleIds2 = Lists.newArrayList(tupleId2);
-        List<TupleId> tupleIds3 = Lists.newArrayList(tupleId3);
-        List<TupleId> tupleIds4 = Lists.newArrayList(tupleId4);
-        List<TupleId> tupleIds5 = Lists.newArrayList(tupleId5);
-        List<TupleId> tupleIds6 = Lists.newArrayList(tupleId6);
-        List<TupleId> tupleIds7 = Lists.newArrayList(tupleId7);
-        List<TupleId> tupleIds213 = Lists.newArrayList(tupleId2, tupleId1, 
tupleId3);
-        List<TupleId> tupleIds21345 = new ArrayList<>();
-        tupleIds21345.addAll(tupleIds213);
-        tupleIds21345.add(tupleId4);
-        tupleIds21345.add(tupleId5);
-        List<TupleId> tupleIds213456 = Lists.newArrayList(tupleId2, tupleId1, 
tupleId3, tupleId4, tupleId5, tupleId6);
-
-        List<SlotDescriptor> slotDescriptors1 = Lists.newArrayList();
-        slotDescriptors1.add(slotDescriptor1);
-        List<SlotDescriptor> slotDescriptors2 = Lists.newArrayList();
-        slotDescriptors2.add(slotDescriptor2);
-        List<Expr> eqConjuncts1 = Lists.newArrayList();
-        eqConjuncts1.add(eqBinaryPredicate1);
-        List<Expr> eqConjuncts2 = Lists.newArrayList();
-        eqConjuncts2.add(eqBinaryPredicate2);
-        List<Expr> eqConjuncts3 = Lists.newArrayList();
-        eqConjuncts3.add(eqBinaryPredicate3);
-
-
-        new Expectations() {
-            {
-                tableRef1.isAnalyzed();
-                result = true;
-                tableRef2.isAnalyzed();
-                result = true;
-                tableRef4.isAnalyzed();
-                result = true;
-                tableRef5.isAnalyzed();
-                result = true;
-                tableRef7.isAnalyzed();
-                result = true;
-                scanNode1.getCardinality();
-                result = 1;
-                scanNode2.getCardinality();
-                result = 2;
-                scanNode3.getCardinality();
-                result = 3;
-                scanNode4.getCardinality();
-                result = 4;
-                scanNode5.getCardinality();
-                result = 5;
-                scanNode6.getCardinality();
-                result = 6;
-                scanNode7.getCardinality();
-                result = 7;
-                tableRef1.getDesc();
-                result = tupleDescriptor1;
-                tupleDescriptor1.getMaterializedSlots();
-                result = slotDescriptors1;
-                tableRef2.getDesc();
-                result = tupleDescriptor2;
-                tupleDescriptor2.getMaterializedSlots();
-                result = slotDescriptors2;
-                tableRef3.getDesc();
-                result = tupleDescriptor3;
-                tupleDescriptor3.getMaterializedSlots();
-                result = Lists.newArrayList(slotDescriptor3);
-                tableRef4.getDesc();
-                result = tupleDescriptor4;
-                tupleDescriptor4.getMaterializedSlots();
-                result = Lists.newArrayList(slotDescriptor4);
-                tableRef5.getDesc();
-                result = tupleDescriptor5;
-                tupleDescriptor5.getMaterializedSlots();
-                result = Lists.newArrayList(slotDescriptor5);
-                tableRef6.getDesc();
-                result = tupleDescriptor6;
-                tupleDescriptor6.getMaterializedSlots();
-                result = Lists.newArrayList(slotDescriptor6);
-                tableRef7.getDesc();
-                result = tupleDescriptor7;
-                tupleDescriptor7.getMaterializedSlots();
-                result = Lists.newArrayList(slotDescriptor7);
-                analyzer.getEqJoinConjuncts(tupleIds7, tupleIds1);
-                result = eqConjuncts1;
-                eqBinaryPredicate1.getChild(0);
-                result = eqT7Slot7;
-                eqT7Slot7.isBoundByTupleIds(tupleIds7);
-                result = true;
-                eqBinaryPredicate1.getChild(1);
-                result = eqT1Slot1;
-                eqT1Slot1.isBoundByTupleIds(tupleIds1);
-                result = true;
-                analyzer.getEqJoinConjuncts(Lists.newArrayList(tupleId2, 
tupleId1), tupleIds3);
-                result = eqConjuncts2;
-                analyzer.getEqJoinConjuncts(tupleIds213, tupleIds5);
-                result = Lists.newArrayList(eqBinaryPredicate4);
-                analyzer.getEqJoinConjuncts(tupleIds213, tupleIds4);
-                result = Lists.newArrayList(eqBinaryPredicate5);
-                analyzer.getEqJoinConjuncts(tupleIds21345, tupleIds6);
-                result = Lists.newArrayList(eqBinaryPredicate6);
-                eqBinaryPredicate6.getChild(0);
-                result = eqT5Slot5;
-                eqBinaryPredicate6.getChild(1);
-                result = eqT6Slot6;
-                eqT5Slot5.isBoundByTupleIds(tupleIds21345);
-                result = true;
-                eqT6Slot6.isBoundByTupleIds(tupleIds6);
-                result = true;
-                analyzer.getEqJoinConjuncts(tupleIds213456, tupleIds7);
-                result = Lists.newArrayList(eqBinaryPredicate7);
-                eqBinaryPredicate7.getChild(0);
-                result = eqT6Slot6;
-                eqBinaryPredicate7.getChild(1);
-                result = eqT7Slot7;
-                eqT6Slot6.isBoundByTupleIds(tupleIds213456);
-                result = true;
-                eqT7Slot7.isBoundByTupleIds(tupleIds7);
-                result = true;
-                scanNode1.getTblRefIds();
-                result = Lists.newArrayList(tupleIds1);
-                scanNode2.getTblRefIds();
-                result = Lists.newArrayList(tupleIds2);
-                scanNode3.getTblRefIds();
-                result = Lists.newArrayList(tupleIds3);
-                scanNode4.getTblRefIds();
-                result = Lists.newArrayList(tupleId4);
-                scanNode5.getTblRefIds();
-                result = Lists.newArrayList(tupleId5);
-                scanNode6.getTblRefIds();
-                result = Lists.newArrayList(tupleId6);
-                scanNode7.getTblRefIds();
-                result = Lists.newArrayList(tupleId7);
-
-                eqT2Slot2.isBoundByTupleIds(Lists.newArrayList(tupleId2, 
tupleId1));
-                result = true;
-                eqBinaryPredicate2.getChild(0);
-                result = eqT2Slot2;
-                eqBinaryPredicate2.getChild(1);
-                result = eqT3Slot3;
-                eqT3Slot3.isBoundByTupleIds(tupleIds3);
-                result = true;
-                eqBinaryPredicate4.getChild(0);
-                result = eqT3Slot3;
-                eqBinaryPredicate4.getChild(1);
-                result = eqT5Slot5;
-                eqT3Slot3.isBoundByTupleIds(tupleIds213);
-                result = true;
-                eqT5Slot5.isBoundByTupleIds(Lists.newArrayList(tupleId5));
-                result = true;
-                eqBinaryPredicate5.getChild(0);
-                result = eqT3Slot3;
-                eqBinaryPredicate5.getChild(1);
-                result = eqT4Slot4;
-                eqT4Slot4.isBoundByTupleIds(Lists.newArrayList(tupleId4));
-                result = true;
-                scanNode1.getTupleIds();
-                result = tupleIds1;
-                scanNode2.getTupleIds();
-                result = tupleIds2;
-                scanNode3.getTupleIds();
-                result = tupleIds3;
-                scanNode4.getTupleIds();
-                result = tupleIds4;
-                scanNode5.getTupleIds();
-                result = tupleIds5;
-                scanNode6.getTupleIds();
-                result = tupleIds6;
-                scanNode7.getTupleIds();
-                result = tupleIds7;
-                scanNode1.getOutputSmap();
-                result = null;
-                scanNode2.getOutputSmap();
-                result = null;
-                scanNode3.getOutputSmap();
-                result = null;
-                scanNode4.getOutputSmap();
-                result = null;
-                scanNode5.getOutputSmap();
-                result = null;
-                scanNode6.getOutputSmap();
-                result = null;
-                scanNode7.getOutputSmap();
-                result = null;
-                tableRef1.getUniqueAlias();
-                result = "t1";
-                tableRef2.getUniqueAlias();
-                result = "t2";
-                tableRef3.getUniqueAlias();
-                result = "t3";
-                tableRef4.getUniqueAlias();
-                result = "t4";
-                tableRef5.getUniqueAlias();
-                result = "t5";
-                tableRef6.getUniqueAlias();
-                result = "t6";
-                tableRef7.getUniqueAlias();
-                result = "t7";
-                tableRef1.getJoinOp();
-                result = JoinOperator.INNER_JOIN;
-                tableRef2.getJoinOp();
-                result = JoinOperator.INNER_JOIN;
-                tableRef3.getJoinOp();
-                result = JoinOperator.RIGHT_OUTER_JOIN;
-                tableRef4.getJoinOp();
-                result = JoinOperator.INNER_JOIN;
-                tableRef5.getJoinOp();
-                result = JoinOperator.INNER_JOIN;
-                tableRef6.getJoinOp();
-                result = JoinOperator.LEFT_OUTER_JOIN;
-                tableRef7.getJoinOp();
-                result = JoinOperator.INNER_JOIN;
-            }
-        };
-        new MockUp<ExprSubstitutionMap>() {
-            @Mock
-            public ExprSubstitutionMap compose(ExprSubstitutionMap f, 
ExprSubstitutionMap g,
-                                               Analyzer analyzer) {
-                return exprSubstitutionMap;
-            }
-
-            @Mock
-            public ExprSubstitutionMap combine(ExprSubstitutionMap f, 
ExprSubstitutionMap g) {
-                return exprSubstitutionMap;
-            }
-        };
-
-        SingleNodePlanner singleNodePlanner = new SingleNodePlanner(context);
-        PlanNode cheapestJoinNode = Deencapsulation.invoke(singleNodePlanner, 
"createCheapestJoinPlan", analyzer, refPlans);
-        Assert.assertEquals(2, cheapestJoinNode.getChildren().size());
-        Assert.assertEquals(Lists.newArrayList(tupleId2, tupleId1, tupleId3, 
tupleId4, tupleId5, tupleId6, tupleId7),
-                cheapestJoinNode.getTupleIds());
-    }
-
     /*
     Query: select * from t1, t3, t2, t4 where (all of inner join condition)
     Original Query: select * from test1, test3, test2, test4
diff --git 
a/regression-test/data/correctness_p0/test_inlineview_with_project.out 
b/regression-test/data/correctness_p0/test_inlineview_with_project.out
new file mode 100644
index 0000000000..72d126351a
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_inlineview_with_project.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+1
+
diff --git 
a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out
 
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out
index 3c17fae7af..4333dfa9ac 100644
--- 
a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out
+++ 
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.out
@@ -1,80 +1,16 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
--- !select --
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      false   10      20      30      4444444444444   55555555555     0.1     
0.222   3333.33 c       varchar1        string1 2022-12-01      2022-12-01      
2022-12-01T22:23:23     2022-12-01T22:23:24.999999      not null
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      false   11      21      33      4444444444444   55555555555     0.1     
0.222   3333.33 c       varchar1        string1 2022-12-01      2022-12-01      
2022-12-01T22:23:23     2022-12-01T22:23:24.999999      not null
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      true    11      12      13      1444444444444   1555555555      1.1     
1.222   13333.33        d       varchar2        string2 2022-12-02      
2022-12-02      2022-12-02T22:23:23     2022-12-02T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      false   21      22      23      2444444444444   255555555       2.1     
2.222   23333.33        f       varchar3        string3 2022-12-03      
2022-12-03      2022-12-03T22:23:23     2022-12-03T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      true    31      32      33      3444444444444   3555555555      3.1     
3.222   33333.33        l       varchar3        string3 2022-12-03      
2022-12-03      2022-12-03T22:23:23     2022-12-03T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      false   10      20      30      944444444444    9555555555      9.1     
9.222   93333.33        p       varchar9        string9 2022-12-09      
2022-12-09      2022-12-09T22:23:23     2022-12-09T22:23:24.999999      not null
-
--- !select --
-[0, 1] [21, 11, 31, 10]        [21, 12, 20, 22, 32]    [30, 13, 23, 33]        
[2444444444444, 4444444444444, 3444444444444, 1444444444444, 944444444444]      
[1555555555, 3555555555, 9555555555, 255555555, 55555555555]    [0.1, 1.1, 3.1, 
9.1, 2.1]       [3.222, 2.222, 9.222, 1.222, 0.222]     [23333.33, 3333.33, 
33333.33, 93333.33, 13333.33]       ['c', 'p', 'l', 'd', 'f']       
['varchar3', 'varchar1', 'varchar2', 'varchar9']        ['string9', 'string2', 
'string1', 'string3']    [2022-12-03, 2022-12-09, 2022-12-02, 2022-12-01]       
 [2022-12-01,  [...]
-
--- !select --
-[0, 0, 1, 0, 1, 0]     [10, 11, 11, 21, 31, 10]        [20, 21, 12, 22, 32, 
20]        [30, 33, 13, 23, 33, 30]        [4444444444444, 4444444444444, 
1444444444444, 2444444444444, 3444444444444, 944444444444]       [55555555555, 
55555555555, 1555555555, 255555555, 3555555555, 9555555555]       [0.1, 0.1, 
1.1, 2.1, 3.1, 9.1]  [0.222, 0.222, 1.222, 2.222, 3.222, 9.222]      [3333.33, 
3333.33, 13333.33, 23333.33, 33333.33, 93333.33]      ['c', 'c', 'd', 'f', 'l', 
'p']  ['varchar1', 'varchar1', 'varchar2', 'varchar3', 'varchar3', 'varchar9 
[...]
-
 -- !select --
 1      1       1       1       1       3       1       2       1       1       
1       1       1       2       1       1       1
 
 -- !select --
 1      1       1       1       1       3       1       2       1       1       
1       1       1       2       1       1       1
 
--- !select --
-1      [0, 1]  [21, 11, 31, 10]        [21, 12, 20, 22, 32]    [30, 13, 23, 
33]        [2444444444444, 4444444444444, 3444444444444, 1444444444444, 
944444444444]      [1555555555, 3555555555, 9555555555, 255555555, 55555555555] 
   [0.1, 1.1, 3.1, 9.1, 2.1]       [3.222, 2.222, 9.222, 1.222, 0.222]     
[23333.33, 3333.33, 33333.33, 93333.33, 13333.33]       ['c', 'p', 'l', 'd', 
'f']       ['varchar3', 'varchar1', 'varchar2', 'varchar9']        ['string9', 
'string2', 'string1', 'string3']    [2022-12-03, 2022-12-09, 2022-12-02, 
2022-12-01]        [2022-12-01 [...]
-
--- !select --
-1      1       1       1       1       1       3       1       2       1       
1       1       1       1       2       1       1       1
-
--- !select --
-1      [0, 0, 1, 0, 1, 0]      [10, 11, 11, 21, 31, 10]        [20, 21, 12, 
22, 32, 20]        [30, 33, 13, 23, 33, 30]        [4444444444444, 
4444444444444, 1444444444444, 2444444444444, 3444444444444, 944444444444]       
[55555555555, 55555555555, 1555555555, 255555555, 3555555555, 9555555555]       
[0.1, 0.1, 1.1, 2.1, 3.1, 9.1]  [0.222, 0.222, 1.222, 2.222, 3.222, 9.222]      
[3333.33, 3333.33, 13333.33, 23333.33, 33333.33, 93333.33]      ['c', 'c', 'd', 
'f', 'l', 'p']  ['varchar1', 'varchar1', 'varchar2', 'varchar3', 'varchar3', 
'varcha [...]
-
--- !select --
-1      1       1       1       1       1       3       1       2       1       
1       1       1       1       2       1       1       1
-
--- !select --
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      false   10      20      30      4444444444444   55555555555     0.1     
0.222   3333.33 c       varchar1        string1 2022-12-01      2022-12-01      
2022-12-01T22:23:23     2022-12-01T22:23:24.999999      not null
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      false   11      21      33      4444444444444   55555555555     0.1     
0.222   3333.33 c       varchar1        string1 2022-12-01      2022-12-01      
2022-12-01T22:23:23     2022-12-01T22:23:24.999999      not null
-1      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-1      true    11      12      13      1444444444444   1555555555      1.1     
1.222   13333.33        d       varchar2        string2 2022-12-02      
2022-12-02      2022-12-02T22:23:23     2022-12-02T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      false   21      22      23      2444444444444   255555555       2.1     
2.222   23333.33        f       varchar3        string3 2022-12-03      
2022-12-03      2022-12-03T22:23:23     2022-12-03T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      true    31      32      33      3444444444444   3555555555      3.1     
3.222   33333.33        l       varchar3        string3 2022-12-03      
2022-12-03      2022-12-03T22:23:23     2022-12-03T22:23:24.999999      not null
-2      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N      \N      \N      \N      \N      not null
-2      false   10      20      30      944444444444    9555555555      9.1     
9.222   93333.33        p       varchar9        string9 2022-12-09      
2022-12-09      2022-12-09T22:23:23     2022-12-09T22:23:24.999999      not null
-
--- !select --
-[0, 1] [21, 11, 31, 10]        [21, 12, 20, 22, 32]    [30, 13, 23, 33]        
[2444444444444, 4444444444444, 3444444444444, 1444444444444, 944444444444]      
[1555555555, 3555555555, 9555555555, 255555555, 55555555555]    [0.1, 1.1, 3.1, 
9.1, 2.1]       [3.222, 2.222, 9.222, 1.222, 0.222]     [23333.33, 3333.33, 
33333.33, 93333.33, 13333.33]       ['c', 'p', 'l', 'd', 'f']       
['varchar3', 'varchar1', 'varchar2', 'varchar9']        ['string9', 'string2', 
'string1', 'string3']    [2022-12-03, 2022-12-09, 2022-12-02, 2022-12-01]       
 [2022-12-01,  [...]
-
--- !select --
-[0, 0, 1, 0, 1, 0]     [10, 11, 11, 21, 31, 10]        [20, 21, 12, 22, 32, 
20]        [30, 33, 13, 23, 33, 30]        [4444444444444, 4444444444444, 
1444444444444, 2444444444444, 3444444444444, 944444444444]       [55555555555, 
55555555555, 1555555555, 255555555, 3555555555, 9555555555]       [0.1, 0.1, 
1.1, 2.1, 3.1, 9.1]  [0.222, 0.222, 1.222, 2.222, 3.222, 9.222]      [3333.33, 
3333.33, 13333.33, 23333.33, 33333.33, 93333.33]      ['c', 'c', 'd', 'f', 'l', 
'p']  ['varchar1', 'varchar1', 'varchar2', 'varchar3', 'varchar3', 'varchar9 
[...]
-
 -- !select --
 1      1       1       1       1       3       1       2       1       1       
1       1       1       2       1       1       1
 
 -- !select --
 1      1       1       1       1       3       1       2       1       1       
1       1       1       2       1       1       1
 
--- !select --
-1      [0, 1]  [21, 11, 31, 10]        [21, 12, 20, 22, 32]    [30, 13, 23, 
33]        [2444444444444, 4444444444444, 3444444444444, 1444444444444, 
944444444444]      [1555555555, 3555555555, 9555555555, 255555555, 55555555555] 
   [0.1, 1.1, 3.1, 9.1, 2.1]       [3.222, 2.222, 9.222, 1.222, 0.222]     
[23333.33, 3333.33, 33333.33, 93333.33, 13333.33]       ['c', 'p', 'l', 'd', 
'f']       ['varchar3', 'varchar1', 'varchar2', 'varchar9']        ['string9', 
'string2', 'string1', 'string3']    [2022-12-03, 2022-12-09, 2022-12-02, 
2022-12-01]        [2022-12-01 [...]
-
--- !select --
-1      1       1       1       1       1       3       1       2       1       
1       1       1       1       2       1       1       1
-
--- !select --
-1      [0, 0, 1, 0, 1, 0]      [10, 11, 11, 21, 31, 10]        [20, 21, 12, 
22, 32, 20]        [30, 33, 13, 23, 33, 30]        [4444444444444, 
4444444444444, 1444444444444, 2444444444444, 3444444444444, 944444444444]       
[55555555555, 55555555555, 1555555555, 255555555, 3555555555, 9555555555]       
[0.1, 0.1, 1.1, 2.1, 3.1, 9.1]  [0.222, 0.222, 1.222, 2.222, 3.222, 9.222]      
[3333.33, 3333.33, 13333.33, 23333.33, 33333.33, 93333.33]      ['c', 'c', 'd', 
'f', 'l', 'p']  ['varchar1', 'varchar1', 'varchar2', 'varchar3', 'varchar3', 
'varcha [...]
-
--- !select --
-1      1       1       1       1       1       3       1       2       1       
1       1       1       1       2       1       1       1
-
 -- !select43 --
 [10, 8]
 
diff --git 
a/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy 
b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy
new file mode 100644
index 0000000000..dbf7cd348a
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy
@@ -0,0 +1,80 @@
+// 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.
+
+suite("test_inlineview_with_project") {
+    sql """
+        drop table if exists cir_1756_t1;
+    """
+
+    sql """
+        drop table if exists cir_1756_t2;
+    """
+    
+    sql """
+        create table cir_1756_t1 (`date` date not null)
+        ENGINE=OLAP
+        DISTRIBUTED BY HASH(`date`) BUCKETS 5
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        );
+    """
+
+    sql """
+        create table cir_1756_t2 ( `date` date not null )
+        ENGINE=OLAP
+        DISTRIBUTED BY HASH(`date`) BUCKETS 5
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        );
+    """
+
+    sql """
+        insert into cir_1756_t1 values("2020-02-02");
+    """
+
+    sql """
+        insert into cir_1756_t2 values("2020-02-02");
+    """
+
+    qt_select """
+        WITH t0 AS(
+            SELECT report.date1 AS date2 FROM(
+                SELECT DATE_FORMAT(date, '%Y%m%d') AS date1 FROM cir_1756_t1
+            ) report GROUP BY report.date1
+            ),
+            t3 AS(
+                SELECT date_format(date, '%Y%m%d') AS `date3`
+                FROM `cir_1756_t2`
+            )
+        SELECT row_number() OVER(ORDER BY date2)
+        FROM(
+            SELECT t0.date2 FROM t0 LEFT JOIN t3 ON t0.date2 = t3.date3
+        ) tx;
+    """
+
+    sql """
+        drop table if exists cir_1756_t1;
+    """
+
+    sql """
+        drop table if exists cir_1756_t2;
+    """
+}
diff --git 
a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy
 
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy
index d09b09797b..f2b19a7e4a 100644
--- 
a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy
@@ -107,11 +107,11 @@ suite("test_aggregate_collect") {
             '2022-12-09', '2022-12-09', '2022-12-09 22:23:23', '2022-12-09 
22:23:24.999999', 'not null')
     """
 
-    qt_select """
+    sql """
         SELECT * FROM ${tableName}
     """
 
-    qt_select """
+    sql """
         SELECT
             collect_set(c_bool),
             collect_set(c_tinyint),
@@ -134,7 +134,7 @@ suite("test_aggregate_collect") {
             ${tableName}
     """
 
-    qt_select """
+    sql """
         SELECT
             collect_list(c_bool),
             collect_list(c_tinyint),
@@ -304,10 +304,10 @@ suite("test_aggregate_collect") {
             ${tableName}
     """
 
-    qt_select "SELECT * FROM ${tableCTAS1}"
-    qt_select "SELECT * FROM ${tableCTAS2}"
-    qt_select "SELECT * FROM ${tableCTAS3}"
-    qt_select "SELECT * FROM ${tableCTAS4}"
+    sql "SELECT * FROM ${tableCTAS1}"
+    sql "SELECT * FROM ${tableCTAS2}"
+    sql "SELECT * FROM ${tableCTAS3}"
+    sql "SELECT * FROM ${tableCTAS4}"
 
     sql "DROP TABLE IF EXISTS ${tableName}"
     sql "DROP TABLE IF EXISTS ${tableCTAS1}"
@@ -402,11 +402,11 @@ suite("test_aggregate_collect") {
             '2022-12-09', '2022-12-09', '2022-12-09 22:23:23', '2022-12-09 
22:23:24.999999', 'not null')
     """
 
-    qt_select """
+    sql """
         SELECT * FROM ${tableName_11}
     """
 
-    qt_select """
+    sql """
         SELECT
             group_uniq_array(c_bool),
             group_uniq_array(c_tinyint),
@@ -429,7 +429,7 @@ suite("test_aggregate_collect") {
             ${tableName_11}
     """
 
-    qt_select """
+    sql """
         SELECT
             group_array(c_bool),
             group_array(c_tinyint),
@@ -598,10 +598,10 @@ suite("test_aggregate_collect") {
             ${tableName_11}
     """
 
-    qt_select "SELECT * FROM ${tableCTAS1_11}"
-    qt_select "SELECT * FROM ${tableCTAS2_11}"
-    qt_select "SELECT * FROM ${tableCTAS3_11}"
-    qt_select "SELECT * FROM ${tableCTAS4_11}"
+    sql "SELECT * FROM ${tableCTAS1_11}"
+    sql "SELECT * FROM ${tableCTAS2_11}"
+    sql "SELECT * FROM ${tableCTAS3_11}"
+    sql "SELECT * FROM ${tableCTAS4_11}"
 
     sql "DROP TABLE IF EXISTS ${tableName_11}"
     sql "DROP TABLE IF EXISTS ${tableCTAS1_11}"


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


Reply via email to