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

morrysnow pushed a commit to branch pick_4.0_58576
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 540a4db87ef73dec8e9d4aea0d854c36ce24eea0
Author: morrySnow <[email protected]>
AuthorDate: Tue Dec 2 16:23:42 2025 +0800

    branch-4.0: [fix](load) sequence column not work well with default value 
#58576
    
    picked from #58576
---
 .../main/java/org/apache/doris/analysis/ColumnDef.java   |  7 +++++++
 .../apache/doris/nereids/rules/analysis/BindSink.java    |  3 +--
 .../trees/plans/commands/merge/MergeIntoCommand.java     |  8 +++-----
 .../data_model_p0/unique/test_sequence_column.groovy     | 16 ++++++++++++++++
 4 files changed, 27 insertions(+), 7 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 e0c18702fea..32784b09734 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
@@ -46,6 +46,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:
@@ -107,6 +108,8 @@ public class ColumnDef {
         public static String CURRENT_DATE = "CURRENT_DATE";
         // default "CURRENT_TIMESTAMP", only for DATETIME 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 HLL_EMPTY = "HLL_EMPTY";
         public static String BITMAP_EMPTY = "BITMAP_EMPTY";
@@ -136,6 +139,10 @@ public class ColumnDef {
             return new DefaultValue(true, value, exprName, precision);
         }
 
+        public static boolean isCurrentTimeStampDefaultValue(String 
defaultValue) {
+            return 
CURRENT_TIMESTAMP_PATTERN.matcher(defaultValue.trim().toUpperCase()).matches();
+        }
+
         public boolean isCurrentTimeStamp() {
             return "CURRENT_TIMESTAMP".equals(value) && defaultValueExprDef != 
null
                     && NOW.equals(defaultValueExprDef.getExprName());
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 34462634f44..cb22abadfda 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
@@ -242,8 +242,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/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/merge/MergeIntoCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/merge/MergeIntoCommand.java
index b9bcbbc390c..9b562492c85 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/merge/MergeIntoCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/merge/MergeIntoCommand.java
@@ -268,9 +268,8 @@ public class MergeIntoCommand extends Command implements 
ForwardWithSync, Explai
             Optional<Column> seqMappingColInTable, Optional<Type> seqColType) {
         ImmutableList.Builder<Expression> builder = ImmutableList.builder();
         if (hasSequenceCol && seqColumnIndex < 0) {
-            if ((!seqMappingColInTable.isPresent() || 
seqMappingColInTable.get().getDefaultValue() == null
-                    || !seqMappingColInTable.get().getDefaultValue()
-                    .equalsIgnoreCase(DefaultValue.CURRENT_TIMESTAMP))) {
+            if (!seqMappingColInTable.isPresent() || 
seqMappingColInTable.get().getDefaultValue() == null
+                    || 
!DefaultValue.isCurrentTimeStampDefaultValue(seqMappingColInTable.get().getDefaultValue()))
 {
                 throw new AnalysisException("Table " + targetTable.getName()
                         + " has sequence column, need to specify the sequence 
column");
             }
@@ -331,8 +330,7 @@ public class MergeIntoCommand extends Command implements 
ForwardWithSync, Explai
             }
             if (!colNameToExpression.containsKey(seqColumnName)
                     && (!seqMappingColInTable.isPresent() || 
seqMappingColInTable.get().getDefaultValue() == null
-                    || !seqMappingColInTable.get().getDefaultValue()
-                    .equalsIgnoreCase(DefaultValue.CURRENT_TIMESTAMP))) {
+                    || 
!DefaultValue.isCurrentTimeStampDefaultValue(seqMappingColInTable.get().getDefaultValue())))
 {
                 throw new AnalysisException("Table " + targetTable.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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to