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 2df72176bdf branch-3.0: [Fix] Add column with default value string
throw exception #45000 (#45315)
2df72176bdf is described below
commit 2df72176bdfa9f5fe3b473524f96af6c54d97343
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Dec 12 19:37:03 2024 +0800
branch-3.0: [Fix] Add column with default value string throw exception
#45000 (#45315)
Cherry-picked from #45000
Co-authored-by: Uniqueyou <[email protected]>
---
.../java/org/apache/doris/analysis/ColumnDef.java | 3 +-
.../test_alter_add_column_default_value_str.out | 14 +++++
.../test_alter_add_column_default_value_str.groovy | 72 ++++++++++++++++++++++
3 files changed, 88 insertions(+), 1 deletion(-)
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 6a7b1c94a50..d95a463fe4a 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
@@ -134,7 +134,8 @@ public class ColumnDef {
}
public boolean isCurrentTimeStamp() {
- return "CURRENT_TIMESTAMP".equals(value) &&
NOW.equals(defaultValueExprDef.getExprName());
+ return "CURRENT_TIMESTAMP".equals(value) && defaultValueExprDef !=
null
+ && NOW.equals(defaultValueExprDef.getExprName());
}
public boolean isCurrentTimeStampWithPrecision() {
diff --git
a/regression-test/data/alter_p0/test_alter_add_column_default_value_str.out
b/regression-test/data/alter_p0/test_alter_add_column_default_value_str.out
new file mode 100644
index 00000000000..b180902fd16
--- /dev/null
+++ b/regression-test/data/alter_p0/test_alter_add_column_default_value_str.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 CURRENT_TIMESTAMP BITMAP_EMPTY
+2 2 2 CURRENT_TIMESTAMP BITMAP_EMPTY
+3 3 3 CURRENT_TIMESTAMP BITMAP_EMPTY
+4 4 4 4 4
+5 5 5 5 5
+6 6 6 6 6
+
diff --git
a/regression-test/suites/alter_p0/test_alter_add_column_default_value_str.groovy
b/regression-test/suites/alter_p0/test_alter_add_column_default_value_str.groovy
new file mode 100644
index 00000000000..f3d03864981
--- /dev/null
+++
b/regression-test/suites/alter_p0/test_alter_add_column_default_value_str.groovy
@@ -0,0 +1,72 @@
+// 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_str') {
+ def tbl = 'test_alter_add_column_default_value_str_tbl'
+ 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("varchar(20) NOT NULL DEFAULT
\"CURRENT_TIMESTAMP\""))
+ assertFalse(tb1[0][1].contains("varchar(20) NOT NULL DEFAULT
\"BITMAP_EMPTY\""))
+
+ sql """
+ ALTER TABLE ${tbl} add column timestamp_default varchar(20) NOT NULL
default "CURRENT_TIMESTAMP";
+ """
+
+ sql """
+ ALTER TABLE ${tbl} add column bitmap_default varchar(20) NOT NULL
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("varchar(20) NOT NULL DEFAULT
\"CURRENT_TIMESTAMP\""))
+ assertTrue(tb2[0][1].contains("varchar(20) NOT NULL DEFAULT
\"BITMAP_EMPTY\""))
+ def resultCreate = sql """ SHOW CREATE TABLE ${tbl} """
+ sql """insert into ${tbl} values (4,4,4,"4","4")"""
+ sql """insert into ${tbl} (k1,v1,v2,timestamp_default,bitmap_default)
values (5,5,5,5,"5")"""
+ sql """insert into ${tbl} (k1,v1,v2,timestamp_default,bitmap_default)
values (6,6,6,6,"6")"""
+ qt_select4 """ SELECT k1,v1,v2,timestamp_default,bitmap_default 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]