You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2025/12/09 03:19:24 UTC
(doris) branch branch-3.1 updated: branch-3.1: [fix](load) sequence column not work well with default value #58576 (#58814)
This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 493196334a5 branch-3.1: [fix](load) sequence column not work well with default value #58576 (#58814)
493196334a5 is described below
commit 493196334a56cf4322a6ca89032c83d8c9b85f67
Author: morrySnow <zh...@selectdb.com>
AuthorDate: Tue Dec 9 11:19:18 2025 +0800
branch-3.1: [fix](load) sequence column not work well with default value #58576 (#58814)
picked from #58576
---
.../main/java/org/apache/doris/analysis/ColumnDef.java | 9 ++++++++-
.../apache/doris/nereids/rules/analysis/BindSink.java | 3 +--
.../data_model_p0/unique/test_sequence_column.groovy | 16 ++++++++++++++++
3 files changed, 25 insertions(+), 3 deletions(-)
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 91812858846..284d01c2f2f 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
@@ -44,6 +44,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Pattern;
// Column definition which is generated by SQL syntax parser
// Syntax:
@@ -103,8 +104,10 @@ public class ColumnDef {
public static String E_NUM = "E";
public static String PI = "PI";
public static String CURRENT_DATE = "CURRENT_DATE";
- // default "CURRENT_TIMESTAMP", only for DATETIME type
+ // default "CURRENT_TIMESTAMP", for datetime / datetimev2 type
public static String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
+ public static Pattern CURRENT_TIMESTAMP_PATTERN
+ = Pattern.compile("^CURRENT_TIMESTAMP(?:\\(\\d?\\))?$");
public static String NOW = "now";
public static String BITMAP_EMPTY = "BITMAP_EMPTY";
public static String HLL_EMPTY = "HLL_EMPTY";
@@ -121,6 +124,10 @@ public class ColumnDef {
// default "value", "[]" means empty array
public static DefaultValue ARRAY_EMPTY_DEFAULT_VALUE = new DefaultValue(true, "[]");
+ public static boolean isCurrentTimeStampDefaultValue(String defaultValue) {
+ return CURRENT_TIMESTAMP_PATTERN.matcher(defaultValue.trim().toUpperCase()).matches();
+ }
+
public static DefaultValue currentTimeStampDefaultValueWithPrecision(Long precision) {
if (precision > ScalarType.MAX_DATETIMEV2_SCALE || precision < 0) {
throw new IllegalArgumentException("column's default value current_timestamp"
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
index 5cd0c166329..1714d3f357b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
@@ -220,8 +220,7 @@ public class BindSink implements AnalysisRuleFactory {
boundSink.getDmlCommandType() != DMLCommandType.INSERT
|| ConnectContext.get().getSessionVariable().isRequireSequenceInInsert())) {
if (!seqColInTable.isPresent() || seqColInTable.get().getDefaultValue() == null
- || !seqColInTable.get().getDefaultValue()
- .equalsIgnoreCase(DefaultValue.CURRENT_TIMESTAMP)) {
+ || !DefaultValue.isCurrentTimeStampDefaultValue(seqColInTable.get().getDefaultValue())) {
throw new org.apache.doris.common.AnalysisException("Table " + table.getName()
+ " has sequence column, need to specify the sequence column");
}
diff --git a/regression-test/suites/data_model_p0/unique/test_sequence_column.groovy b/regression-test/suites/data_model_p0/unique/test_sequence_column.groovy
index 8c2956b38c5..1b905504cf2 100644
--- a/regression-test/suites/data_model_p0/unique/test_sequence_column.groovy
+++ b/regression-test/suites/data_model_p0/unique/test_sequence_column.groovy
@@ -60,6 +60,22 @@ suite("test_sequence_column") {
order_qt_all "SELECT * from ${tableName}"
+ // test sequence column with default value current_timestamp(6)
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """
+ CREATE TABLE `${tableName}` (
+ `ts_tz` datetimev2(6) default current_timestamp(6),
+ `ts_tz_value` datetimev2(6) default current_timestamp(6),
+ `value` INT
+ ) UNIQUE KEY(`ts_tz`)
+ DISTRIBUTED BY HASH(`ts_tz`) BUCKETS 16
+ PROPERTIES (
+ "replication_num" = "1",
+ "function_column.sequence_col" = 'ts_tz_value'
+ );
+ """
+ sql """insert into ${tableName} (value) VALUES(1), (2), (3)"""
+
// test sequence X variant
sql "DROP TABLE IF EXISTS ${tableName}"
try{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org