Skip to content

Commit

Permalink
[Feat](planner)create table stmt offer default distribution attribute…
Browse files Browse the repository at this point in the history
… :random distribution and auto bucket (#35189)

Co-authored-by: feiniaofeiafei <[email protected]>
  • Loading branch information
feiniaofeiafei and feiniaofeiafei authored May 22, 2024
1 parent 7056f99 commit 7e2bcb5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public void analyze(Analyzer analyzer) throws UserException {

// analyze distribution
if (distributionDesc == null) {
throw new AnalysisException("Create olap table should contain distribution desc");
distributionDesc = new RandomDistributionDesc(FeConstants.default_bucket_num, true);
}
distributionDesc.analyze(columnSet, columnDefs, keysDesc);
if (distributionDesc.type == DistributionInfo.DistributionInfoType.RANDOM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void validate(ConnectContext ctx) {

if (engineName.equalsIgnoreCase("olap")) {
if (distribution == null) {
throw new AnalysisException("Create olap table should contain distribution desc");
distribution = new DistributionDescriptor(false, true, FeConstants.default_bucket_num, null);
}
properties = maybeRewriteByAutoBucket(distribution, properties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !test_insert --
1

-- !test_select --
1 2

-- !test_show --
test_create_table_without_distribution CREATE TABLE `test_create_table_without_distribution` (\n `a` INT NULL,\n `b` INT NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`a`, `b`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY RANDOM BUCKETS AUTO\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V1",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n);

-- !test_insert_old_planner --
1

-- !test_select_old_planner --
1 2

-- !test_show_old_planner --
test_create_table_without_distribution CREATE TABLE `test_create_table_without_distribution` (\n `a` INT NULL,\n `b` INT NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`a`, `b`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY RANDOM BUCKETS AUTO\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V1",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n);

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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_create_table_without_distribution") {
sql "SET enable_nereids_planner=true;"
sql "SET enable_fallback_to_original_planner=false;"
multi_sql """
drop table if exists test_create_table_without_distribution;
create table test_create_table_without_distribution(a int, b int) properties ("replication_num"="1")
"""
qt_test_insert """
insert into test_create_table_without_distribution values(1,2);
"""
qt_test_select "select * from test_create_table_without_distribution;"
qt_test_show " show create table test_create_table_without_distribution;"

sql "SET enable_nereids_planner=false;"
multi_sql """
drop table if exists test_create_table_without_distribution;
create table test_create_table_without_distribution(a int, b int) properties ("replication_num"="1")
"""
qt_test_insert_old_planner """
insert into test_create_table_without_distribution values(1,2);
"""
qt_test_select_old_planner "select * from test_create_table_without_distribution;"
qt_test_show_old_planner " show create table test_create_table_without_distribution;"


}

0 comments on commit 7e2bcb5

Please sign in to comment.