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

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 2957fdc039c [branch2.1] pick [fix](show) show create table show index 
comment err… (#37034)
2957fdc039c is described below

commit 2957fdc039c7e5dd45da1e50bfc542ac31ece2f4
Author: zgxme <[email protected]>
AuthorDate: Tue Jul 16 11:19:27 2024 +0800

    [branch2.1] pick [fix](show) show create table show index comment err… 
(#37034)
    
    ## Proposed changes
    pick https://github.com/apache/doris/pull/36306
---
 .../main/java/org/apache/doris/catalog/Index.java  | 23 +++++++++++++++-------
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  4 +++-
 .../show_p0/test_show_create_table_and_views.out   |  8 ++++----
 .../test_show_create_table_and_views_nereids.out   |  8 ++++----
 .../suites/index_p0/test_index_meta.groovy         | 12 +++++------
 .../test_show_create_table_and_views.groovy        |  4 +++-
 ...test_show_create_table_and_views_nereids.groovy |  4 +++-
 7 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Index.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Index.java
index 24abe49095f..6ead50192dd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Index.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Index.java
@@ -23,11 +23,13 @@ import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.io.Writable;
 import org.apache.doris.common.util.PrintableMap;
+import org.apache.doris.common.util.SqlUtils;
 import org.apache.doris.persist.gson.GsonUtils;
 import org.apache.doris.thrift.TIndexType;
 import org.apache.doris.thrift.TOlapTableIndex;
 
 import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang3.StringUtils;
 
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -62,7 +64,7 @@ public class Index implements Writable {
     private String comment;
 
     public Index(long indexId, String indexName, List<String> columns,
-                 IndexDef.IndexType indexType, Map<String, String> properties, 
String comment) {
+            IndexDef.IndexType indexType, Map<String, String> properties, 
String comment) {
         this.indexId = indexId;
         this.indexName = indexName;
         this.columns = columns;
@@ -148,7 +150,14 @@ public class Index implements Writable {
     }
 
     public String getComment() {
-        return comment;
+        return getComment(false);
+    }
+
+    public String getComment(boolean escapeQuota) {
+        if (!escapeQuota) {
+            return comment;
+        }
+        return SqlUtils.escapeQuota(comment);
     }
 
     public void setComment(String comment) {
@@ -172,7 +181,7 @@ public class Index implements Writable {
 
     public Index clone() {
         return new Index(indexId, indexName, new ArrayList<>(columns),
-                         indexType, new HashMap<>(properties), comment);
+                indexType, new HashMap<>(properties), comment);
     }
 
     @Override
@@ -201,8 +210,8 @@ public class Index implements Writable {
             sb.append(" PROPERTIES");
             sb.append(getPropertiesString());
         }
-        if (comment != null) {
-            sb.append(" COMMENT '" + comment + "'");
+        if (StringUtils.isNotBlank(comment)) {
+            sb.append(" COMMENT '").append(getComment(true)).append("'");
         }
         return sb.toString();
     }
@@ -230,7 +239,7 @@ public class Index implements Writable {
                     column = column.toLowerCase();
                     if (bfColumns.contains(column)) {
                         throw new AnalysisException(column + " should have 
only one ngram bloom filter index or bloom "
-                            + "filter index");
+                                + "filter index");
                     }
                     bfColumns.add(column);
                 }
@@ -240,7 +249,7 @@ public class Index implements Writable {
             column = column.toLowerCase();
             if (bfColumns.contains(column)) {
                 throw new AnalysisException(column + " should have only one 
ngram bloom filter index or bloom "
-                    + "filter index");
+                        + "filter index");
             }
             bfColumns.add(column);
         }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index c56a47c257a..7b28e992f0f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -2749,7 +2749,9 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         List<String> indexCols = visitIdentifierList(ctx.cols);
         Map<String, String> properties = visitPropertyItemList(ctx.properties);
         String indexType = ctx.indexType != null ? 
ctx.indexType.getText().toUpperCase() : null;
-        String comment = ctx.comment != null ? ctx.comment.getText() : "";
+        //comment should remove '\' and '(") at the beginning and end
+        String comment = ctx.comment == null ? "" : 
LogicalPlanBuilderAssistant.escapeBackSlash(
+                        ctx.comment.getText().substring(1, 
ctx.STRING_LITERAL().getText().length() - 1));
         // change BITMAP index to INVERTED index
         if (Config.enable_create_bitmap_index_as_inverted_index
                 && "BITMAP".equalsIgnoreCase(indexType)) {
diff --git a/regression-test/data/show_p0/test_show_create_table_and_views.out 
b/regression-test/data/show_p0/test_show_create_table_and_views.out
index f432bb0308b..fc7eb008641 100644
--- a/regression-test/data/show_p0/test_show_create_table_and_views.out
+++ b/regression-test/data/show_p0/test_show_create_table_and_views.out
@@ -1,6 +1,6 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !show --
-show_create_table_and_views_table      CREATE TABLE 
`show_create_table_and_views_table` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPARTITION p5 VALUES [...]
+show_create_table_and_views_table      CREATE TABLE 
`show_create_table_and_views_table` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884 
[...]
 
 -- !select --
 1      1       30
@@ -36,11 +36,11 @@ show_create_table_and_views_view    CREATE VIEW 
`show_create_table_and_views_view`
 300    1
 
 -- !show --
-show_create_table_and_views_table      CREATE TABLE 
`show_create_table_and_views_table` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPARTITION p5 VALUES [...]
+show_create_table_and_views_table      CREATE TABLE 
`show_create_table_and_views_table` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884 
[...]
 
 -- !show --
-show_create_table_and_views_like       CREATE TABLE 
`show_create_table_and_views_like` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPARTITION p5 VALUES [ [...]
+show_create_table_and_views_like       CREATE TABLE 
`show_create_table_and_views_like` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-17014118346046923173168730371588410 
[...]
 
 -- !show --
-show_create_table_and_views_like_with_rollup   CREATE TABLE 
`show_create_table_and_views_like_with_rollup` (\n  `user_id` LARGEINT NOT 
NULL,\n  `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")) [...]
+show_create_table_and_views_like_with_rollup   CREATE TABLE 
`show_create_table_and_views_like_with_rollup` (\n  `user_id` LARGEINT NOT 
NULL,\n  `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  
INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  
INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" 
comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-17014118346 [...]
 
diff --git 
a/regression-test/data/show_p0/test_show_create_table_and_views_nereids.out 
b/regression-test/data/show_p0/test_show_create_table_and_views_nereids.out
index 2fe50f2427b..9b1f6d3e4a0 100644
--- a/regression-test/data/show_p0/test_show_create_table_and_views_nereids.out
+++ b/regression-test/data/show_p0/test_show_create_table_and_views_nereids.out
@@ -1,6 +1,6 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !show --
-show_create_table_and_views_nereids_table      CREATE TABLE 
`show_create_table_and_views_nereids_table` (\n  `user_id` LARGEINT NOT NULL,\n 
 `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPAR [...]
+show_create_table_and_views_nereids_table      CREATE TABLE 
`show_create_table_and_views_nereids_table` (\n  `user_id` LARGEINT NOT NULL,\n 
 `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-17014118346046923 [...]
 
 -- !select --
 1      1       30
@@ -36,11 +36,11 @@ show_create_table_and_views_nereids_view    CREATE VIEW 
`show_create_table_and_view
 300    1
 
 -- !show --
-show_create_table_and_views_nereids_table      CREATE TABLE 
`show_create_table_and_views_nereids_table` (\n  `user_id` LARGEINT NOT NULL,\n 
 `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPAR [...]
+show_create_table_and_views_nereids_table      CREATE TABLE 
`show_create_table_and_views_nereids_table` (\n  `user_id` LARGEINT NOT NULL,\n 
 `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-17014118346046923 [...]
 
 -- !show --
-show_create_table_and_views_nereids_like       CREATE TABLE 
`show_create_table_and_views_nereids_like` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0"\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [("300"), ("400")),\nPARTI [...]
+show_create_table_and_views_nereids_like       CREATE TABLE 
`show_create_table_and_views_nereids_like` (\n  `user_id` LARGEINT NOT NULL,\n  
`good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT "0",\n  INDEX 
index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n  INDEX 
index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) 
ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES [("-1701411834604692317 [...]
 
 -- !show --
-show_create_table_and_views_nereids_like_with_rollup   CREATE TABLE 
`show_create_table_and_views_nereids_like_with_rollup` (\n  `user_id` LARGEINT 
NOT NULL,\n  `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT 
"0"\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY 
RANGE(`good_id`)\n(PARTITION p1 VALUES 
[("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES 
[("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 
VALUES [( [...]
+show_create_table_and_views_nereids_like_with_rollup   CREATE TABLE 
`show_create_table_and_views_nereids_like_with_rollup` (\n  `user_id` LARGEINT 
NOT NULL,\n  `good_id` LARGEINT NOT NULL,\n  `cost` BIGINT SUM NULL DEFAULT 
"0",\n  INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index 
comment',\n  INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test 
index\\" comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, 
`good_id`)\nPARTITION BY RANGE(`good_id`)\n(PARTITION p1 VALUES [...]
 
diff --git a/regression-test/suites/index_p0/test_index_meta.groovy 
b/regression-test/suites/index_p0/test_index_meta.groovy
index e1d26f825f3..577f18678cd 100644
--- a/regression-test/suites/index_p0/test_index_meta.groovy
+++ b/regression-test/suites/index_p0/test_index_meta.groovy
@@ -65,12 +65,12 @@ suite("index_meta", "p0") {
     assertEquals(show_result[0][2], "idx_id")
     assertEquals(show_result[0][4], "id")
     assertEquals(show_result[0][10], "INVERTED")
-    assertEquals(show_result[0][11], "'index for id'")
+    assertEquals(show_result[0][11], "index for id")
     assertEquals(show_result[0][12], "")
     assertEquals(show_result[1][2], "idx_name")
     assertEquals(show_result[1][4], "name")
     assertEquals(show_result[1][10], "INVERTED")
-    assertEquals(show_result[1][11], "'index for name'")
+    assertEquals(show_result[1][11], "index for name")
     assertEquals(show_result[1][12], "(\"parser\" = \"none\", \"lower_case\" = 
\"true\")")
 
     // add index on column description
@@ -84,12 +84,12 @@ suite("index_meta", "p0") {
     assertEquals(show_result[0][2], "idx_id")
     assertEquals(show_result[0][4], "id")
     assertEquals(show_result[0][10], "INVERTED")
-    assertEquals(show_result[0][11], "'index for id'")
+    assertEquals(show_result[0][11], "index for id")
     assertEquals(show_result[0][12], "")
     assertEquals(show_result[1][2], "idx_name")
     assertEquals(show_result[1][4], "name")
     assertEquals(show_result[1][10], "INVERTED")
-    assertEquals(show_result[1][11], "'index for name'")
+    assertEquals(show_result[1][11], "index for name")
     assertEquals(show_result[1][12], "(\"parser\" = \"none\", \"lower_case\" = 
\"true\")")
     assertEquals(show_result[2][2], "idx_desc")
     assertEquals(show_result[2][4], "description")
@@ -108,7 +108,7 @@ suite("index_meta", "p0") {
     assertEquals(show_result[0][2], "idx_id")
     assertEquals(show_result[0][4], "id")
     assertEquals(show_result[0][10], "INVERTED")
-    assertEquals(show_result[0][11], "'index for id'")
+    assertEquals(show_result[0][11], "index for id")
     assertEquals(show_result[0][12], "")
     assertEquals(show_result[1][2], "idx_desc")
     assertEquals(show_result[1][4], "description")
@@ -127,7 +127,7 @@ suite("index_meta", "p0") {
     assertEquals(show_result[0][2], "idx_id")
     assertEquals(show_result[0][4], "id")
     assertEquals(show_result[0][10], "INVERTED")
-    assertEquals(show_result[0][11], "'index for id'")
+    assertEquals(show_result[0][11], "index for id")
     assertEquals(show_result[0][12], "")
     assertEquals(show_result[1][2], "idx_desc")
     assertEquals(show_result[1][4], "description")
diff --git 
a/regression-test/suites/show_p0/test_show_create_table_and_views.groovy 
b/regression-test/suites/show_p0/test_show_create_table_and_views.groovy
index 5872cc95d5a..2fd5f09d307 100644
--- a/regression-test/suites/show_p0/test_show_create_table_and_views.groovy
+++ b/regression-test/suites/show_p0/test_show_create_table_and_views.groovy
@@ -37,7 +37,9 @@ suite("test_show_create_table_and_views", "show") {
         CREATE TABLE ${dbName}.${tableName} (
             `user_id` LARGEINT NOT NULL,
             `good_id` LARGEINT NOT NULL,
-            `cost` BIGINT SUM DEFAULT "0"
+            `cost` BIGINT SUM DEFAULT "0",
+            INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index 
comment',
+            INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test 
index" comment'
         )
         AGGREGATE KEY(`user_id`, `good_id`)
         PARTITION BY RANGE(`good_id`)
diff --git 
a/regression-test/suites/show_p0/test_show_create_table_and_views_nereids.groovy
 
b/regression-test/suites/show_p0/test_show_create_table_and_views_nereids.groovy
index 88fd00444ad..81102d90c3a 100644
--- 
a/regression-test/suites/show_p0/test_show_create_table_and_views_nereids.groovy
+++ 
b/regression-test/suites/show_p0/test_show_create_table_and_views_nereids.groovy
@@ -39,7 +39,9 @@ suite("test_show_create_table_and_views_nereids", "show") {
         CREATE TABLE ${dbName}.${tableName} (
             `user_id` LARGEINT NOT NULL,
             `good_id` LARGEINT NOT NULL,
-            `cost` BIGINT SUM DEFAULT "0"
+            `cost` BIGINT SUM DEFAULT "0",
+            INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index 
comment',
+            INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test 
index" comment'
         )
         AGGREGATE KEY(`user_id`, `good_id`)
         PARTITION BY RANGE(`good_id`)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to