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 82f497c8e17 branch-3.0: [Fix](ccr) Wrong result of tosql for add 
column with comment #45319 (#45726)
82f497c8e17 is described below

commit 82f497c8e17470afe242a7fba586fec0d1ee6ece
Author: Uniqueyou <1520358...@qq.com>
AuthorDate: Mon Dec 23 11:19:34 2024 +0800

    branch-3.0: [Fix](ccr) Wrong result of tosql for add column with comment 
#45319 (#45726)
    
    pick : https://github.com/apache/doris/pull/45319
---
 .../java/org/apache/doris/analysis/ColumnDef.java  |  2 +-
 .../doris/analysis/AddColumnCommentTest.java       | 75 ++++++++++++++++++++++
 2 files changed, 76 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 fc3ea435ca2..45465581907 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
@@ -687,7 +687,7 @@ public class ColumnDef {
                 sb.append("DEFAULT ").append("NULL").append(" ");
             }
         }
-        sb.append("COMMENT \"").append(comment).append("\"");
+        sb.append("COMMENT 
\"").append(SqlUtils.escapeQuota(comment)).append("\"");
 
         return sb.toString();
     }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/AddColumnCommentTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/AddColumnCommentTest.java
new file mode 100644
index 00000000000..1adc4add7e3
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/AddColumnCommentTest.java
@@ -0,0 +1,75 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.analysis.ColumnDef.DefaultValue;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+
+import com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.List;
+
+public class AddColumnCommentTest {
+    private static Analyzer analyzer;
+
+    @BeforeClass
+    public static void setUp() {
+        analyzer = AccessTestUtil.fetchAdminAnalyzer(false);
+    }
+
+    @Test
+    public void testNormal() throws AnalysisException {
+        List<ColumnDef> columns = Lists.newArrayList();
+        ColumnDef definition = new ColumnDef("col1", new 
TypeDef(ScalarType.createType(PrimitiveType.VARCHAR)),
+                true,
+                null, false,
+                new DefaultValue(true, "col1_default"), "a");
+        definition.setKeysType(KeysType.DUP_KEYS);
+        columns.add(definition);
+        definition = new ColumnDef("col2", new 
TypeDef(ScalarType.createType(PrimitiveType.INT)),
+                false,
+                null, false,
+                new DefaultValue(true, 0), "[\"a\", \"b\"]");
+        columns.add(definition);
+        definition = new ColumnDef("col3", new 
TypeDef(ScalarType.createType(PrimitiveType.VARCHAR)),
+                false,
+                null, false,
+                new DefaultValue(true, "col3_default"), "['a', 'b']");
+        columns.add(definition);
+        definition = new ColumnDef("col4", new 
TypeDef(ScalarType.createType(PrimitiveType.VARCHAR)),
+                false,
+                null, false,
+                new DefaultValue(true, "col4_default"), "'[123, 456]' and 
'[789, 10]'");
+        columns.add(definition);
+        AddColumnsClause clause = new AddColumnsClause(columns, null, null);
+        clause.analyze(analyzer);
+        System.out.println(clause.toString());
+        Assert.assertEquals(
+                "ADD COLUMN (`col1` varchar(65533) NOT NULL DEFAULT 
\"col1_default\" COMMENT \"a\", "
+                        + "`col2` int NOT NULL DEFAULT \"0\" COMMENT 
\"[\\\"a\\\", \\\"b\\\"]\", "
+                        + "`col3` varchar(65533) NOT NULL DEFAULT 
\"col3_default\" COMMENT \"['a', 'b']\", "
+                        + "`col4` varchar(65533) NOT NULL DEFAULT 
\"col4_default\" COMMENT \"'[123, 456]' and '[789, 10]'\")",
+                clause.toString());
+    }
+}


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

Reply via email to