From edfbe2d39477e9f3946f1e9f40af2c36b29f9c0a Mon Sep 17 00:00:00 2001 From: changyuwei <2017501503@qq.com> Date: Wed, 28 Jun 2023 20:20:07 +0800 Subject: [PATCH 1/5] [fix](create table) modify varchar default length 1 to 65533 --- .../Create/CREATE-TABLE.md | 2 +- .../Create/CREATE-TABLE.md | 2 +- .../org/apache/doris/analysis/ColumnDef.java | 9 +++-- .../apache/doris/catalog/CreateTableTest.java | 14 +++++++ .../data/ddl_p0/test_createtable_strlen.out | 7 ++++ .../ddl_p0/test_createtable_strlen.groovy | 40 +++++++++++++++++++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 regression-test/data/ddl_p0/test_createtable_strlen.out create mode 100644 regression-test/suites/ddl_p0/test_createtable_strlen.groovy diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md index a2f8c4731bd7d1..2e3acc25e37551 100644 --- a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md +++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md @@ -92,7 +92,7 @@ Column definition list: CHAR[(length)] Fixed-length character string. Length range: 1 ~ 255. Default is 1 VARCHAR[(length)] - Variable length character string. Length range: 1 ~ 65533. Default is 1 + Variable length character string. Length range: 1 ~ 65533. Default is 65533 HLL (1~16385 bytes) HyperLogLog column type, do not need to specify the length and default value. The length is controlled within the system according to the degree of data aggregation. Must be used with HLL_UNION aggregation type. diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md index 01266687c0bef4..2023b79d0339d2 100644 --- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE.md @@ -87,7 +87,7 @@ distribution_desc CHAR[(length)] 定长字符串。长度范围:1 ~ 255。默认为1 VARCHAR[(length)] - 变长字符串。长度范围:1 ~ 65533。默认为1 + 变长字符串。长度范围:1 ~ 65533。默认为65533 HLL (1~16385个字节) HyperLogLog 列类型,不需要指定长度和默认值。长度根据数据的聚合程度系统内控制。 必须配合 HLL_UNION 聚合类型使用。 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 433c9b615d56ff..b8c69b438b3d09 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 @@ -263,11 +263,14 @@ public void analyze(boolean isOlap) throws AnalysisException { 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); } } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java index 50373270052e4e..41a3507a20966f 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java @@ -725,4 +725,18 @@ public void testCreateTableWithInMemory() throws Exception { + "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()); + } } diff --git a/regression-test/data/ddl_p0/test_createtable_strlen.out b/regression-test/data/ddl_p0/test_createtable_strlen.out new file mode 100644 index 00000000000000..2a89d34218f47b --- /dev/null +++ b/regression-test/data/ddl_p0/test_createtable_strlen.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !create -- +k1 CHAR(1) Yes true \N +K2 CHAR(10) Yes false \N NONE +K3 VARCHAR(65533) Yes false \N NONE +K4 VARCHAR(10) Yes false \N NONE + diff --git a/regression-test/suites/ddl_p0/test_createtable_strlen.groovy b/regression-test/suites/ddl_p0/test_createtable_strlen.groovy new file mode 100644 index 00000000000000..daf4be557ed726 --- /dev/null +++ b/regression-test/suites/ddl_p0/test_createtable_strlen.groovy @@ -0,0 +1,40 @@ +// 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. + + +suite("test_createtable_strlen") { + + def table = "test_ct_strlen" + try { + sql """ + create table ${table} ( + k1 CHAR, + K2 CHAR(10) , + K3 VARCHAR , + K4 VARCHAR(10) ) + duplicate key (k1) + distributed by hash(k1) buckets 1 + properties('replication_num' = '1'); + """ + + qt_create """ desc ${table}; """ + + } finally { + sql """ DROP TABLE IF EXISTS ${table}; """ + } + +} \ No newline at end of file From 81f10c39e8ff89f2f91fc6271aeb542a7510377e Mon Sep 17 00:00:00 2001 From: changyuwei <2017501503@qq.com> Date: Thu, 29 Jun 2023 10:48:44 +0800 Subject: [PATCH 2/5] [fix](create table) modify varchar default length 1 to 65533 --- .../src/test/java/org/apache/doris/catalog/CreateTableTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java index 41a3507a20966f..2d5226d8e0d1e8 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.java @@ -730,7 +730,7 @@ public void testCreateTableWithInMemory() throws Exception { 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');"); + + " 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"); From 1fa84bc1055d1efd48570f9de9daf946aa79e81a Mon Sep 17 00:00:00 2001 From: changyuwei <2017501503@qq.com> Date: Sun, 9 Jul 2023 18:44:58 +0800 Subject: [PATCH 3/5] [fix](create table) modify varchar default length 1 to 65533 --- regression-test/suites/index_p0/test_bitmap_index.groovy | 8 ++++---- .../suites/inverted_index_p0/test_bitmap_index.groovy | 6 +++--- .../suites/inverted_index_p0/test_inverted_index.groovy | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/regression-test/suites/index_p0/test_bitmap_index.groovy b/regression-test/suites/index_p0/test_bitmap_index.groovy index d85b09fbdbbc90..017aab3b3d35df 100644 --- a/regression-test/suites/index_p0/test_bitmap_index.groovy +++ b/regression-test/suites/index_p0/test_bitmap_index.groovy @@ -29,7 +29,7 @@ suite("test_bitmap_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -110,7 +110,7 @@ suite("test_bitmap_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -196,12 +196,12 @@ suite("test_bitmap_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, k10 DECIMAL, - k11 BOOLEAN, + k11 BOOLEAN,s k12 DATEV2, k13 DATETIMEV2, k14 DATETIMEV2(3), diff --git a/regression-test/suites/inverted_index_p0/test_bitmap_index.groovy b/regression-test/suites/inverted_index_p0/test_bitmap_index.groovy index 3fabd292ce177c..0b360f3f6bffe4 100644 --- a/regression-test/suites/inverted_index_p0/test_bitmap_index.groovy +++ b/regression-test/suites/inverted_index_p0/test_bitmap_index.groovy @@ -29,7 +29,7 @@ suite("test_bitmap_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -102,7 +102,7 @@ suite("test_bitmap_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -180,7 +180,7 @@ suite("test_bitmap_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, diff --git a/regression-test/suites/inverted_index_p0/test_inverted_index.groovy b/regression-test/suites/inverted_index_p0/test_inverted_index.groovy index cdb19f53ff2591..25cfadff448261 100644 --- a/regression-test/suites/inverted_index_p0/test_inverted_index.groovy +++ b/regression-test/suites/inverted_index_p0/test_inverted_index.groovy @@ -29,7 +29,7 @@ suite("test_inverted_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -110,7 +110,7 @@ suite("test_inverted_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, @@ -196,7 +196,7 @@ suite("test_inverted_index", "inverted_index") { k3 INT, k4 BIGINT, k5 CHAR, - k6 VARCHAR, + k6 VARCHAR(1), k7 DATE, k8 DATETIME, k9 LARGEINT, From 9c8345d9e27b32ab5ca3da693776912b01dbaed8 Mon Sep 17 00:00:00 2001 From: changyuwei <2017501503@qq.com> Date: Sun, 9 Jul 2023 18:48:51 +0800 Subject: [PATCH 4/5] [fix](create table) modify varchar default length 1 to 65533 --- regression-test/suites/index_p0/test_bitmap_index.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regression-test/suites/index_p0/test_bitmap_index.groovy b/regression-test/suites/index_p0/test_bitmap_index.groovy index 017aab3b3d35df..73e5ab0d9ed05c 100644 --- a/regression-test/suites/index_p0/test_bitmap_index.groovy +++ b/regression-test/suites/index_p0/test_bitmap_index.groovy @@ -201,7 +201,7 @@ suite("test_bitmap_index") { k8 DATETIME, k9 LARGEINT, k10 DECIMAL, - k11 BOOLEAN,s + k11 BOOLEAN, k12 DATEV2, k13 DATETIMEV2, k14 DATETIMEV2(3), From 4f98174bceca64e646aab25a283d404999fc4385 Mon Sep 17 00:00:00 2001 From: changyuwei <2017501503@qq.com> Date: Mon, 10 Jul 2023 08:56:47 +0800 Subject: [PATCH 5/5] [fix](create table) modify varchar default length 1 to 65533 --- .../java/org/apache/doris/planner/TableFunctionPlanTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java index 0b1308c9b1ac23..6c353a67d13efa 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java @@ -50,12 +50,12 @@ public static void setUp() throws Exception { 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);