This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch dev-1.0.1 in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 1a43e0d4125bff42f9b79a72caaf9580a3716322 Author: xueweizhang <[email protected]> AuthorDate: Sun May 29 18:02:16 2022 +0800 [bugfix] Fix create table like when having hidden columns (#9694) --- .../java/org/apache/doris/catalog/Catalog.java | 24 +++++++--- .../data_model/unique/test_unique_table_like.out | 15 +++++++ .../unique/test_unique_table_like.groovy | 52 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java index ffded947bf..bf04888bf3 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java @@ -3087,7 +3087,7 @@ public class Catalog { throw new DdlException("Table[" + table.getName() + "] is external, not support rollup copy"); } - Catalog.getDdlStmt(stmt, stmt.getDbName(), table, createTableStmt, null, null, false, false); + Catalog.getDdlStmt(stmt, stmt.getDbName(), table, createTableStmt, null, null, false, false, true); if (createTableStmt.isEmpty()) { ErrorReport.reportDdlException(ErrorCode.ERROR_CREATE_TABLE_LIKE_EMPTY, "CREATE"); } @@ -4076,11 +4076,18 @@ public class Catalog { public static void getDdlStmt(Table table, List<String> createTableStmt, List<String> addPartitionStmt, List<String> createRollupStmt, boolean separatePartition, boolean hidePassword) { - getDdlStmt(null, null, table, createTableStmt, addPartitionStmt, createRollupStmt, separatePartition, hidePassword); + getDdlStmt(null, null, table, createTableStmt, addPartitionStmt, createRollupStmt, + separatePartition, hidePassword, false); } - public static void getDdlStmt(DdlStmt ddlStmt, String dbName, Table table, List<String> createTableStmt, List<String> addPartitionStmt, - List<String> createRollupStmt, boolean separatePartition, boolean hidePassword) { + /** + * Get table ddl stmt. + * + * @param getDdlForLike Get schema for 'create table like' or not. when true, without hidden columns. + */ + public static void getDdlStmt(DdlStmt ddlStmt, String dbName, Table table, List<String> createTableStmt, + List<String> addPartitionStmt, List<String> createRollupStmt, + boolean separatePartition, boolean hidePassword, boolean getDdlForLike) { StringBuilder sb = new StringBuilder(); // 1. create table @@ -4105,7 +4112,14 @@ public class Catalog { } sb.append("`").append(table.getName()).append("` (\n"); int idx = 0; - for (Column column : table.getBaseSchema()) { + List<Column> columns; + // when 'create table B like A', always return schema of A without hidden columns + if (getDdlForLike) { + columns = table.getBaseSchema(false); + } else { + columns = table.getBaseSchema(); + } + for (Column column : columns) { if (idx++ != 0) { sb.append(",\n"); } diff --git a/regression-test/data/data_model/unique/test_unique_table_like.out b/regression-test/data/data_model/unique/test_unique_table_like.out new file mode 100644 index 0000000000..ffcbaf18cc --- /dev/null +++ b/regression-test/data/data_model/unique/test_unique_table_like.out @@ -0,0 +1,15 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !desc_uniq_table -- +k INT Yes true \N +int_value INT Yes false \N REPLACE +char_value CHAR(10) Yes false \N REPLACE +date_value DATE Yes false \N REPLACE +__DORIS_DELETE_SIGN__ TINYINT No false 0 REPLACE + +-- !desc_uniq_table -- +k INT Yes true \N +int_value INT Yes false \N REPLACE +char_value CHAR(10) Yes false \N REPLACE +date_value DATE Yes false \N REPLACE +__DORIS_DELETE_SIGN__ TINYINT No false 0 REPLACE + diff --git a/regression-test/suites/data_model/unique/test_unique_table_like.groovy b/regression-test/suites/data_model/unique/test_unique_table_like.groovy new file mode 100644 index 0000000000..6250b61138 --- /dev/null +++ b/regression-test/suites/data_model/unique/test_unique_table_like.groovy @@ -0,0 +1,52 @@ +// 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_unique_table_like", "data_model") { + def dbName = "test_unique_db" + List<List<Object>> db = sql "show databases like '${dbName}'" + if (db.size() == 0) { + sql "CREATE DATABASE ${dbName}" + } + sql "use ${dbName}" + + // test uniq table like + def tbNameA = "test_uniq" + def tbNameB = "test_uniq_like" + sql "ADMIN SET FRONTEND CONFIG ('enable_batch_delete_by_default' = 'true')" + sql "SET show_hidden_columns=true" + sql "DROP TABLE IF EXISTS ${tbNameA}" + sql """ + CREATE TABLE IF NOT EXISTS ${tbNameA} ( + k int, + int_value int, + char_value char(10), + date_value date + ) + ENGINE=OLAP + UNIQUE KEY(k) + DISTRIBUTED BY HASH(k) BUCKETS 5 properties("replication_num" = "1"); + """ + qt_desc_uniq_table "desc ${tbNameA}" + sql """ + CREATE TABLE IF NOT EXISTS ${tbNameB} LIKE ${tbNameA}; + """ + + qt_desc_uniq_table "desc ${tbNameB}" + sql "DROP TABLE ${tbNameA}" + sql "DROP TABLE ${tbNameB}" +} + --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
