You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2022/03/14 22:58:40 UTC

[kudu] branch master updated: [tools] Support copying unpartitioned table

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 7189b51  [tools] Support copying unpartitioned table
7189b51 is described below

commit 7189b519625d8f6ef7f70bc259733a672a28267f
Author: zhangyifan27 <ch...@163.com>
AuthorDate: Mon Mar 14 23:08:00 2022 +0800

    [tools] Support copying unpartitioned table
    
    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 <mr...@cloudera.com>
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
    Reviewed-by: Alexey Serbin <al...@apache.org>
    Tested-by: Alexey Serbin <al...@apache.org>
---
 src/kudu/tools/kudu-tool-test.cc | 22 ++++++++++++++++++++++
 src/kudu/tools/table_scanner.cc  |  6 ++++++
 2 files changed, 28 insertions(+)

diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 1b73a3b..793e738 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -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
@@ -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();
@@ -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;
@@ -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));
@@ -932,6 +953,7 @@ INSTANTIATE_TEST_SUITE_P(CopyTableParameterized,
                                            kTestCopyTableUpsert,
                                            kTestCopyTableSchemaOnly,
                                            kTestCopyTableComplexSchema,
+                                           kTestCopyUnpartitionedTable,
                                            kTestCopyTablePredicates));
 
 void ToolTest::StartExternalMiniCluster(ExternalMiniClusterOptions opts) {
diff --git a/src/kudu/tools/table_scanner.cc b/src/kudu/tools/table_scanner.cc
index 3c7923f..8be3b4c 100644
--- a/src/kudu/tools/table_scanner.cc
+++ b/src/kudu/tools/table_scanner.cc
@@ -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";