From b1c2a8343f429baebf5aa5cc6e7dec7749983bab Mon Sep 17 00:00:00 2001 From: xy720 <22125576+xy720@users.noreply.github.com> Date: Tue, 13 Sep 2022 08:48:28 +0800 Subject: [PATCH] [Bug](array_type) Forbid adding array key columns #12479 mysql> desc array_test; +-----------+----------------+------+-------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+----------------+------+-------+---------+-------+ | id | INT | Yes | true | NULL | | | c_array | ARRAY | Yes | false | NULL | NONE | +-----------+----------------+------+-------+---------+-------+ Before: mysql> ALTER TABLE array_test ADD COLUMN add_arr_key array key NULL DEFAULT NULL; Query OK, 0 rows affected (0.00 sec) After: mysql> ALTER TABLE array_test ADD COLUMN c_array array key NULL DEFAULT NULL; ERROR 1105 (HY000): errCode = 2, detailMessage = Array can only be used in the non-key column of the duplicate table at present. mysql> ALTER TABLE array_test MODIFY COLUMN c_array array key NULL DEFAULT NULL; ERROR 1105 (HY000): errCode = 2, detailMessage = Array can only be used in the non-key column of the duplicate table at present. --- .../src/main/java/org/apache/doris/analysis/ColumnDef.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java index 788b5e59f1..5a944aa7b2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java @@ -265,6 +265,10 @@ public class ColumnDef { } if (type.getPrimitiveType() == PrimitiveType.ARRAY) { + if (isKey()) { + throw new AnalysisException("Array can only be used in the non-key column of" + + " the duplicate table at present."); + } if (defaultValue.isSet && defaultValue != DefaultValue.NULL_DEFAULT_VALUE) { throw new AnalysisException("Array type column default value only support null"); }