Skip to content

Commit adeae3c

Browse files
authored
[fix](cluster key) some data type is not supported for cluster key (#38966)
1. some data type is not supported for key column, it's the same for cluster key column 2. modify some cluster key cases as the mow cases
1 parent 2f11a4c commit adeae3c

23 files changed

+444
-46
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java

+33-28
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,37 @@ private DataType updateCharacterTypeLength(DataType dataType) {
199199
}
200200
}
201201

202+
private void checkKeyColumnType(boolean isOlap) {
203+
if (isOlap) {
204+
if (type.isFloatLikeType()) {
205+
throw new AnalysisException("Float or double can not used as a key, use decimal instead.");
206+
} else if (type.isStringType()) {
207+
throw new AnalysisException("String Type should not be used in key column[" + name + "]");
208+
} else if (type.isArrayType()) {
209+
throw new AnalysisException("Array can only be used in the non-key column of"
210+
+ " the duplicate table at present.");
211+
}
212+
}
213+
if (type.isBitmapType() || type.isHllType() || type.isQuantileStateType()) {
214+
throw new AnalysisException("Key column can not set complex type:" + name);
215+
} else if (type.isJsonType()) {
216+
throw new AnalysisException("JsonType type should not be used in key column[" + getName() + "].");
217+
} else if (type.isVariantType()) {
218+
throw new AnalysisException("Variant type should not be used in key column[" + getName() + "].");
219+
} else if (type.isMapType()) {
220+
throw new AnalysisException("Map can only be used in the non-key column of"
221+
+ " the duplicate table at present.");
222+
} else if (type.isStructType()) {
223+
throw new AnalysisException("Struct can only be used in the non-key column of"
224+
+ " the duplicate table at present.");
225+
}
226+
}
227+
202228
/**
203229
* validate column definition and analyze
204230
*/
205-
public void validate(boolean isOlap, Set<String> keysSet, boolean isEnableMergeOnWrite, KeysType keysType) {
231+
public void validate(boolean isOlap, Set<String> keysSet, Set<String> clusterKeySet, boolean isEnableMergeOnWrite,
232+
KeysType keysType) {
206233
try {
207234
FeNameFormat.checkColumnName(name);
208235
} catch (Exception e) {
@@ -234,33 +261,7 @@ public void validate(boolean isOlap, Set<String> keysSet, boolean isEnableMergeO
234261
throw new AnalysisException(
235262
String.format("Key column %s can not set aggregation type", name));
236263
}
237-
if (isOlap) {
238-
if (type.isFloatLikeType()) {
239-
throw new AnalysisException(
240-
"Float or double can not used as a key, use decimal instead.");
241-
} else if (type.isStringType()) {
242-
throw new AnalysisException(
243-
"String Type should not be used in key column[" + name + "]");
244-
} else if (type.isArrayType()) {
245-
throw new AnalysisException("Array can only be used in the non-key column of"
246-
+ " the duplicate table at present.");
247-
}
248-
}
249-
if (type.isBitmapType() || type.isHllType() || type.isQuantileStateType()) {
250-
throw new AnalysisException("Key column can not set complex type:" + name);
251-
} else if (type.isJsonType()) {
252-
throw new AnalysisException(
253-
"JsonType type should not be used in key column[" + getName() + "].");
254-
} else if (type.isVariantType()) {
255-
throw new AnalysisException(
256-
"Variant type should not be used in key column[" + getName() + "].");
257-
} else if (type.isMapType()) {
258-
throw new AnalysisException("Map can only be used in the non-key column of"
259-
+ " the duplicate table at present.");
260-
} else if (type.isStructType()) {
261-
throw new AnalysisException("Struct can only be used in the non-key column of"
262-
+ " the duplicate table at present.");
263-
}
264+
checkKeyColumnType(isOlap);
264265
} else if (aggType == null && isOlap) {
265266
Preconditions.checkState(keysType != null, "keysType is null");
266267
if (keysType.equals(KeysType.DUP_KEYS)) {
@@ -274,6 +275,10 @@ public void validate(boolean isOlap, Set<String> keysSet, boolean isEnableMergeO
274275
}
275276
}
276277

278+
if (clusterKeySet.contains(name)) {
279+
checkKeyColumnType(isOlap);
280+
}
281+
277282
if (aggType != null) {
278283
// check if aggregate type is valid
279284
if (aggType != AggregateType.GENERIC

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void analyze(ConnectContext ctx) throws Exception {
162162
final boolean finalEnableMergeOnWrite = false;
163163
Set<String> keysSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
164164
keysSet.addAll(keys);
165-
columns.forEach(c -> c.validate(true, keysSet, finalEnableMergeOnWrite, KeysType.DUP_KEYS));
165+
columns.forEach(c -> c.validate(true, keysSet, Sets.newHashSet(), finalEnableMergeOnWrite, KeysType.DUP_KEYS));
166166

167167
if (distribution == null) {
168168
throw new AnalysisException("Create async materialized view should contain distribution desc");

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ public void validate(ConnectContext ctx) {
558558
final boolean finalEnableMergeOnWrite = isEnableMergeOnWrite;
559559
Set<String> keysSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
560560
keysSet.addAll(keys);
561-
columns.forEach(c -> c.validate(engineName.equals(ENGINE_OLAP), keysSet, finalEnableMergeOnWrite,
561+
Set<String> clusterKeySet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
562+
clusterKeySet.addAll(clusterKeysColumnNames);
563+
columns.forEach(c -> c.validate(engineName.equals(ENGINE_OLAP), keysSet, clusterKeySet, finalEnableMergeOnWrite,
562564
keysType));
563565

564566
// validate index
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !select_0 --
3+
true 1 10 {"c":"c"}
4+
5+
-- !select_1 --
6+
7+
-- !select_2 --
8+
9+
-- !select_3 --
10+
true 1 10 {"c":"c"}
11+
12+
-- !select_4 --
13+
14+
-- !select_5 --
15+
16+
-- !select_6 --
17+
18+
-- !select_7 --
19+
true 1 10 {"c":"c"}
20+
21+
-- !select_8 --
22+
true 1 10 {"c":"c"}
23+
24+
-- !select_9 --
25+
true 1 30 {"b":"b"}
26+
27+
-- !select_10 --
28+
true 1 10 {"c":"c"}
29+
30+
-- !select_11 --
31+
true 1 10 {"c":"c"}
32+
33+
-- !select_12 --
34+
true 1 30 {"b":"b"}
35+
36+
-- !select_0 --
37+
true 1 10 {"c":"c"}
38+
39+
-- !select_1 --
40+
41+
-- !select_2 --
42+
43+
-- !select_3 --
44+
true 1 10 {"c":"c"}
45+
46+
-- !select_4 --
47+
48+
-- !select_5 --
49+
50+
-- !select_6 --
51+
52+
-- !select_7 --
53+
true 1 10 {"c":"c"}
54+
55+
-- !select_8 --
56+
true 1 10 {"c":"c"}
57+
58+
-- !select_9 --
59+
true 1 30 {"b":"b"}
60+
61+
-- !select_10 --
62+
true 1 10 {"c":"c"}
63+
64+
-- !select_11 --
65+
true 1 10 {"c":"c"}
66+
67+
-- !select_12 --
68+
true 1 30 {"b":"b"}
69+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !sql --
3+
1 10
4+
2 200
5+
3 30
6+
4 400
7+
5 500
8+
6 600
9+
7 7
10+
8 8
11+
9 9
12+
10 10
13+
14+
-- !sql --
15+
1 10
16+
2 200
17+
3 30
18+
4 400
19+
5 500
20+
6 600
21+
7 7
22+
8 8
23+
9 9
24+
10 10
25+
26+
-- !sql --
27+
1 10
28+
2 200
29+
3 30
30+
4 400
31+
5 500
32+
6 600
33+
7 7
34+
8 8
35+
9 9
36+
10 10
37+

regression-test/suites/point_query_p0/test_point_query_cluster_key.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ suite("test_point_query_cluster_key") {
239239
sql """CREATE TABLE ${tableName} (
240240
`customer_key` bigint(20) NULL,
241241
`customer_btm_value_0` text NULL,
242-
`customer_btm_value_1` text NULL,
242+
`customer_btm_value_1` VARCHAR(1000) NULL,
243243
`customer_btm_value_2` text NULL
244244
) ENGINE=OLAP
245245
UNIQUE KEY(`customer_key`)

regression-test/suites/unique_with_mow_c_p0/ssb_unique_sql_zstd/ddl/customer_create.sql

-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 10
1414
PROPERTIES (
1515
"compression"="zstd",
1616
"replication_num" = "1",
17-
"disable_auto_compaction" = "true",
1817
"enable_unique_key_merge_on_write" = "true"
1918
);

regression-test/suites/unique_with_mow_c_p0/ssb_unique_sql_zstd/ddl/date_create.sql

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ DISTRIBUTED BY HASH(`d_datekey`) BUCKETS 1
2323
PROPERTIES (
2424
"compression"="zstd",
2525
"replication_num" = "1",
26-
"disable_auto_compaction" = "true",
2726
"enable_unique_key_merge_on_write" = "true"
2827
);

regression-test/suites/unique_with_mow_c_p0/ssb_unique_sql_zstd/ddl/lineorder_create.sql

-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ DISTRIBUTED BY HASH(`lo_orderkey`) BUCKETS 48
3131
PROPERTIES (
3232
"compression"="zstd",
3333
"replication_num" = "1",
34-
"disable_auto_compaction" = "true",
3534
"enable_unique_key_merge_on_write" = "true"
3635
);

regression-test/suites/unique_with_mow_c_p0/ssb_unique_sql_zstd/ddl/part_create.sql

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ DISTRIBUTED BY HASH(`p_partkey`) BUCKETS 10
1515
PROPERTIES (
1616
"compression"="zstd",
1717
"replication_num" = "1",
18-
"disable_auto_compaction" = "true",
1918
"enable_unique_key_merge_on_write" = "true"
2019
);

regression-test/suites/unique_with_mow_c_p0/ssb_unique_sql_zstd/ddl/supplier_create.sql

-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ DISTRIBUTED BY HASH(`s_suppkey`) BUCKETS 10
1313
PROPERTIES (
1414
"compression"="zstd",
1515
"replication_num" = "1",
16-
"disable_auto_compaction" = "true",
1716
"enable_unique_key_merge_on_write" = "true"
1817
);

regression-test/suites/unique_with_mow_c_p0/test_create_table.groovy

+20
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,24 @@ suite("test_create_table") {
227227
"""
228228
exception "Cluster keys only support unique keys table"
229229
}
230+
231+
// cluster key contains complex type
232+
test {
233+
sql """
234+
CREATE TABLE `$tableName` (
235+
`c_custkey` int(11) NOT NULL COMMENT "",
236+
`c_name` varchar(26) NOT NULL COMMENT "",
237+
`c_address` varchar(41) NOT NULL COMMENT "",
238+
`c_city` variant NOT NULL COMMENT ""
239+
)
240+
UNIQUE KEY (`c_custkey`)
241+
CLUSTER BY (`c_name`, `c_city`, `c_address`)
242+
DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 1
243+
PROPERTIES (
244+
"replication_num" = "1",
245+
"enable_unique_key_merge_on_write" = "true"
246+
);
247+
"""
248+
exception "Variant type should not be used in key column"
249+
}
230250
}

0 commit comments

Comments
 (0)