This is an automated email from the ASF dual-hosted git repository. mgreber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit a9d42cdb8438858cf1bd18c203d1687ed5734346 Author: xinghuayu007 <[email protected]> AuthorDate: Fri Aug 2 17:57:02 2024 +0800 Table copy supports creating empty range partition Currently when the source table's range partition is empty, using CLI command 'table copy xxx --create_table=true' to create the destination table, it will create a table with unbouned partition table. That is not right. Empty range partition is not equal to unbouned partition. For example: The source table is: TABLE test1 ( key INT32 NOT NULL, int_val INT32 NOT NULL, string_val STRING NULLABLE, PRIMARY KEY (key) ) HASH (key) PARTITIONS 2, RANGE (key) () OWNER root REPLICAS 1 COMMENT The destination table is: TABLE test1 ( key INT32 NOT NULL, int_val INT32 NOT NULL, string_val STRING NULLABLE, PRIMARY KEY (key) ) HASH (key) PARTITIONS 2, RANGE (key) ( PARTITION UNBOUNDED ) Change-Id: I59f62d7114772112b39f9fba0c5c90dd0a418a97 Reviewed-on: http://gerrit.cloudera.org:8080/21637 Reviewed-by: Yingchun Lai <[email protected]> Tested-by: Marton Greber <[email protected]> Reviewed-by: Marton Greber <[email protected]> --- src/kudu/tools/kudu-tool-test.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/kudu/tools/table_scanner.cc | 2 ++ 2 files changed, 42 insertions(+) diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc index 4ef500923..6112f31d9 100644 --- a/src/kudu/tools/kudu-tool-test.cc +++ b/src/kudu/tools/kudu-tool-test.cc @@ -5990,6 +5990,46 @@ TEST_F(ToolTest, TableScanFaultTolerant) { } } +TEST_F(ToolTest, TableCopyCreateEmptyPartition) { + NO_FATALS(StartExternalMiniCluster()); + shared_ptr<KuduClient> client; + ASSERT_OK(cluster_->CreateClient(nullptr, &client)); + unique_ptr<KuduTableCreator> table_creator(client->NewTableCreator()); + KuduSchema schema = KuduSchema::FromSchema(GetSimpleTestSchema()); + const string& kSrcTableName = "test1"; + const string& kDstTableName = "test2"; + // Create a table with empty range partition. + ASSERT_OK(table_creator->table_name(kSrcTableName) + .schema(&schema) + .num_replicas(1) + .add_hash_partitions({"key"}, 2) + .set_range_partition_columns({"key"}) + .set_allow_empty_partition(true) + .Create()); + + const string& master_addr = cluster_->master()->bound_rpc_addr().ToString(); + string stdout; + NO_FATALS(RunActionStdoutString(Substitute("table describe $0 $1", + master_addr, + kSrcTableName), &stdout)); + // Check the source table's range partition schema. + ASSERT_STR_CONTAINS(stdout, "RANGE (key) ()"); + + // Table copy the source table and create the destination table. + NO_FATALS(RunTool( + Substitute("table copy $0 $1 $2 --dst_table=$3 " + "--create_table=true", + master_addr, kSrcTableName, + master_addr, kDstTableName + ), nullptr, nullptr)); + stdout.clear(); + NO_FATALS(RunActionStdoutString(Substitute("table describe $0 $1", + master_addr, + kDstTableName), &stdout)); + // Check the destination table's range partition schema. + ASSERT_STR_CONTAINS(stdout, "RANGE (key) ()"); +} + TEST_F(ToolTest, TableCopyLimitSpeed) { SKIP_IF_SLOW_NOT_ALLOWED(); diff --git a/src/kudu/tools/table_scanner.cc b/src/kudu/tools/table_scanner.cc index 44529c93a..34e74daec 100644 --- a/src/kudu/tools/table_scanner.cc +++ b/src/kudu/tools/table_scanner.cc @@ -553,6 +553,8 @@ Status CreateDstTableIfNeeded(const client::sp::shared_ptr<KuduTable>& src_table table_creator->set_range_partition_columns({}); } + table_creator->set_allow_empty_partition(true); + // Create table. RETURN_NOT_OK(table_creator->Create()); LOG(INFO) << "Table " << dst_table_name << " created successfully";
