This is an automated email from the ASF dual-hosted git repository. huajianlan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 0903dd61f3 [Enhancement](Planner) Improve error message when columns order and keys orders don't match. (#11724) 0903dd61f3 is described below commit 0903dd61f352414af362797cb9ba098b2c3d8ce8 Author: Shuo Wang <wangshuo...@gmail.com> AuthorDate: Thu Aug 18 13:28:54 2022 +0800 [Enhancement](Planner) Improve error message when columns order and keys orders don't match. (#11724) When creating table like this: ``` CREATE TABLE `test`.`test_key_order` ( `k1` tinyint(4) NULL COMMENT "", `k2` smallint(6) NULL COMMENT "", `k3` int(11) NULL COMMENT "", `v1` double MAX NULL COMMENT "", `v2` float SUM NULL COMMENT "" ) ENGINE=OLAP AGGREGATE KEY(`k1`, `k3`, `k2`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`) BUCKETS 5 PROPERTIES ( "replication_num" = "1" ); ``` The error message before is: ``` Key columns should be a ordered prefix of the schema. ``` With this PR, the error message is: ``` Key columns should be a ordered prefix of the schema. KeyColumns[1] (starts from zero) is k3, but corresponding column is k2 in the previous columns declaration. ``` --- .../java/org/apache/doris/analysis/KeysDesc.java | 5 ++++- .../java/org/apache/doris/planner/QueryPlanTest.java | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/KeysDesc.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/KeysDesc.java index e853474971..83fc766ecb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/KeysDesc.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/KeysDesc.java @@ -75,7 +75,10 @@ public class KeysDesc implements Writable { if (cols.stream().noneMatch(col -> col.getName().equalsIgnoreCase(keyName))) { throw new AnalysisException("Key column[" + keyName + "] doesn't exist."); } - throw new AnalysisException("Key columns should be a ordered prefix of the schema."); + throw new AnalysisException("Key columns should be a ordered prefix of the schema." + + " KeyColumns[" + i + "] (starts from zero) is " + keyName + ", " + + "but corresponding column is " + name + " in the previous " + + "columns declaration."); } if (cols.get(i).getAggregateType() != null) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java index 73a5f8e776..fe628869e3 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java @@ -53,6 +53,7 @@ import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Ignore; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.List; @@ -2147,4 +2148,23 @@ public class QueryPlanTest extends TestWithFeService { // errCode = 2, detailMessage = Unknown column 'col2' in 't_2' Assert.assertFalse(explainString.contains("errCode")); } + + @Test + public void testKeyOrderError() throws Exception { + Assertions.assertTrue(getSQLPlanOrErrorMsg("CREATE TABLE `test`.`test_key_order` (\n" + + " `k1` tinyint(4) NULL COMMENT \"\",\n" + + " `k2` smallint(6) NULL COMMENT \"\",\n" + + " `k3` int(11) NULL COMMENT \"\",\n" + + " `v1` double MAX NULL COMMENT \"\",\n" + + " `v2` float SUM NULL COMMENT \"\"\n" + + ") ENGINE=OLAP\n" + + "AGGREGATE KEY(`k1`, `k3`, `k2`)\n" + + "COMMENT \"OLAP\"\n" + + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" + + "PROPERTIES (\n" + + "\"replication_num\" = \"1\"\n" + + ");").contains("Key columns should be a ordered prefix of the schema. " + + "KeyColumns[1] (starts from zero) is k3, " + + "but corresponding column is k2 in the previous columns declaration.")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org