[fix](create table) modify varchar default length 1 to 65533 (#21302)
*modify archer default length 1 to varchar.max.length , when create table.*
```mysql
create table t2 (
k1 CHAR,
K2 CHAR(10) ,
K3 VARCHAR ,
K4 VARCHAR(1024) )
duplicate key (k1)
distributed by hash(k1) buckets 1
properties('replication_num' = '1');
desc t2;
```
| Field | Type | Null | Key | Default | Extra |
| -- |--|--| -| -| -|
| k1 | CHAR(1) | Yes | true | NULL | |
| K2 | CHAR(10) | Yes | false | NULL | NONE |
| K3 | VARCHAR(65533) | Yes | false | NULL | NONE |
| K4 | VARCHAR(1024) | Yes | false | NULL | NONE |
This commit is contained in:
@ -263,11 +263,14 @@ public class ColumnDef {
|
||||
if (typeDef.getType().isScalarType()) {
|
||||
final ScalarType targetType = (ScalarType) typeDef.getType();
|
||||
if (targetType.getPrimitiveType().isStringType() && !targetType.isLengthSet()) {
|
||||
if (targetType.getPrimitiveType() != PrimitiveType.STRING) {
|
||||
targetType.setLength(1);
|
||||
} else {
|
||||
if (targetType.getPrimitiveType() == PrimitiveType.VARCHAR) {
|
||||
// always set varchar length MAX_VARCHAR_LENGTH
|
||||
targetType.setLength(ScalarType.MAX_VARCHAR_LENGTH);
|
||||
} else if (targetType.getPrimitiveType() == PrimitiveType.STRING) {
|
||||
// always set text length MAX_STRING_LENGTH
|
||||
targetType.setLength(ScalarType.MAX_STRING_LENGTH);
|
||||
} else {
|
||||
targetType.setLength(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -725,4 +725,18 @@ public class CreateTableTest {
|
||||
+ "distributed by hash(k1) buckets 1 properties('replication_num' = '1','in_memory'='true');");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithStringLen() throws DdlException {
|
||||
ExceptionChecker.expectThrowsNoException(() -> {
|
||||
createTable("create table test.test_strLen(k1 CHAR, k2 CHAR(10) , k3 VARCHAR ,k4 VARCHAR(10))"
|
||||
+ " duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1');");
|
||||
});
|
||||
Database db = Env.getCurrentInternalCatalog().getDbOrDdlException("default_cluster:test");
|
||||
OlapTable tb = (OlapTable) db.getTableOrDdlException("test_strLen");
|
||||
Assert.assertEquals(1, tb.getColumn("k1").getStrLen());
|
||||
Assert.assertEquals(10, tb.getColumn("k2").getStrLen());
|
||||
Assert.assertEquals(ScalarType.MAX_VARCHAR_LENGTH, tb.getColumn("k3").getStrLen());
|
||||
Assert.assertEquals(10, tb.getColumn("k4").getStrLen());
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,12 +50,12 @@ public class TableFunctionPlanTest {
|
||||
CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, ctx);
|
||||
Env.getCurrentEnv().createDb(createDbStmt);
|
||||
// 3. create table tbl1
|
||||
String createTblStmtStr = "create table db1.tbl1(k1 int, k2 varchar, k3 varchar) "
|
||||
String createTblStmtStr = "create table db1.tbl1(k1 int, k2 varchar(1), k3 varchar(1)) "
|
||||
+ "DUPLICATE KEY(k1) distributed by hash(k1) buckets 3 properties('replication_num' = '1');";
|
||||
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
|
||||
Env.getCurrentEnv().createTable(createTableStmt);
|
||||
|
||||
createTblStmtStr = "create table db1.tbl2(k1 int, k2 varchar, v1 bitmap bitmap_union) "
|
||||
createTblStmtStr = "create table db1.tbl2(k1 int, k2 varchar(1), v1 bitmap bitmap_union) "
|
||||
+ "distributed by hash(k1) buckets 3 properties('replication_num' = '1');";
|
||||
createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
|
||||
Env.getCurrentEnv().createTable(createTableStmt);
|
||||
|
||||
Reference in New Issue
Block a user