Skip to content

Commit

Permalink
Table copy supports creating empty range partition
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
xinghuayu007 authored and martongreber committed Aug 16, 2024
1 parent ae4a3a9 commit a9d42cd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/kudu/tools/kudu-tool-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions src/kudu/tools/table_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit a9d42cd

Please sign in to comment.