Skip to content

Commit

Permalink
[tools] Support copying unpartitioned table
Browse files Browse the repository at this point in the history
The "kudu table copy" tool generated an error while copying
an unpartitioned table: Invalid argument: Table partitioning must be
specified using add_hash_partitions or set_range_partition_columns
This patch fixed it.

Change-Id: I4fcdcf93aadfaa2df59e59afa7bb3524ede2ac60
Reviewed-on: http://gerrit.cloudera.org:8080/18318
Reviewed-by: Mahesh Reddy <[email protected]>
Reviewed-by: Andrew Wong <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
  • Loading branch information
zhangyifan27 authored and alexeyserbin committed Mar 14, 2022
1 parent 2a5e565 commit 7189b51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/kudu/tools/kudu-tool-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ enum RunCopyTableCheckArgsType {
kTestCopyTableUpsert,
kTestCopyTableSchemaOnly,
kTestCopyTableComplexSchema,
kTestCopyUnpartitionedTable,
kTestCopyTablePredicates
};
// Subclass of ToolTest that allows running individual test cases with different parameters to run
Expand All @@ -721,6 +722,10 @@ class ToolTestCopyTableParameterized :
KuduSchema schema;
ASSERT_OK(CreateComplexSchema(&schema));
ww.set_schema(schema);
} else if (test_case_ == kTestCopyUnpartitionedTable) {
KuduSchema schema;
ASSERT_OK(CreateUnpartitionedTable(&schema));
ww.set_schema(schema);
}
ww.Setup();
ww.Start();
Expand Down Expand Up @@ -759,6 +764,9 @@ class ToolTestCopyTableParameterized :
args.columns = kComplexSchemaColumns;
args.mode = TableCopyMode::INSERT_TO_NOT_EXIST_TABLE;
return { args };
case kTestCopyUnpartitionedTable:
args.mode = TableCopyMode::INSERT_TO_NOT_EXIST_TABLE;
return {args};
case kTestCopyTablePredicates: {
auto mid = total_rows_ / 2;
vector<RunCopyTableCheckArgs> multi_args;
Expand Down Expand Up @@ -898,6 +906,19 @@ class ToolTestCopyTableParameterized :
return Status::OK();
}

Status CreateUnpartitionedTable(KuduSchema* schema) {
shared_ptr<KuduClient> client;
RETURN_NOT_OK(cluster_->CreateClient(nullptr, &client));
unique_ptr<KuduTableCreator> table_creator(client->NewTableCreator());
*schema = KuduSchema::FromSchema(GetSimpleTestSchema());
RETURN_NOT_OK(table_creator->table_name(kTableName)
.schema(schema)
.set_range_partition_columns({})
.num_replicas(1)
.Create());
return Status::OK();
}

void InsertOneRowWithNullCell() {
shared_ptr<KuduClient> client;
ASSERT_OK(cluster_->CreateClient(nullptr, &client));
Expand Down Expand Up @@ -932,6 +953,7 @@ INSTANTIATE_TEST_SUITE_P(CopyTableParameterized,
kTestCopyTableUpsert,
kTestCopyTableSchemaOnly,
kTestCopyTableComplexSchema,
kTestCopyUnpartitionedTable,
kTestCopyTablePredicates));

void ToolTest::StartExternalMiniCluster(ExternalMiniClusterOptions opts) {
Expand Down
6 changes: 6 additions & 0 deletions src/kudu/tools/table_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ Status CreateDstTableIfNeeded(const client::sp::shared_ptr<KuduTable>& src_table
table_creator->add_range_partition(lower.release(), upper.release());
}

if (partition_schema.hash_schema().empty() &&
partition_schema.range_schema().column_ids.empty()) {
// This src table is unpartitioned, just create a table range partitioned on no columns.
table_creator->set_range_partition_columns({});
}

// Create table.
RETURN_NOT_OK(table_creator->Create());
LOG(INFO) << "Table " << dst_table_name << " created successfully";
Expand Down

0 comments on commit 7189b51

Please sign in to comment.