diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java index 1aa98bb492..df314d7f37 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java @@ -212,9 +212,17 @@ public class PlanTranslatorContext { exprIdToColumnRef.put(exprId, columnRefExpr); } + /** + * merge source fragment info into target fragment. + * include runtime filter info and fragment attribute. + */ public void mergePlanFragment(PlanFragment srcFragment, PlanFragment targetFragment) { srcFragment.getTargetRuntimeFilterIds().forEach(targetFragment::setTargetRuntimeFilterIds); srcFragment.getBuilderRuntimeFilterIds().forEach(targetFragment::setBuilderRuntimeFilterIds); + targetFragment.setHasColocatePlanNode(targetFragment.hasColocatePlanNode() + || srcFragment.hasColocatePlanNode()); + targetFragment.setHasNullAwareLeftAntiJoin(targetFragment.isHasNullAwareLeftAntiJoin() + || srcFragment.isHasNullAwareLeftAntiJoin()); this.planFragments.remove(srcFragment); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/MultiCastPlanFragment.java b/fe/fe-core/src/main/java/org/apache/doris/planner/MultiCastPlanFragment.java index e52bbb0557..4b2258c8a2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/MultiCastPlanFragment.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/MultiCastPlanFragment.java @@ -31,6 +31,8 @@ public class MultiCastPlanFragment extends PlanFragment { public MultiCastPlanFragment(PlanFragment planFragment) { super(planFragment.getFragmentId(), planFragment.getPlanRoot(), planFragment.getDataPartition(), planFragment.getBuilderRuntimeFilterIds(), planFragment.getTargetRuntimeFilterIds()); + this.hasColocatePlanNode = planFragment.hasColocatePlanNode; + this.hasNullAwareLeftAntiJoin = planFragment.hasNullAwareLeftAntiJoin; this.outputPartition = DataPartition.RANDOM; this.children.addAll(planFragment.getChildren()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java index d95343d0e5..f24c16561a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java @@ -147,9 +147,9 @@ public class PlanFragment extends TreeNode { private int bucketNum; // has colocate plan node - private boolean hasColocatePlanNode = false; + protected boolean hasColocatePlanNode = false; - private boolean hasNullAwareLeftAntiJoin = false; + protected boolean hasNullAwareLeftAntiJoin = false; private TResultSinkType resultSinkType = TResultSinkType.MYSQL_PROTOCAL; diff --git a/regression-test/data/nereids_p0/colocate/test_multi_cast_colocate.out b/regression-test/data/nereids_p0/colocate/test_multi_cast_colocate.out new file mode 100644 index 0000000000..0656c42045 --- /dev/null +++ b/regression-test/data/nereids_p0/colocate/test_multi_cast_colocate.out @@ -0,0 +1,103 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test -- +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 + diff --git a/regression-test/data/nereids_p0/colocate/test_set_operation_colocate.out b/regression-test/data/nereids_p0/colocate/test_set_operation_colocate.out new file mode 100644 index 0000000000..2e735a3b03 --- /dev/null +++ b/regression-test/data/nereids_p0/colocate/test_set_operation_colocate.out @@ -0,0 +1,10 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test -- +1 +1 +1 +1 +1 +1 +1 + diff --git a/regression-test/suites/nereids_p0/colocate/test_multi_cast_colocate.groovy b/regression-test/suites/nereids_p0/colocate/test_multi_cast_colocate.groovy new file mode 100644 index 0000000000..92cc3e8eb9 --- /dev/null +++ b/regression-test/suites/nereids_p0/colocate/test_multi_cast_colocate.groovy @@ -0,0 +1,59 @@ +// 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. + +// this suite is for creating table with timestamp datatype in defferent +// case. For example: 'year' and 'Year' datatype should also be valid in definition + +suite("test_multi_cast_colocate") { + sql 'set enable_nereids_planner=true' + sql 'set enable_fallback_to_original_planner=false' + sql 'set enable_nereids_dml=true' + + sql """ + drop table if exists test_multi_cast_colocate + """ + + sql """ + create table test_multi_cast_colocate ( + `c1` int, + `c2` varchar(10) , + `pk` int + ) engine=olap + distributed by hash(pk) buckets 10 + properties("replication_num" = "1"); + """ + + sql """ + insert into test_multi_cast_colocate(pk,c1,c2) values (0,null,'m'),(1,1,"me"),(2,null,'p'),(3,null,"and"),(4,7,'v'),(5,3,"what"),(6,5,'j'),(7,null,"he's"),(8,null,'q'),(9,8,"like"),(10,null,"me"),(11,null,"from"),(12,4,'r'),(13,null,"now"),(14,null,'q'),(15,2,"me"),(16,6,'y'),(17,4,"on"),(18,null,'d'),(19,7,"really"),(20,2,"for"),(21,null,'a'),(22,9,'j'),(23,null,"tell"),(24,6,'f'),(25,7,'n'),(26,3,'g'),(27,null,"on"),(28,0,'l'),(29,2,'n'),(30,null,"her"),(31,null,"got"),(32,8,'i'),(33,7,'g'),(34,null,"from"),(35,null,'j'),(36,null,"did"),(37,null,'v'),(38,9,"could"),(39,null,"if"),(40,null,"no"),(41,1,"me"),(42,3,"good"),(43,8,"i"),(44,9,'e'),(45,null,"here"),(46,3,'t'),(47,null,"some"),(48,5,"he"),(49,6,"there"),(50,3,'v'),(51,null,"will"),(52,6,'y'),(53,null,"were"),(54,8,'h'),(55,null,"mean"),(56,7,'k'),(57,null,"they"),(58,1,'j'),(59,3,'f'),(60,null,"been"),(61,null,'u'),(62,null,"out"),(63,null,'w'),(64,4,"back"),(65,null,'c'),(66,0,"well"),(67,null,"didn't"),(68,3,'w'),(69,0,'f'),(70,null,"get"),(71,null,"is"),(72,null,"her"),(73,2,'m'),(74,null,'n'),(75,null,"we"),(76,8,"say"),(77,null,"no"),(78,null,'m'),(79,null,'r'),(80,2,"to"),(81,null,'u'),(82,0,"in"),(83,null,"yeah"),(84,8,"in"),(85,4,"here"),(86,null,"had"),(87,3,'b'),(88,3,"all"),(89,null,"that"),(90,null,"this"),(91,7,"know"),(92,4,'c'),(93,null,"be"),(94,null,"his"),(95,4,"they"),(96,null,'y'),(97,null,'j'),(98,9,'r'),(99,5,"who"); + """ + + sql """ + sync + """ + + qt_test """ + WITH cte1 AS ( + SELECT t1.`pk` + FROM test_multi_cast_colocate AS t1 LEFT SEMI + JOIN test_multi_cast_colocate AS alias1 ON t1.`pk` = alias1.`pk` + ) + SELECT cte1.`pk` AS pk1 + FROM cte1 + FULL OUTER JOIN cte1 AS alias2 ON cte1.`pk` = alias2.`pk` + ORDER BY pk1 + """ +} diff --git a/regression-test/suites/nereids_p0/colocate/test_set_operation_colocate.groovy b/regression-test/suites/nereids_p0/colocate/test_set_operation_colocate.groovy new file mode 100644 index 0000000000..c36d673b10 --- /dev/null +++ b/regression-test/suites/nereids_p0/colocate/test_set_operation_colocate.groovy @@ -0,0 +1,104 @@ +// 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. + +// this suite is for creating table with timestamp datatype in defferent +// case. For example: 'year' and 'Year' datatype should also be valid in definition + +suite("test_set_operation_colocate") { + sql 'set enable_nereids_planner=true' + sql 'set enable_fallback_to_original_planner=false' + sql 'set enable_nereids_dml=true' + + sql """ + drop table if exists test1 + """ + + sql """ + drop table if exists test2 + """ + + sql """ + drop table if exists test3 + """ + + sql """ + create table test1 ( + `c1` int , + `c2` varchar(10) , + `pk` int + ) engine=olap + distributed by hash(pk) buckets 10 + properties("replication_num" = "1"); + """ + + sql """ + insert into test1(pk,c1,c2) values (0,8,"yes"),(1,3,'y'),(2,3,"on"),(3,5,'f'),(4,null,'m'),(5,null,"really"),(6,null,"get"); + """ + + sql """ + create table test2 ( + `c1` int , + `c2` varchar(10) , + `pk` int + ) engine=olap + distributed by hash(pk) buckets 10 + properties("replication_num" = "1"); + """ + + sql """ + insert into test2(pk,c1,c2) values (0,null,"okay"),(1,8,'h'),(2,null,'x'),(3,3,'c'),(4,4,'i'),(5,null,"because"),(6,6,"yeah"),(7,7,'i'),(8,1,'z'),(9,null,'h'),(10,null,'x'),(11,7,'k'),(12,null,'n'),(13,8,'s'),(14,null,"I'll"),(15,null,"yeah"),(16,6,"was"),(17,null,"can"),(18,1,'a'),(19,null,'s'),(20,2,'n'),(21,4,"right"),(22,4,"were"); + """ + + sql """ + create table test3 ( + `c1` int, + `c2` varchar(10) , + `pk` int + ) engine=olap + distributed by hash(pk) buckets 10 + properties("replication_num" = "1"); + """ + + sql """ + insert into test3(pk,c1,c2) values (0,7,"have"); + """ + + sql """ + sync + """ + + qt_test """ + SELECT COUNT () AS pk1 + FROM ( + ( + SELECT t1.`pk` + FROM test1 AS t1 + FULL OUTER JOIN test1 AS alias1 ON t1.`pk` = alias1.`pk` + ) + UNION + ( + SELECT t1.`pk` + FROM test1 AS t1, + test2 AS alias2 + INNER JOIN test3 AS alias3 + ORDER BY t1.pk + ) + ) subq1 + GROUP BY subq1.`pk` + ORDER BY 1; + """ +}