Skip to content

Commit

Permalink
[fix](planner) separate table's isPartitioned() method #27515 #28163 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman authored Dec 13, 2023
1 parent cde6847 commit 6a26cdf
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ public int getAsInt() {
BuildIndexClause buildIndexClause = (BuildIndexClause) alterClause;
IndexDef indexDef = buildIndexClause.getIndexDef();
Index index = buildIndexClause.getIndex();
if (!olapTable.isPartitioned()) {
if (!olapTable.isPartitionedTable()) {
List<String> specifiedPartitions = indexDef.getPartitionNames();
if (!specifiedPartitions.isEmpty()) {
throw new DdlException("table " + olapTable.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void checkTable(Env env) throws AnalysisException {
if (partitionStringNames == null) {
return;
}
if (!table.isPartitioned()) {
if (!table.isPartitionedTable()) {
throw new AnalysisException("Table[" + tblName.getTbl() + "] is not partitioned.");
}
Table.TableType tblType = table.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,15 +800,15 @@ private void analyzePlanHints() throws AnalysisException {
}
for (String hint : planHints) {
if (SHUFFLE_HINT.equalsIgnoreCase(hint)) {
if (!targetTable.isPartitioned()) {
if (!targetTable.isPartitionedTable()) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_INSERT_HINT_NOT_SUPPORT);
}
if (isRepartition != null && !isRepartition) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PLAN_HINT_CONFILT, hint);
}
isRepartition = Boolean.TRUE;
} else if (NOSHUFFLE_HINT.equalsIgnoreCase(hint)) {
if (!targetTable.isPartitioned()) {
if (!targetTable.isPartitionedTable()) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_INSERT_HINT_NOT_SUPPORT);
}
if (isRepartition != null && isRepartition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,13 @@ public Status getIntersectPartNamesWith(OlapTable anotherTbl, List<String> inter
}

@Override
public boolean isPartitioned() {
public boolean isPartitionedTable() {
return !PartitionType.UNPARTITIONED.equals(partitionInfo.getType());
}

// Return true if data is distributed by one more partitions or buckets.
@Override
public boolean isPartitionDistributed() {
int numSegs = 0;
for (Partition part : getPartitions()) {
numSegs += part.getDistributionInfo().getBucketNum();
Expand Down
8 changes: 7 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,14 @@ public void readFields(DataInput in) throws IOException {
}

// return if this table is partitioned.
// For OlapTable, return true only if its partition type is RANGE or HASH
public boolean isPartitionedTable() {
return false;
}

// return if this table is partitioned, for planner.
// For OlapTable ture when is partitioned, or distributed by hash when no partition
public boolean isPartitioned() {
public boolean isPartitionDistributed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ isPartialUpdate, isFromNativeInsertStmt, groupExpression, getLogicalProperties()
* get output physical properties
*/
public PhysicalProperties getRequirePhysicalProperties() {
if (targetTable.isPartitioned()) {
if (targetTable.isPartitionDistributed()) {
DistributionInfo distributionInfo = targetTable.getDefaultDistributionInfo();
if (distributionInfo instanceof HashDistributionInfo) {
HashDistributionInfo hashDistributionInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ PlanFragment createInsertFragment(
boolean needRepartition = false;
boolean needMerge = false;
if (isFragmentPartitioned(inputFragment)) {
if (targetTable.isPartitioned()) {
if (targetTable.isPartitionDistributed()) {
if (stmt.getDataPartition().getType() == TPartitionType.RANDOM) {
return inputFragment;
}
Expand All @@ -138,7 +138,7 @@ PlanFragment createInsertFragment(
needMerge = true;
}
} else {
if (targetTable.isPartitioned()) {
if (targetTable.isPartitionDistributed()) {
if (isRepart != null && isRepart) {
needRepartition = true;
} else {
Expand Down
33 changes: 33 additions & 0 deletions fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FeConstants;
import org.apache.doris.qe.QueryState;
import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.qe.StmtExecutor;
Expand Down Expand Up @@ -682,4 +683,36 @@ public void testEliminatingSortNode() throws Exception {
Assertions.assertFalse(plan1.contains("order by:"));
}
}

@Test
public void testInsertPlan() throws Exception {
FeConstants.runningUnitTest = true;
// 1. should not contains exchange node in old planner
boolean v = connectContext.getSessionVariable().isEnableNereidsPlanner();
try {
connectContext.getSessionVariable().setEnableNereidsPlanner(false);
String sql1 = "explain insert into db1.tbl1 select * from db1.tbl1";
StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1);
stmtExecutor1.execute();
Planner planner1 = stmtExecutor1.planner();
String plan1 = planner1.getExplainString(new ExplainOptions(false, false));
Assertions.assertFalse(plan1.contains("VEXCHANGE"));
} finally {
connectContext.getSessionVariable().setEnableNereidsPlanner(v);
}

// 1. should not contains exchange node in new planner
v = connectContext.getSessionVariable().isEnableNereidsPlanner();
try {
connectContext.getSessionVariable().setEnableNereidsPlanner(true);
String sql1 = "explain insert into db1.tbl1 select * from db1.tbl1";
StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1);
stmtExecutor1.execute();
Planner planner1 = stmtExecutor1.planner();
String plan1 = planner1.getExplainString(new ExplainOptions(false, false));
Assertions.assertFalse(plan1.contains("VEXCHANGE"));
} finally {
connectContext.getSessionVariable().setEnableNereidsPlanner(v);
}
}
}

0 comments on commit 6a26cdf

Please sign in to comment.