[cherry-pick](branch-2.1) Pick "[Feature](schema change) Support add column bitmap with default value bitmap_empty (#42331)" (#42702)

Pick #42331
This commit is contained in:
abmdocrt
2024-11-01 21:46:38 +08:00
committed by GitHub
parent 03a614f945
commit c5374be1bc
7 changed files with 97 additions and 2 deletions

View File

@ -278,6 +278,7 @@ terminal String
KW_BIN,
KW_BINLOG,
KW_BITMAP,
KW_BITMAP_EMPTY,
KW_BITMAP_UNION,
KW_BLOB,
KW_BOOLEAN,
@ -3752,6 +3753,10 @@ opt_default_value ::=
{:
RESULT = ColumnDef.DefaultValue.currentTimeStampDefaultValueWithPrecision(precision);
:}
| KW_DEFAULT KW_BITMAP_EMPTY
{:
RESULT = ColumnDef.DefaultValue.BITMAP_EMPTY_DEFAULT_VALUE;
:}
;
opt_is_key ::=
@ -7748,6 +7753,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

View File

@ -98,6 +98,7 @@ public class ColumnDef {
// default "CURRENT_TIMESTAMP", only for DATETIME type
public static String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
public static String NOW = "now";
public static String BITMAP_EMPTY = "BITMAP_EMPTY";
public static DefaultValue CURRENT_TIMESTAMP_DEFAULT_VALUE = new DefaultValue(true, CURRENT_TIMESTAMP, NOW);
// no default value
public static DefaultValue NOT_SET = new DefaultValue(false, null);
@ -107,7 +108,7 @@ public class ColumnDef {
// default "value", "0" means empty hll
public static DefaultValue HLL_EMPTY_DEFAULT_VALUE = new DefaultValue(true, ZERO);
// default "value", "0" means empty bitmap
public static DefaultValue BITMAP_EMPTY_DEFAULT_VALUE = new DefaultValue(true, ZERO);
public static DefaultValue BITMAP_EMPTY_DEFAULT_VALUE = new DefaultValue(true, ZERO, BITMAP_EMPTY);
// default "value", "[]" means empty array
public static DefaultValue ARRAY_EMPTY_DEFAULT_VALUE = new DefaultValue(true, "[]");

View File

@ -595,7 +595,8 @@ public class NativeInsertStmt extends InsertStmt {
}
// hll column must in mentionedColumns
for (Column col : targetTable.getBaseSchema()) {
if (col.getType().isObjectStored() && !mentionedColumns.contains(col.getName())) {
if (col.getType().isObjectStored() && !col.hasDefaultValue() && !mentionedColumns.contains(
col.getName())) {
throw new AnalysisException(
"object-stored column " + col.getName() + " must in insert into columns");
}

View File

@ -810,6 +810,11 @@ public class Column implements Writable, GsonPostProcessable {
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("");
}

View File

@ -122,6 +122,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));

View File

@ -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

View File

@ -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"
}