This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new c5374be1bca [cherry-pick](branch-2.1) Pick "[Feature](schema change)
Support add column bitmap with default value bitmap_empty (#42331)" (#42702)
c5374be1bca is described below
commit c5374be1bca6473fd1dbee33708bc1c5cf154e66
Author: abmdocrt <[email protected]>
AuthorDate: Fri Nov 1 21:46:38 2024 +0800
[cherry-pick](branch-2.1) Pick "[Feature](schema change) Support add column
bitmap with default value bitmap_empty (#42331)" (#42702)
Pick #42331
---
fe/fe-core/src/main/cup/sql_parser.cup | 7 +++
.../java/org/apache/doris/analysis/ColumnDef.java | 3 +-
.../apache/doris/analysis/NativeInsertStmt.java | 3 +-
.../main/java/org/apache/doris/catalog/Column.java | 5 ++
fe/fe-core/src/main/jflex/sql_scanner.flex | 1 +
.../test_alter_add_column_default_value.out | 14 +++++
.../test_alter_add_column_default_value.groovy | 66 ++++++++++++++++++++++
7 files changed, 97 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index 4a01f0ca848..ace26c55299 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -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
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
index 50498846ec4..3702f502778 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
@@ -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, "[]");
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
index 172904cb49f..a21cfb45553 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
@@ -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");
}
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 21895b81a8a..7e549e5dffd 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
@@ -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("");
}
diff --git a/fe/fe-core/src/main/jflex/sql_scanner.flex
b/fe/fe-core/src/main/jflex/sql_scanner.flex
index 1abcc2fa7ec..080d152b40a 100644
--- a/fe/fe-core/src/main/jflex/sql_scanner.flex
+++ b/fe/fe-core/src/main/jflex/sql_scanner.flex
@@ -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));
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 00000000000..fa833bbda29
--- /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 00000000000..895523bb3f0
--- /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"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]