This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 6a26cdf49f3 [fix](planner) separate table's isPartitioned() method
#27515 #28163 (#28351)
6a26cdf49f3 is described below
commit 6a26cdf49f37c41e2a6d701acc8ff3d6778ecbf2
Author: Mingyu Chen <[email protected]>
AuthorDate: Wed Dec 13 22:53:11 2023 +0800
[fix](planner) separate table's isPartitioned() method #27515 #28163
(#28351)
bp #27515 #28163
---
.../apache/doris/alter/SchemaChangeHandler.java | 2 +-
.../java/org/apache/doris/analysis/ExportStmt.java | 2 +-
.../apache/doris/analysis/NativeInsertStmt.java | 4 +--
.../java/org/apache/doris/catalog/OlapTable.java | 8 +++++-
.../main/java/org/apache/doris/catalog/Table.java | 8 +++++-
.../plans/physical/PhysicalOlapTableSink.java | 2 +-
.../apache/doris/planner/DistributedPlanner.java | 4 +--
.../java/org/apache/doris/planner/PlannerTest.java | 33 ++++++++++++++++++++++
8 files changed, 54 insertions(+), 9 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
index 3aa8e7888e4..aa84677e917 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
@@ -1938,7 +1938,7 @@ public class SchemaChangeHandler extends AlterHandler {
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()
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExportStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExportStmt.java
index dd406f86617..2533dbeb5a7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExportStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExportStmt.java
@@ -255,7 +255,7 @@ public class ExportStmt extends StatementBase {
if (partitionStringNames == null) {
return;
}
- if (!table.isPartitioned()) {
+ if (!table.isPartitionedTable()) {
throw new AnalysisException("Table[" + tblName.getTbl() + "]
is not partitioned.");
}
Table.TableType tblType = table.getType();
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
index 679c189b0fb..b866fc7650b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
@@ -800,7 +800,7 @@ public class NativeInsertStmt extends InsertStmt {
}
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) {
@@ -808,7 +808,7 @@ public class NativeInsertStmt extends InsertStmt {
}
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) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 185117e7687..7142723de31 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -1251,7 +1251,13 @@ public class OlapTable extends Table {
}
@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();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
index fdaa41d2a8f..da88bb13eb8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
@@ -440,8 +440,14 @@ public abstract class Table extends MetaObject implements
Writable, TableIf {
}
// 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;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java
index 3c0a7177fc4..e63d6a93fcf 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapTableSink.java
@@ -214,7 +214,7 @@ public class PhysicalOlapTableSink<CHILD_TYPE extends Plan>
extends PhysicalSink
* get output physical properties
*/
public PhysicalProperties getRequirePhysicalProperties() {
- if (targetTable.isPartitioned()) {
+ if (targetTable.isPartitionDistributed()) {
DistributionInfo distributionInfo =
targetTable.getDefaultDistributionInfo();
if (distributionInfo instanceof HashDistributionInfo) {
HashDistributionInfo hashDistributionInfo
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
b/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
index a719081496b..d3dd27ee73b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
@@ -125,7 +125,7 @@ public class DistributedPlanner {
boolean needRepartition = false;
boolean needMerge = false;
if (isFragmentPartitioned(inputFragment)) {
- if (targetTable.isPartitioned()) {
+ if (targetTable.isPartitionDistributed()) {
if (stmt.getDataPartition().getType() ==
TPartitionType.RANDOM) {
return inputFragment;
}
@@ -138,7 +138,7 @@ public class DistributedPlanner {
needMerge = true;
}
} else {
- if (targetTable.isPartitioned()) {
+ if (targetTable.isPartitionDistributed()) {
if (isRepart != null && isRepart) {
needRepartition = true;
} else {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
index 8e99eadd1aa..5ea31261f4d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
@@ -21,6 +21,7 @@ import org.apache.doris.analysis.ExplainOptions;
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;
@@ -682,4 +683,36 @@ public class PlannerTest extends TestWithFeService {
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);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]