You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/03/18 04:29:41 UTC

[GitHub] [incubator-doris] HappenLee commented on a change in pull request #5521: [Colocate plan][Step1] Colocate join covers more situations

HappenLee commented on a change in pull request #5521:
URL: https://github.com/apache/incubator-doris/pull/5521#discussion_r595913700



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
##########
@@ -30,15 +30,15 @@
 import org.apache.doris.thrift.TPlan;
 import org.apache.doris.thrift.TPlanNode;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-

Review comment:
       No need to change the import order of Logger?

##########
File path: fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java
##########
@@ -0,0 +1,113 @@
+// 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.planner;
+
+import org.apache.doris.analysis.CreateDbStmt;
+import org.apache.doris.analysis.CreateTableStmt;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.utframe.UtFrameUtils;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ColocatePlanTest {
+    private static final String COLOCATE_ENABLE = "colocate: true";
+    private static String runningDir = "fe/mocked/DemoTest/" + UUID.randomUUID().toString() + "/";
+    private static ConnectContext ctx;
+
+    @Before
+    public void setUp() throws Exception {
+        FeConstants.runningUnitTest = true;
+        UtFrameUtils.createMinDorisCluster(runningDir, 2);
+        ctx = UtFrameUtils.createDefaultCtx();
+        String createDbStmtStr = "create database db1;";
+        CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, ctx);
+        Catalog.getCurrentCatalog().createDb(createDbStmt);
+        // create table test_colocate (k1 int ,k2 int, k3 int, k4 int)
+        // distributed by hash(k1, k2) buckets 10
+        // properties ("replication_num" = "2");
+        String createTblStmtStr = "create table db1.test_colocate(k1 int, k2 int, k3 int, k4 int) "
+                + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2');";
+        CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
+        Catalog.getCurrentCatalog().createTable(createTableStmt);
+    }
+
+    // without
+    // 1. agg: group by column < distributed columns
+    // 2. join: src data has been redistributed
+    @Test
+    public void sqlDistributedSmallerThanData1() throws Exception {
+        String sql = "explain select * from (select k1 from db1.test_colocate group by k1) a , db1.test_colocate b "
+                + "where a.k1=b.k1";
+        String plan1 = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
+        Assert.assertEquals(2, StringUtils.countMatches(plan1, "AGGREGATE"));
+        Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.REDISTRIBUTED_SRC_DATA));
+    }
+
+    // without : join column < distributed columns;
+    @Test
+    public void sqlDistributedSmallerThanData2() throws Exception {
+        String sql = "explain select * from (select k1 from db1.test_colocate group by k1, k2) a , db1.test_colocate b "
+                + "where a.k1=b.k1";
+        String plan1 = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
+        Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.INCONSISTENT_DISTRIBUTION_OF_TABLE_AND_QUERY));
+    }
+
+    // with:
+    // 1. agg columns = distributed columns

Review comment:
       group by columns is better?

##########
File path: fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java
##########
@@ -44,6 +41,10 @@
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 
+import org.apache.commons.validator.routines.InetAddressValidator;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;

Review comment:
       some as up comment

##########
File path: fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java
##########
@@ -0,0 +1,113 @@
+// 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.planner;
+
+import org.apache.doris.analysis.CreateDbStmt;
+import org.apache.doris.analysis.CreateTableStmt;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.utframe.UtFrameUtils;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ColocatePlanTest {
+    private static final String COLOCATE_ENABLE = "colocate: true";
+    private static String runningDir = "fe/mocked/DemoTest/" + UUID.randomUUID().toString() + "/";
+    private static ConnectContext ctx;
+
+    @Before
+    public void setUp() throws Exception {
+        FeConstants.runningUnitTest = true;
+        UtFrameUtils.createMinDorisCluster(runningDir, 2);
+        ctx = UtFrameUtils.createDefaultCtx();
+        String createDbStmtStr = "create database db1;";
+        CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, ctx);
+        Catalog.getCurrentCatalog().createDb(createDbStmt);
+        // create table test_colocate (k1 int ,k2 int, k3 int, k4 int)
+        // distributed by hash(k1, k2) buckets 10
+        // properties ("replication_num" = "2");
+        String createTblStmtStr = "create table db1.test_colocate(k1 int, k2 int, k3 int, k4 int) "
+                + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2');";
+        CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
+        Catalog.getCurrentCatalog().createTable(createTableStmt);
+    }
+
+    // without
+    // 1. agg: group by column < distributed columns
+    // 2. join: src data has been redistributed
+    @Test
+    public void sqlDistributedSmallerThanData1() throws Exception {
+        String sql = "explain select * from (select k1 from db1.test_colocate group by k1) a , db1.test_colocate b "
+                + "where a.k1=b.k1";
+        String plan1 = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
+        Assert.assertEquals(2, StringUtils.countMatches(plan1, "AGGREGATE"));
+        Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.REDISTRIBUTED_SRC_DATA));
+    }
+
+    // without : join column < distributed columns;
+    @Test
+    public void sqlDistributedSmallerThanData2() throws Exception {
+        String sql = "explain select * from (select k1 from db1.test_colocate group by k1, k2) a , db1.test_colocate b "
+                + "where a.k1=b.k1";
+        String plan1 = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
+        Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.INCONSISTENT_DISTRIBUTION_OF_TABLE_AND_QUERY));
+    }
+
+    // with:
+    // 1. agg columns = distributed columns
+    // 2. hash columns = agg output columns = distributed columns
+    @Test
+    public void sqlAggAndJoinSameAsTableMeta() throws Exception {
+        String sql = "explain select * from (select k1, k2 from db1.test_colocate group by k1, k2) a , db1.test_colocate b "
+                + "where a.k1=b.k1 and a.k2=b.k2";
+        String plan1 = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
+        Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE"));
+        Assert.assertTrue(plan1.contains(COLOCATE_ENABLE));
+    }
+
+    // with:
+    // 1. agg columns > distributed columns
+    // 2. hash columns = agg output columns > distributed columns

Review comment:
       hash columns? means join columns?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org