You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by w4...@apache.org on 2024/09/24 07:18:32 UTC

(doris) branch fix_column_def_sql_result created (now bda5eb26603)

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

w41ter pushed a change to branch fix_column_def_sql_result
in repository https://gitbox.apache.org/repos/asf/doris.git


      at bda5eb26603 [fix](analysis) Fix ColumnDef to sql result

This branch includes the following new commits:

     new bda5eb26603 [fix](analysis) Fix ColumnDef to sql result

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


(doris) 01/01: [fix](analysis) Fix ColumnDef to sql result

Posted by w4...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

w41ter pushed a commit to branch fix_column_def_sql_result
in repository https://gitbox.apache.org/repos/asf/doris.git

commit bda5eb26603217579267831daf79972be5603c9b
Author: w41ter <w4...@gmail.com>
AuthorDate: Tue Sep 24 07:09:26 2024 +0000

    [fix](analysis) Fix ColumnDef to sql result
    
    For sql:
    
    ```
    ALTER TABLE table_3333338 ADD COLUMN col484 DATETIME(1) REPLACE_IF_NOT_NULL
    ```
    
    the toSql result is:
    
    ```
    ADD COLUMN `col484` datetimev2(1) REPLACE_IF_NOT_NULL NULL DEFAULT "null" COMMENT ""
    ```
    
    the `DEFAULT "null"` is not a valid expr for datetime. This PR correct
    the behaviour of toSql of the NULL DEFAULT VALUE to `DEFAULT NULL`.
---
 .../main/java/org/apache/doris/analysis/ColumnDef.java    | 15 ++++++++++++++-
 .../java/org/apache/doris/analysis/ColumnDefTest.java     |  8 +++++++-
 2 files changed, 21 insertions(+), 2 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 9bd34e1410b..52255196bdb 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
@@ -175,9 +175,22 @@ public class ColumnDef {
                 }
                 return LocalDateTime.now(TimeUtils.getTimeZone().toZoneId())
                         .format(DateTimeFormatter.ofPattern(format));
+            } else if (value == null) {
+                return "NULL";
             }
             return value;
         }
+
+        public String toSql() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("DEFAULT ");
+            if (value != null) {
+                sb.append('"').append(value).append('"');
+            } else {
+                sb.append("NULL");
+            }
+            return sb.toString();
+        }
     }
 
     // parameter initialized in constructor
@@ -662,7 +675,7 @@ public class ColumnDef {
         }
 
         if (defaultValue.isSet) {
-            sb.append("DEFAULT \"").append(defaultValue.value).append("\" ");
+            sb.append(defaultValue.toSql()).append(" ");
         }
         sb.append("COMMENT \"").append(comment).append("\"");
 
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/ColumnDefTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/ColumnDefTest.java
index 246dd5dc8ff..c8764a0a2e0 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ColumnDefTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ColumnDefTest.java
@@ -89,7 +89,7 @@ public class ColumnDefTest {
             ColumnDef column = new ColumnDef("col", intCol, false, AggregateType.REPLACE_IF_NOT_NULL, true, DefaultValue.NOT_SET, "");
             column.analyze(true);
             Assert.assertEquals(AggregateType.REPLACE_IF_NOT_NULL, column.getAggregateType());
-            Assert.assertEquals("`col` int REPLACE_IF_NOT_NULL NULL DEFAULT \"null\" COMMENT \"\"", column.toSql());
+            Assert.assertEquals("`col` int REPLACE_IF_NOT_NULL NULL DEFAULT NULL COMMENT \"\"", column.toSql());
         } // CHECKSTYLE IGNORE THIS LINE
         { // CHECKSTYLE IGNORE THIS LINE
             // not allow null
@@ -98,6 +98,12 @@ public class ColumnDefTest {
             Assert.assertEquals(AggregateType.REPLACE_IF_NOT_NULL, column.getAggregateType());
             Assert.assertEquals("`col` int REPLACE_IF_NOT_NULL NULL DEFAULT \"10\" COMMENT \"\"", column.toSql());
         } // CHECKSTYLE IGNORE THIS LINE
+        { // CHECKSTYLE IGNORE THIS LINE
+            ColumnDef column = new ColumnDef("col", intCol, false, AggregateType.REPLACE_IF_NOT_NULL, true, DefaultValue.NULL_DEFAULT_VALUE, "");
+            column.analyze(true);
+            Assert.assertEquals(AggregateType.REPLACE_IF_NOT_NULL, column.getAggregateType());
+            Assert.assertEquals("`col` int REPLACE_IF_NOT_NULL NULL DEFAULT NULL COMMENT \"\"", column.toSql());
+        } // CHECKSTYLE IGNORE THIS LINE
     }
 
     @Test(expected = AnalysisException.class)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org