[improvement] modify comment " to ', to be compatible with mysql. (#10327)
This commit is contained in:
@ -232,6 +232,7 @@ import com.sleepycat.je.rep.NetworkRestore;
|
||||
import com.sleepycat.je.rep.NetworkRestoreConfig;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
@ -2741,9 +2742,7 @@ public class Catalog {
|
||||
}
|
||||
sb.append(Joiner.on(", ").join(keysColumnNames)).append(")");
|
||||
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
addTableComment(olapTable, sb);
|
||||
|
||||
// partition
|
||||
PartitionInfo partitionInfo = olapTable.getPartitionInfo();
|
||||
@ -2872,9 +2871,9 @@ public class Catalog {
|
||||
sb.append("\n)");
|
||||
} else if (table.getType() == TableType.MYSQL) {
|
||||
MysqlTable mysqlTable = (MysqlTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(mysqlTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
if (mysqlTable.getOdbcCatalogResourceName() == null) {
|
||||
@ -2892,9 +2891,9 @@ public class Catalog {
|
||||
sb.append(")");
|
||||
} else if (table.getType() == TableType.ODBC) {
|
||||
OdbcTable odbcTable = (OdbcTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(odbcTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
if (odbcTable.getOdbcCatalogResourceName() == null) {
|
||||
@ -2913,9 +2912,9 @@ public class Catalog {
|
||||
sb.append(")");
|
||||
} else if (table.getType() == TableType.BROKER) {
|
||||
BrokerTable brokerTable = (BrokerTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(brokerTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append("\"broker_name\" = \"").append(brokerTable.getBrokerName()).append("\",\n");
|
||||
@ -2931,9 +2930,8 @@ public class Catalog {
|
||||
}
|
||||
} else if (table.getType() == TableType.ELASTICSEARCH) {
|
||||
EsTable esTable = (EsTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(esTable, sb);
|
||||
|
||||
// partition
|
||||
PartitionInfo partitionInfo = esTable.getPartitionInfo();
|
||||
@ -2965,9 +2963,9 @@ public class Catalog {
|
||||
sb.append(")");
|
||||
} else if (table.getType() == TableType.HIVE) {
|
||||
HiveTable hiveTable = (HiveTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(hiveTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append("\"database\" = \"").append(hiveTable.getHiveDb()).append("\",\n");
|
||||
@ -2976,9 +2974,9 @@ public class Catalog {
|
||||
sb.append("\n)");
|
||||
} else if (table.getType() == TableType.ICEBERG) {
|
||||
IcebergTable icebergTable = (IcebergTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(icebergTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append("\"iceberg.database\" = \"").append(icebergTable.getIcebergDb()).append("\",\n");
|
||||
@ -2987,9 +2985,9 @@ public class Catalog {
|
||||
sb.append("\n)");
|
||||
} else if (table.getType() == TableType.HUDI) {
|
||||
HudiTable hudiTable = (HudiTable) table;
|
||||
if (!Strings.isNullOrEmpty(table.getComment())) {
|
||||
sb.append("\nCOMMENT \"").append(table.getComment(true)).append("\"");
|
||||
}
|
||||
|
||||
addTableComment(hudiTable, sb);
|
||||
|
||||
// properties
|
||||
sb.append("\nPROPERTIES (\n");
|
||||
sb.append(new PrintableMap<>(hudiTable.getTableProperties(), " = ", true, true, false).toString());
|
||||
@ -3682,7 +3680,7 @@ public class Catalog {
|
||||
|
||||
// the invoker should keep table's write lock
|
||||
public void modifyTableColocate(Database db, OlapTable table, String colocateGroup, boolean isReplay,
|
||||
GroupId assignedGroupId)
|
||||
GroupId assignedGroupId)
|
||||
throws DdlException {
|
||||
|
||||
String oldGroup = table.getColocateGroup();
|
||||
@ -4110,7 +4108,7 @@ public class Catalog {
|
||||
|
||||
ModifyTableDefaultDistributionBucketNumOperationLog info
|
||||
= new ModifyTableDefaultDistributionBucketNumOperationLog(
|
||||
db.getId(), olapTable.getId(), bucketNum);
|
||||
db.getId(), olapTable.getId(), bucketNum);
|
||||
editLog.logModifyDefaultDistributionBucketNum(info);
|
||||
LOG.info("modify table[{}] default bucket num to {}", olapTable.getName(), bucketNum);
|
||||
}
|
||||
@ -4608,7 +4606,7 @@ public class Catalog {
|
||||
if (column.getAggregationType() == AggregateType.REPLACE
|
||||
|| column.getAggregationType() == AggregateType.REPLACE_IF_NOT_NULL) {
|
||||
throw new DdlException("Cannot change distribution type of aggregate keys table which has value"
|
||||
+ " columns with " + column.getAggregationType() + " type.");
|
||||
+ " columns with " + column.getAggregationType() + " type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4916,4 +4914,10 @@ public class Catalog {
|
||||
// send task immediately
|
||||
AgentTaskExecutor.submit(batchTask);
|
||||
}
|
||||
|
||||
private static void addTableComment(Table table, StringBuilder sb) {
|
||||
if (StringUtils.isNotBlank(table.getComment())) {
|
||||
sb.append("\nCOMMENT '").append(table.getComment(true)).append("'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ import org.apache.doris.thrift.TColumnType;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -116,17 +117,17 @@ public class Column implements Writable {
|
||||
}
|
||||
|
||||
public Column(String name, Type type, boolean isKey, AggregateType aggregateType, String defaultValue,
|
||||
String comment) {
|
||||
String comment) {
|
||||
this(name, type, isKey, aggregateType, false, defaultValue, comment);
|
||||
}
|
||||
|
||||
public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
|
||||
String defaultValue, String comment) {
|
||||
String defaultValue, String comment) {
|
||||
this(name, type, isKey, aggregateType, isAllowNull, defaultValue, comment, true, null);
|
||||
}
|
||||
|
||||
public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
|
||||
String defaultValue, String comment, boolean visible, DefaultValueExprDef defaultValueExprDef) {
|
||||
String defaultValue, String comment, boolean visible, DefaultValueExprDef defaultValueExprDef) {
|
||||
this.name = name;
|
||||
if (this.name == null) {
|
||||
this.name = "";
|
||||
@ -419,8 +420,8 @@ public class Column implements Writable {
|
||||
Integer lSize = type.getColumnStringRepSize();
|
||||
Integer rSize = other.type.getColumnStringRepSize();
|
||||
if (rSize < lSize) {
|
||||
throw new DdlException("Can not change from wider type " + type.toSql()
|
||||
+ " to narrower type " + other.type.toSql());
|
||||
throw new DdlException(
|
||||
"Can not change from wider type " + type.toSql() + " to narrower type " + other.type.toSql());
|
||||
}
|
||||
}
|
||||
|
||||
@ -442,9 +443,9 @@ public class Column implements Writable {
|
||||
}
|
||||
}
|
||||
|
||||
if ((getDataType() == PrimitiveType.VARCHAR && other.getDataType() == PrimitiveType.VARCHAR)
|
||||
|| (getDataType() == PrimitiveType.CHAR && other.getDataType() == PrimitiveType.VARCHAR)
|
||||
|| (getDataType() == PrimitiveType.CHAR && other.getDataType() == PrimitiveType.CHAR)) {
|
||||
if ((getDataType() == PrimitiveType.VARCHAR && other.getDataType() == PrimitiveType.VARCHAR) || (
|
||||
getDataType() == PrimitiveType.CHAR && other.getDataType() == PrimitiveType.VARCHAR) || (
|
||||
getDataType() == PrimitiveType.CHAR && other.getDataType() == PrimitiveType.CHAR)) {
|
||||
if (getStrLen() > other.getStrLen()) {
|
||||
throw new DdlException("Cannot shorten string length");
|
||||
}
|
||||
@ -522,20 +523,22 @@ public class Column implements Writable {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("`").append(name).append("` ");
|
||||
String typeStr = type.toSql();
|
||||
sb.append(typeStr).append(" ");
|
||||
if (aggregationType != null && aggregationType != AggregateType.NONE
|
||||
&& !isUniqueTable && !isAggregationTypeImplicit) {
|
||||
sb.append(aggregationType.name()).append(" ");
|
||||
sb.append(typeStr);
|
||||
if (aggregationType != null && aggregationType != AggregateType.NONE && !isUniqueTable
|
||||
&& !isAggregationTypeImplicit) {
|
||||
sb.append(" ").append(aggregationType.name());
|
||||
}
|
||||
if (isAllowNull) {
|
||||
sb.append("NULL ");
|
||||
sb.append(" NULL");
|
||||
} else {
|
||||
sb.append("NOT NULL ");
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
if (defaultValue != null && getDataType() != PrimitiveType.HLL && getDataType() != PrimitiveType.BITMAP) {
|
||||
sb.append("DEFAULT \"").append(defaultValue).append("\" ");
|
||||
sb.append(" DEFAULT \"").append(defaultValue).append("\"");
|
||||
}
|
||||
if (StringUtils.isNotBlank(comment)) {
|
||||
sb.append(" COMMENT '").append(getComment(true)).append("'");
|
||||
}
|
||||
sb.append("COMMENT \"").append(getComment(true)).append("\"");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
@ -547,9 +550,8 @@ public class Column implements Writable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, getDataType(), aggregationType, isAggregationTypeImplicit,
|
||||
isKey, isAllowNull, getDefaultValue(), getStrLen(), getPrecision(), getScale(),
|
||||
comment, visible, children);
|
||||
return Objects.hash(name, getDataType(), aggregationType, isAggregationTypeImplicit, isKey, isAllowNull,
|
||||
getDefaultValue(), getStrLen(), getPrecision(), getScale(), comment, visible, children);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -62,10 +62,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, connectContext);
|
||||
Catalog.getCurrentCatalog().createDb(createDbStmt);
|
||||
String varcharTable = "CREATE TABLE `test`.`varchar_table`\n" + "(\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT '',\n"
|
||||
+ " `username` varchar(255) NOT NULL COMMENT ''\n"
|
||||
+ " `userId` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) NOT NULL\n"
|
||||
+ ") ENGINE = OLAP unique KEY(`userId`)\n"
|
||||
+ "COMMENT \"varchar_table\"\n"
|
||||
+ "COMMENT 'varchar_table'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -76,20 +76,20 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTable(varcharTable);
|
||||
String decimalTable = "CREATE TABLE `test`.`decimal_table`\n"
|
||||
+ "(\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT '',\n"
|
||||
+ " `amount_decimal` decimal(10, 2) NOT NULL COMMENT ''\n"
|
||||
+ " `userId` varchar(255) NOT NULL,\n"
|
||||
+ " `amount_decimal` decimal(10, 2) NOT NULL\n"
|
||||
+ ") ENGINE = OLAP unique KEY(`userId`)\n"
|
||||
+ "COMMENT \"decimal_table\"\n"
|
||||
+ "COMMENT 'decimal_table'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
+ "\"in_memory\" = \"false\",\n"
|
||||
+ "\"storage_format\" = \"V2\")";
|
||||
createTable(decimalTable);
|
||||
String joinTable = "CREATE TABLE `test`.`join_table` (`userId` varchar(255) NOT NULL COMMENT '',"
|
||||
+ " `status` int NOT NULL COMMENT '')"
|
||||
String joinTable = "CREATE TABLE `test`.`join_table` (`userId` varchar(255) NOT NULL,"
|
||||
+ " `status` int NOT NULL)"
|
||||
+ " ENGINE = OLAP unique KEY(`userId`)\n"
|
||||
+ "COMMENT \"join_table\"\n"
|
||||
+ "COMMENT 'join_table'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -143,11 +143,11 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromVarchar);
|
||||
ShowResultSet showResultSet = showCreateTable("select_varchar");
|
||||
Assert.assertEquals("CREATE TABLE `select_varchar` (\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `userId` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`userId`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -164,10 +164,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromFunction1);
|
||||
ShowResultSet showResultSet1 = showCreateTable("select_function_1");
|
||||
Assert.assertEquals("CREATE TABLE `select_function_1` (\n"
|
||||
+ " `_col0` bigint(20) NULL COMMENT \"\"\n"
|
||||
+ " `_col0` bigint(20) NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`_col0`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`_col0`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -182,14 +182,14 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromFunction2);
|
||||
ShowResultSet showResultSet2 = showCreateTable("select_function_2");
|
||||
Assert.assertEquals("CREATE TABLE `select_function_2` (\n"
|
||||
+ " `_col0` bigint(20) NULL COMMENT \"\",\n"
|
||||
+ " `_col1` bigint(20) NULL COMMENT \"\",\n"
|
||||
+ " `_col2` bigint(20) NULL COMMENT \"\",\n"
|
||||
+ " `_col3` bigint(20) NULL COMMENT \"\",\n"
|
||||
+ " `_col4` bigint(20) NULL COMMENT \"\"\n"
|
||||
+ " `_col0` bigint(20) NULL,\n"
|
||||
+ " `_col1` bigint(20) NULL,\n"
|
||||
+ " `_col2` bigint(20) NULL,\n"
|
||||
+ " `_col3` bigint(20) NULL,\n"
|
||||
+ " `_col4` bigint(20) NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`_col0`, `_col1`, `_col2`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`_col0`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -206,10 +206,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectAlias1);
|
||||
ShowResultSet showResultSet1 = showCreateTable("select_alias_1");
|
||||
Assert.assertEquals("CREATE TABLE `select_alias_1` (\n"
|
||||
+ " `amount` bigint(20) NULL COMMENT \"\"\n"
|
||||
+ " `amount` bigint(20) NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`amount`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`amount`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -222,11 +222,11 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectAlias2);
|
||||
ShowResultSet showResultSet2 = showCreateTable("select_alias_2");
|
||||
Assert.assertEquals("CREATE TABLE `select_alias_2` (\n"
|
||||
+ " `alias_name` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `alias_name` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`alias_name`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`alias_name`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -243,12 +243,12 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromJoin);
|
||||
ShowResultSet showResultSet = showCreateTable("select_join");
|
||||
Assert.assertEquals("CREATE TABLE `select_join` (\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL COMMENT \"\",\n"
|
||||
+ " `status` int(11) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `userId` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL,\n"
|
||||
+ " `status` int(11) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`userId`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -262,13 +262,13 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromJoin1);
|
||||
ShowResultSet showResultSet1 = showCreateTable("select_join1");
|
||||
Assert.assertEquals("CREATE TABLE `select_join1` (\n"
|
||||
+ " `userId1` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `userId2` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL COMMENT \"\",\n"
|
||||
+ " `status` int(11) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `userId1` varchar(255) NOT NULL,\n"
|
||||
+ " `userId2` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL,\n"
|
||||
+ " `status` int(11) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`userId1`, `userId2`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId1`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -286,12 +286,12 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromName);
|
||||
ShowResultSet showResultSet = showCreateTable("select_name");
|
||||
Assert.assertEquals("CREATE TABLE `select_name` (\n"
|
||||
+ " `user` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `testname` varchar(255) REPLACE NOT NULL COMMENT \"\",\n"
|
||||
+ " `userstatus` int(11) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `user` varchar(255) NOT NULL,\n"
|
||||
+ " `testname` varchar(255) REPLACE NOT NULL,\n"
|
||||
+ " `userstatus` int(11) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`user`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`user`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -307,10 +307,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromName);
|
||||
ShowResultSet showResultSet = showCreateTable("select_union");
|
||||
Assert.assertEquals("CREATE TABLE `select_union` (\n"
|
||||
+ " `userId` varchar(255) NULL COMMENT \"\"\n"
|
||||
+ " `userId` varchar(255) NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`userId`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -326,10 +326,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromCte);
|
||||
ShowResultSet showResultSet = showCreateTable("select_cte");
|
||||
Assert.assertEquals("CREATE TABLE `select_cte` (\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT \"\"\n"
|
||||
+ " `userId` varchar(255) NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`userId`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -342,10 +342,10 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromCteAndUnion);
|
||||
ShowResultSet showResultSet1 = showCreateTable("select_cte_union");
|
||||
Assert.assertEquals("CREATE TABLE `select_cte_union` (\n"
|
||||
+ " `id` tinyint(4) NOT NULL COMMENT \"\"\n"
|
||||
+ " `id` tinyint(4) NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`id`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "DISTRIBUTED BY HASH(`id`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_allocation\" = \"tag.location.default: 1\",\n"
|
||||
@ -364,11 +364,11 @@ public class CreateTableAsSelectStmtTest {
|
||||
createTableAsSelect(selectFromPartition);
|
||||
ShowResultSet showResultSet = showCreateTable("selectPartition");
|
||||
Assert.assertEquals("CREATE TABLE `selectPartition` (\n"
|
||||
+ " `userId` varchar(255) NOT NULL COMMENT \"\",\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL COMMENT \"\"\n"
|
||||
+ " `userId` varchar(255) NOT NULL,\n"
|
||||
+ " `username` varchar(255) REPLACE NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "AGGREGATE KEY(`userId`)\n"
|
||||
+ "COMMENT \"OLAP\"\n"
|
||||
+ "COMMENT 'OLAP'\n"
|
||||
+ "PARTITION BY LIST(`userId`)\n"
|
||||
+ "(PARTITION p1 VALUES IN (\"CA\",\"GB\",\"US\",\"ZH\"))\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
|
||||
@ -17,47 +17,33 @@
|
||||
|
||||
package org.apache.doris.analysis;
|
||||
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.mysql.privilege.MockedAuth;
|
||||
import org.apache.doris.mysql.privilege.PaloAuth;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.common.FeConstants;
|
||||
import org.apache.doris.qe.ShowResultSet;
|
||||
import org.apache.doris.utframe.TestWithFeService;
|
||||
|
||||
import mockit.Mocked;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ShowCreateTableStmtTest {
|
||||
private Analyzer analyzer;
|
||||
public class ShowCreateTableStmtTest extends TestWithFeService {
|
||||
|
||||
@Mocked
|
||||
private PaloAuth auth;
|
||||
@Mocked
|
||||
private ConnectContext ctx;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
|
||||
MockedAuth.mockedAuth(auth);
|
||||
MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
|
||||
@Override
|
||||
protected void runBeforeAll() throws Exception {
|
||||
FeConstants.runningUnitTest = true;
|
||||
createDatabase("test");
|
||||
useDatabase("test");
|
||||
createTable("create table table1\n"
|
||||
+ "(k1 int comment 'test column k1', k2 int comment 'test column k2') comment 'test table1' distributed by hash(k1) buckets 1\n"
|
||||
+ "properties(\"replication_num\" = \"1\");");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNormal() throws AnalysisException {
|
||||
ShowCreateTableStmt stmt = new ShowCreateTableStmt(new TableName("testDb", "testTbl"));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW CREATE TABLE testCluster:testDb.testTbl", stmt.toString());
|
||||
Assert.assertEquals("testCluster:testDb", stmt.getDb());
|
||||
Assert.assertEquals("testTbl", stmt.getTable());
|
||||
Assert.assertEquals(2, stmt.getMetaData().getColumnCount());
|
||||
Assert.assertEquals("Table", stmt.getMetaData().getColumn(0).getName());
|
||||
Assert.assertEquals("Create Table", stmt.getMetaData().getColumn(1).getName());
|
||||
public void testNormal() throws Exception {
|
||||
String sql = "show create table table1";
|
||||
ShowResultSet showResultSet = showCreateTable(sql);
|
||||
String showSql = showResultSet.getResultRows().get(0).get(1);
|
||||
Assertions.assertTrue(showSql.contains("`k1` int(11) NULL COMMENT 'test column k1'"));
|
||||
Assertions.assertTrue(showSql.contains("COMMENT 'test table1'"));
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testNoTbl() throws AnalysisException {
|
||||
ShowCreateTableStmt stmt = new ShowCreateTableStmt(null);
|
||||
stmt.analyze(analyzer);
|
||||
Assert.fail("No Exception throws.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import org.apache.doris.analysis.CreateViewStmt;
|
||||
import org.apache.doris.analysis.DropPolicyStmt;
|
||||
import org.apache.doris.analysis.DropSqlBlockRuleStmt;
|
||||
import org.apache.doris.analysis.ExplainOptions;
|
||||
import org.apache.doris.analysis.ShowCreateTableStmt;
|
||||
import org.apache.doris.analysis.SqlParser;
|
||||
import org.apache.doris.analysis.SqlScanner;
|
||||
import org.apache.doris.analysis.StatementBase;
|
||||
@ -44,6 +45,8 @@ import org.apache.doris.planner.Planner;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.qe.OriginStatement;
|
||||
import org.apache.doris.qe.QueryState;
|
||||
import org.apache.doris.qe.ShowExecutor;
|
||||
import org.apache.doris.qe.ShowResultSet;
|
||||
import org.apache.doris.qe.StmtExecutor;
|
||||
import org.apache.doris.system.Backend;
|
||||
import org.apache.doris.system.SystemInfoService;
|
||||
@ -357,6 +360,12 @@ public abstract class TestWithFeService {
|
||||
connectContext.setDatabase(ClusterNamespace.getFullName(SystemInfoService.DEFAULT_CLUSTER, dbName));
|
||||
}
|
||||
|
||||
protected ShowResultSet showCreateTable(String sql) throws Exception {
|
||||
ShowCreateTableStmt stmt = (ShowCreateTableStmt) parseAndAnalyzeStmt(sql);
|
||||
ShowExecutor executor = new ShowExecutor(connectContext, stmt);
|
||||
return executor.execute();
|
||||
}
|
||||
|
||||
public void createTable(String sql) throws Exception {
|
||||
createTables(sql);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user