Skip to content

Commit

Permalink
[feature-wip](autoinc)(step-3) add auto increment support for unique …
Browse files Browse the repository at this point in the history
…table (apache#22036)
  • Loading branch information
bobhan1 authored Jul 21, 2023
1 parent 6512893 commit 74313c7
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ Column definition list:

* `AUTO_INCREMENT`(only avaliable in master branch)

To indicate if the column is a auto-increment column. Auto-increment column can be used to generate a unique identity for new row. If no values are assgined for auto-increment column when inserting, Doris will generate sequence numbers automatically. You can also assign the auto-increment column with NULL literal to indicate Doris to generate sequence numbers. It should be noted that, for performance reasons, BE will cache some values of auto-increment columns in memory. Therefore, the values generated by auto-increment columns can only guarantee monotonicity and uniqueness, but not strict continuity.
To indicate if the column is a auto-increment column. Auto-increment column can be used to generate a unique identity for new row. If no values are assgined for auto-increment column when inserting, Doris will generate sequence numbers automatically. You can also assign the auto-increment column with NULL literal to indicate Doris to generate sequence numbers. It should be noted that, for performance reasons, BE will cache some values of auto-increment column in memory. Therefore, the values generated by auto-increment column can only guarantee monotonicity and uniqueness, but not strict continuity.
A table can have at most one auto-incremnt column. The auto-increment column should be BIGINT type and be NOT NULL.
Currently, only table of duplicate model supports auto-increment column.
Both Duplicate model table and Unique model table support auto-increment column

* `default_value`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ distribution_desc

是否为自增列,自增列可以用来为新插入的行生成一个唯一标识。在插入表数据时如果没有指定自增列的值,则会自动生成一个合法的值。当自增列被显示地插入NULL时,其值也会被替换为生成的合法值。需要注意的是,处于性能考虑,BE会在内存中缓存部分自增列的值,所以自增列自动生成的值只能保证单调性和唯一性,无法保证严格的连续性。
一张表中至多有一个列是自增列,自增列必须是BIGINT类型,且必须为NOT NULL。
目前只有duplicate模型支持自增列
Duplicate模型表和Unique模型表均支持自增列

* `default_value`
列默认值,当导入数据未指定该列的值时,系统将赋予该列default_value。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,8 @@ public enum ErrorCode {
ERR_AUTO_INCREMENT_COLUMN_NOT_BIGINT_TYPE(5095, new byte[]{'4', '2', '0', '0', '0'},
"the auto increment must be BIGINT type."),

ERR_AUTO_INCREMENT_COLUMN_NOT_INT_DUPLICATE_TABLE(5096, new byte[]{'4', '2', '0', '0', '0'},
"the auto increment is only supported in duplicate table.");
ERR_AUTO_INCREMENT_COLUMN_IN_AGGREGATE_TABLE(5096, new byte[]{'4', '2', '0', '0', '0'},
"the auto increment is only supported in duplicate table and unique table.");

// This is error code
private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2692,8 +2692,8 @@ private void checkAutoIncColumns(List<Column> columns, KeysType type) throws Ddl
}
}
}
if (encounterAutoIncColumn && type != KeysType.DUP_KEYS) {
ErrorReport.reportDdlException(ErrorCode.ERR_AUTO_INCREMENT_COLUMN_NOT_INT_DUPLICATE_TABLE);
if (encounterAutoIncColumn && type == KeysType.AGG_KEYS) {
ErrorReport.reportDdlException(ErrorCode.ERR_AUTO_INCREMENT_COLUMN_IN_AGGREGATE_TABLE);
}
}

Expand Down
9 changes: 9 additions & 0 deletions regression-test/data/data_model_p0/unique/auto_inc_basic.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Bob, 100
Alice, 200
Tom, 300
Test, 400
Carter, 500
Smith, 600
Beata, 700
Doris, 800
Nereids, 900
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0, 123
2, 323
4, 523
6, 723
8, 923
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bob, 9990
Tom, 9992
Carter, 9994
Beata, 9996
Nereids, 9998
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
null, Bob, 100
null, Alice, 200
null, Tom, 300
null, Test, 400
0, Carter, 500
1, Smith, 600
2, Beata, 700
3, Doris, 800
4, Nereids, 900
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
null, Bob, 100
null, Alice, 200
null, Tom, 300
null, Test, 400
4, Carter, 500
5, Smith, 600
6, Beata, 700
7, Doris, 800
8, Nereids, 900
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
0 Bob 100
1 Alice 200
2 Tom 300
3 Test 400
4 Carter 500
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !sql --
0 Bob 123
1 Alice 200
2 Tom 323
3 Test 400
4 Carter 523
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !sql --
0 Bob 100
1 Alice 200
2 Tom 300
3 Test 400
4 Carter 500
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !sql --
1 Alice 200
3 Test 400
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900
1230 Bob 100
1232 Tom 300
1234 Carter 500

-- !sql --
0 Bob 100
1 Alice 200
2 Tom 300
3 Test 400
4 Carter 500
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !sql --
0 Bob 123
1 Alice 200
2 Tom 323
3 Test 400
4 Carter 523
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !update_inplace --
0 Carter 500
1 Smith 600
2 Beata 700
3 Doris 800
4 Nereids 900

-- !partial_update_key --
0 Bob 100
1 Alice 200
2 Tom 300
3 Test 400
4 Carter 500
5 Smith 600
6 Beata 700
7 Doris 800
8 Nereids 900

-- !partial_update_key --
0 Bob 123
1 Alice 200
2 Tom 323
3 Test 400
4 Carter 523
5 Smith 600
6 Beata 723
7 Doris 800
8 Nereids 923

-- !partial_update_value --
Bob 100 0
Alice 200 1
Tom 300 2
Test 400 3
Carter 500 4
Smith 600 5
Beata 700 6
Doris 800 7
Nereids 900 8

-- !partial_update_value --
Alice 200 1
Test 400 3
Smith 600 5
Doris 800 7
Bob 100 9990
Tom 300 9992
Carter 500 9994
Beata 700 9996
Nereids 900 9998

-- !partial_update_value --
Bob 100 0
Alice 200 1
Tom 300 2
Test 400 3
Carter 500 4
Smith 600 5
Beata 700 6
Doris 800 7
Nereids 900 8

-- !partial_update_value --
Bob 9990 0
Alice 200 1
Tom 9992 2
Test 400 3
Carter 9994 4
Smith 600 5
Beata 9996 6
Doris 800 7
Nereids 9998 8

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ suite("test_aggregate_table") {
AGGREGATE KEY(k)
DISTRIBUTED BY HASH(k) BUCKETS 5 properties("replication_num" = "1");
"""
exception "the auto increment is only supported in duplicate table."
exception "the auto increment is only supported in duplicate table and unique table."
}
// sql "drop database ${dbName}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,4 @@ suite("test_unique_table") {
order_qt_select_uniq_table "select * from ${tbName}"
qt_desc_uniq_table "desc ${tbName}"
sql "DROP TABLE ${tbName}"

def table_auto_inc = "test_aggregate_tab_with_auto_inc_col"
sql "drop table if exists ${table_auto_inc}"
test {
sql """
CREATE TABLE IF NOT EXISTS ${table_auto_inc} (
k BIGINT NOT NULL AUTO_INCREMENT,
int_value int,
char_value char(10),
date_value date
)
UNIQUE KEY(k)
DISTRIBUTED BY HASH(k) BUCKETS 5 properties("replication_num" = "1");
"""
exception "the auto increment is only supported in duplicate table."
}
}
Loading

0 comments on commit 74313c7

Please sign in to comment.