Skip to content

Commit b1fd124

Browse files
authored
[feature](struct-type/map-type) Add switch for struct and map type for creating table (#16379)
Add switches to forbid uses creating table with struct or map column.
1 parent dfb610d commit b1fd124

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

fe/fe-common/src/main/java/org/apache/doris/common/Config.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,18 @@ public class Config extends ConfigBase {
17401740
@ConfField(mutable = true, masterOnly = true)
17411741
public static boolean enable_array_type = false;
17421742

1743+
/**
1744+
* Support complex data type MAP.
1745+
*/
1746+
@ConfField(mutable = true, masterOnly = true)
1747+
public static boolean enable_map_type = false;
1748+
1749+
/**
1750+
* Support complex data type STRUCT.
1751+
*/
1752+
@ConfField(mutable = true, masterOnly = true)
1753+
public static boolean enable_struct_type = false;
1754+
17431755
/**
17441756
* The timeout of executing async remote fragment.
17451757
* In normal case, the async remote fragment will be executed in a short time. If system are under high load

fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,22 @@ public void analyze(Analyzer analyzer) throws UserException, AnalysisException {
427427
for (ColumnDef columnDef : columnDefs) {
428428
columnDef.analyze(engineName.equals("olap"));
429429

430-
if (columnDef.getType().isArrayType() && engineName.equals("olap")) {
430+
if (columnDef.getType().isComplexType() && engineName.equals("olap")) {
431+
if (columnDef.getType().isMapType() && !Config.enable_map_type) {
432+
throw new AnalysisException("Please open enable_map_type config before use Map.");
433+
}
434+
435+
if (columnDef.getType().isStructType() && !Config.enable_struct_type) {
436+
throw new AnalysisException("Please open enable_struct_type config before use Struct.");
437+
}
438+
431439
if (columnDef.getAggregateType() != null && columnDef.getAggregateType() != AggregateType.NONE) {
432-
throw new AnalysisException("Array column can't support aggregation "
433-
+ columnDef.getAggregateType());
440+
throw new AnalysisException(columnDef.getType().getPrimitiveType()
441+
+ " column can't support aggregation " + columnDef.getAggregateType());
434442
}
435443
if (columnDef.isKey()) {
436-
throw new AnalysisException("Array can only be used in the non-key column of"
437-
+ " the duplicate table at present.");
444+
throw new AnalysisException(columnDef.getType().getPrimitiveType()
445+
+ " can only be used in the non-key column of the duplicate table at present.");
438446
}
439447
}
440448

fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,4 +687,22 @@ public void testCreateTableWithArrayType() throws Exception {
687687
+ ");");
688688
});
689689
}
690+
691+
@Test
692+
public void testCreateTableWithMapType() throws Exception {
693+
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "Please open enable_map_type config before use Map.",
694+
() -> {
695+
createTable("create table test.test_map(k1 INT, k2 Map<int, VARCHAR(20)>) duplicate key (k1) "
696+
+ "distributed by hash(k1) buckets 1 properties('replication_num' = '1');");
697+
});
698+
}
699+
700+
@Test
701+
public void testCreateTableWithStructType() throws Exception {
702+
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "Please open enable_struct_type config before use Struct.",
703+
() -> {
704+
createTable("create table test.test_struct(k1 INT, k2 Struct<f1:int, f2:VARCHAR(20)>) duplicate key (k1) "
705+
+ "distributed by hash(k1) buckets 1 properties('replication_num' = '1');");
706+
});
707+
}
690708
}

0 commit comments

Comments
 (0)