This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new e46149b6fd4 [cherry-pick](branch-3.0) Pick "[Feature](schema change) 
Support add column bitmap with default value bitmap_empty  (#42331)" (#42701)
e46149b6fd4 is described below

commit e46149b6fd4f98e8501fc01494fa0de4e7602d41
Author: abmdocrt <yukang.lian2...@gmail.com>
AuthorDate: Sat Nov 2 21:50:28 2024 +0800

    [cherry-pick](branch-3.0) Pick "[Feature](schema change) Support add column 
bitmap with default value bitmap_empty  (#42331)" (#42701)
    
    ## Proposed changes
    
    Pick #42331
    
    <!--Describe your changes.-->
---
 fe/fe-core/src/main/cup/sql_parser.cup             |  7 +++
 .../java/org/apache/doris/analysis/ColumnDef.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 ++++++++++++++++++++++
 6 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 0cfd889f0a8..dca7752761c 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/analysis/ColumnDef.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
index bd7ca73a449..6a7b1c94a50 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
@@ -105,6 +105,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 String HLL_EMPTY = "HLL_EMPTY";
         public static DefaultValue CURRENT_TIMESTAMP_DEFAULT_VALUE = new 
DefaultValue(true, CURRENT_TIMESTAMP, NOW);
         // no default value
@@ -115,7 +116,7 @@ public class ColumnDef {
         // default "value", "0" means empty hll
         public static DefaultValue HLL_EMPTY_DEFAULT_VALUE = new 
DefaultValue(true, ZERO, HLL_EMPTY);
         // 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/catalog/Column.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
index 7e0ab33aa7c..a5505133ca2 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
@@ -985,6 +985,11 @@ public class Column implements 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 1863fc877cb..9903675e18d 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 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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to