Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
import org.apache.doris.nereids.trees.plans.algebra.Relation;
import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalJoin;
import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalPlan;
import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalSort;
import org.apache.doris.nereids.trees.plans.physical.PhysicalAssertNumRows;
import org.apache.doris.nereids.trees.plans.physical.PhysicalBlackholeSink;
Expand Down Expand Up @@ -1656,9 +1657,7 @@ public PlanFragment visitPhysicalFilter(PhysicalFilter<? extends Plan> filter, P
PlanNode planNode = inputFragment.getPlanRoot();
// the three nodes don't support conjuncts, need create a SelectNode to filter data
if (planNode instanceof ExchangeNode || planNode instanceof SortNode || planNode instanceof UnionNode) {
SelectNode selectNode = new SelectNode(context.nextPlanNodeId(), planNode);
selectNode.setNereidsId(filter.getId());
context.getNereidsIdToPlanNodeIdMap().put(filter.getId(), selectNode.getId());
SelectNode selectNode = createSelectNode(filter, planNode, context);
addConjunctsToPlanNode(filter, selectNode, context);
addPlanRoot(inputFragment, selectNode, filter);
} else {
Expand All @@ -1669,12 +1668,10 @@ public PlanFragment visitPhysicalFilter(PhysicalFilter<? extends Plan> filter, P
|| CollectionUtils.isNotEmpty(planNode.getProjectList())
// already have limit on this node, filter need execute after limit, so need a new node
|| planNode.hasLimit()) {
planNode = new SelectNode(context.nextPlanNodeId(), planNode);
planNode.setNereidsId(filter.getId());
planNode = createSelectNode(filter, planNode, context);
// NOTE: can't collect planNode.getId() on filter's child, such as scan node
// since if the filter is embedded into scan, the id mapping relation is not correct
// i.e, the physical filter's nereids's id will be mapped to final plan's scan node
context.getNereidsIdToPlanNodeIdMap().put(filter.getId(), planNode.getId());
addPlanRoot(inputFragment, planNode, filter);
}
addConjunctsToPlanNode(filter, planNode, context);
Expand All @@ -1688,6 +1685,16 @@ public PlanFragment visitPhysicalFilter(PhysicalFilter<? extends Plan> filter, P
return inputFragment;
}

private SelectNode createSelectNode(AbstractPhysicalPlan physicalPlan, PlanNode child,
PlanTranslatorContext context) {
SelectNode selectNode = new SelectNode(context.nextPlanNodeId(), child);
selectNode.setNereidsId(physicalPlan.getId());
context.getNereidsIdToPlanNodeIdMap().put(physicalPlan.getId(), selectNode.getId());
selectNode.setDistributeExprLists(getDistributeExpr(physicalPlan));
selectNode.setChildrenDistributeExprLists(getDistributeExprs(physicalPlan.child(0)));
return selectNode;
}

@Override
public PlanFragment visitPhysicalGenerate(PhysicalGenerate<? extends Plan> generate,
PlanTranslatorContext context) {
Expand Down Expand Up @@ -2325,9 +2332,7 @@ public PlanFragment visitPhysicalProject(PhysicalProject<? extends Plan> project
PlanNode inputPlanNode = inputFragment.getPlanRoot();
// this means already have project on this node, filter need execute after project, so need a new node
if (CollectionUtils.isNotEmpty(inputPlanNode.getProjectList())) {
SelectNode selectNode = new SelectNode(context.nextPlanNodeId(), inputPlanNode);
selectNode.setNereidsId(project.getId());
context.getNereidsIdToPlanNodeIdMap().put(project.getId(), selectNode.getId());
SelectNode selectNode = createSelectNode(project, inputPlanNode, context);
addPlanRoot(inputFragment, selectNode, project);
inputPlanNode = selectNode;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_over_analytic_shuffle_join --
10 45 55 1045

-- !select_over_aligned_analytic_shuffle_join --
10 45 55 1045
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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_select_analytic_shuffle_join") {
sql "DROP TABLE IF EXISTS select_analytic_join_left"
sql "DROP TABLE IF EXISTS select_analytic_join_right"

sql """CREATE TABLE select_analytic_join_left (
k INT, v INT
) ENGINE=OLAP DUPLICATE KEY(k)
DISTRIBUTED BY HASH(k) BUCKETS 10
PROPERTIES ("replication_num"="1")"""
sql """CREATE TABLE select_analytic_join_right (
k INT, w INT
) ENGINE=OLAP DUPLICATE KEY(k)
DISTRIBUTED BY HASH(k) BUCKETS 10
PROPERTIES ("replication_num"="1")"""

sql """INSERT INTO select_analytic_join_left VALUES
(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10)"""
sql """INSERT INTO select_analytic_join_right VALUES
(0,100),(1,101),(2,102),(3,103),(4,104),
(5,105),(6,106),(7,107),(8,108),(9,109)"""

def variables = "enable_local_shuffle_planner=true,enable_local_shuffle=true," +
"enable_bucket_shuffle_join=false,ignore_storage_data_distribution=true," +
"parallel_pipeline_task_num=3,enable_sql_cache=false"

order_qt_select_over_analytic_shuffle_join """SELECT /*+SET_VAR(${variables})*/
COUNT(*), SUM(s.k), SUM(s.running_v), SUM(d.w)
FROM (
SELECT k, SUM(v) OVER (PARTITION BY v ORDER BY v
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_v,
random(0) AS r
FROM select_analytic_join_left
) s JOIN [shuffle] select_analytic_join_right d ON s.k=d.k
WHERE s.r < 2.0"""

order_qt_select_over_aligned_analytic_shuffle_join """SELECT /*+SET_VAR(${variables})*/
COUNT(*), SUM(s.k), SUM(s.running_v), SUM(d.w)
FROM (
SELECT k, SUM(v) OVER (PARTITION BY k ORDER BY k
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_v,
random(0) AS r
FROM select_analytic_join_left
) s JOIN [shuffle] select_analytic_join_right d ON s.k=d.k
WHERE s.r < 2.0"""
}
Loading