[branch2.1] pick [fix](show) show create table show index comment err… (#37034)

## Proposed changes
pick https://github.com/apache/doris/pull/36306
This commit is contained in:
zgxme
2024-07-16 11:19:27 +08:00
committed by GitHub
parent 47096f2083
commit 2957fdc039
7 changed files with 39 additions and 24 deletions

View File

@ -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);
}

View File

@ -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)) {