diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index 0cfd889f0a8501..dca7752761c0a4 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -285,6 +285,7 @@ terminal String KW_BIN, KW_BINLOG, KW_BITMAP, + KW_BITMAP_EMPTY, KW_BITMAP_UNION, KW_BLOB, KW_BOOLEAN, @@ -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); @@ -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 diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java index 1fb386e2b2dd86..53499079eb17e0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java @@ -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(""); } diff --git a/fe/fe-core/src/main/jflex/sql_scanner.flex b/fe/fe-core/src/main/jflex/sql_scanner.flex index 1863fc877cbcd9..9903675e18d346 100644 --- a/fe/fe-core/src/main/jflex/sql_scanner.flex +++ b/fe/fe-core/src/main/jflex/sql_scanner.flex @@ -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)); diff --git a/regression-test/data/alter_p0/test_alter_add_column_default_value.out b/regression-test/data/alter_p0/test_alter_add_column_default_value.out new file mode 100644 index 00000000000000..fa833bbda29375 --- /dev/null +++ b/regression-test/data/alter_p0/test_alter_add_column_default_value.out @@ -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 + diff --git a/regression-test/suites/alter_p0/test_alter_add_column_default_value.groovy b/regression-test/suites/alter_p0/test_alter_add_column_default_value.groovy new file mode 100644 index 00000000000000..895523bb3f013b --- /dev/null +++ b/regression-test/suites/alter_p0/test_alter_add_column_default_value.groovy @@ -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" +}