Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](schema change) Support add column bitmap with default value bitmap_empty #42331

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ terminal String
KW_BIN,
KW_BINLOG,
KW_BITMAP,
KW_BITMAP_EMPTY,
KW_BITMAP_UNION,
KW_BLOB,
KW_BOOLEAN,
Expand Down Expand Up @@ -3972,6 +3973,10 @@ opt_default_value ::=
{:
RESULT = ColumnDef.DefaultValue.currentTimeStampDefaultValueWithPrecision(precision);
:}
| KW_DEFAULT KW_BITMAP_EMPTY
{:
RESULT = ColumnDef.DefaultValue.BITMAP_EMPTY_DEFAULT_VALUE;
:}
| KW_DEFAULT INTEGER_LITERAL:value
{:
RESULT = new ColumnDef.DefaultValue(true, value);
Expand Down Expand Up @@ -8102,6 +8107,8 @@ keyword ::=
{: RESULT = id; :}
| KW_BITMAP:id
{: RESULT = id; :}
| KW_BITMAP_EMPTY:id
{: RESULT = id; :}
| KW_QUANTILE_STATE:id
{: RESULT = id; :}
| KW_AGG_STATE:id
Expand Down
5 changes: 5 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,11 @@ public String toSql(boolean isUniqueTable, boolean isCompatible) {
sb.append(" DEFAULT \"").append(defaultValue).append("\"");
}
}
if (getDataType() == PrimitiveType.BITMAP && defaultValue != null) {
if (defaultValueExprDef != null) {
sb.append(" DEFAULT ").append(defaultValueExprDef.getExprName()).append("");
}
}
if (hasOnUpdateDefaultValue) {
sb.append(" ON UPDATE ").append(defaultValue).append("");
}
Expand Down
1 change: 1 addition & 0 deletions fe/fe-core/src/main/jflex/sql_scanner.flex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import org.apache.doris.qe.SqlModeHelper;
keywordMap.put("binlog", new Integer(SqlParserSymbols.KW_BINLOG));
keywordMap.put("bitmap", new Integer(SqlParserSymbols.KW_BITMAP));
keywordMap.put("inverted", new Integer(SqlParserSymbols.KW_INVERTED));
keywordMap.put("bitmap_empty", new Integer(SqlParserSymbols.KW_BITMAP_EMPTY));
keywordMap.put("bitmap_union", new Integer(SqlParserSymbols.KW_BITMAP_UNION));
keywordMap.put("ngram_bf", new Integer(SqlParserSymbols.KW_NGRAM_BF));
keywordMap.put("blob", new Integer(SqlParserSymbols.KW_BLOB));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select1 --
1 1 1
2 2 2
3 3 3

-- !select4 --
1 1 1
2 2 2
3 3 3
4 4 4 444
5 5 5
6 6 6

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite('test_alter_add_column_default_value') {
def tbl = 'test_alter_add_column_default_value'
sql "DROP TABLE IF EXISTS ${tbl} FORCE"
sql """
CREATE TABLE ${tbl} (
`k1` BIGINT NOT NULL,
`v1` BIGINT NULL,
`v2` INT NULL,
) ENGINE=OLAP
UNIQUE KEY(`k1`)
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """
INSERT INTO ${tbl} VALUES (1,1,1),(2,2,2),(3,3,3)
"""

sql """ SYNC """

// Check data before ALTER TABLE
qt_select1 """ SELECT * FROM ${tbl} ORDER BY k1 """
def tb1 = sql """ show create table ${tbl}"""
logger.info("tb1:{}", tb1[0][1])
assertFalse(tb1[0][1].contains("bitmap NOT NULL DEFAULT BITMAP_EMPTY"))

sql """
ALTER TABLE ${tbl} add column v3 bitmap default bitmap_empty;
"""

waitForSchemaChangeDone {
sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tbl}' ORDER BY createtime DESC LIMIT 1 """
time 600
}

// Check table structure after ALTER TABLE
def tb2 = sql """ show create table ${tbl}"""
logger.info("tb2:{}", tb2[0][1])
assertTrue(tb2[0][1].contains("bitmap NOT NULL DEFAULT BITMAP_EMPTY"))
def resultCreate = sql """ SHOW CREATE TABLE ${tbl} """
sql """insert into ${tbl} values (4,4,4,to_bitmap(444))"""
sql """insert into ${tbl} (k1,v1,v2) values (5,5,5)"""
sql """insert into ${tbl} (k1,v1,v2) values (6,6,6)"""
qt_select4 """ SELECT k1,v1,v1,bitmap_to_string(v3) FROM ${tbl} ORDER BY k1 """

sql "DROP TABLE IF EXISTS ${tbl} FORCE"
}
Loading