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 7ea5fe5ea [tools] update on 'kudu table create' command
7ea5fe5ea is described below

commit 7ea5fe5eae2e03fe2dc88e69a0dfe82d3f2d7088
Author: Alexey Serbin <ale...@apache.org>
AuthorDate: Thu Jul 28 19:02:11 2022 -0700

    [tools] update on 'kudu table create' command
    
    This patch updates the code related to the kudu CLI command
    'table create':
      * added 'owner' field to CreateTablePB/JSON
      * added 'comment' field to CreateTablePB/JSON
      * updated corresponding comments in the tool.proto file
      * fixed the example of the JSON object for CreateTablePB
      * made the example of JSON object for CreateTablePB redable
      * re-ordered string constants in tool_action_table.cc
      * other minor updates
    
    Change-Id: Ib2855ee07e0dae4df669e6dd1d5ad4281d3b906b
    Reviewed-on: http://gerrit.cloudera.org:8080/18796
    Tested-by: Kudu Jenkins
    Reviewed-by: Abhishek Chennaka <achenn...@cloudera.com>
    Reviewed-by: Attila Bukor <abu...@apache.org>
---
 src/kudu/tools/tool.proto           |  23 ++++---
 src/kudu/tools/tool_action_table.cc | 124 ++++++++++++++++++++++++------------
 2 files changed, 98 insertions(+), 49 deletions(-)

diff --git a/src/kudu/tools/tool.proto b/src/kudu/tools/tool.proto
index b73151376..dc735e137 100644
--- a/src/kudu/tools/tool.proto
+++ b/src/kudu/tools/tool.proto
@@ -426,9 +426,9 @@ message PartitionPB {
     // Column names of columns included in the range. All columns must be
     // a component of the primary key.
     repeated string columns = 1;
-    // Range bound.
+    // Range bounds.
     repeated RangeBoundPB range_bounds = 2;
-    // Range split.
+    // Range splits.
     repeated SplitValuePB range_splits = 3;
   }
 
@@ -467,17 +467,22 @@ message SchemaPB {
 // is converted to the PB. Used for creating a new table by kudu tool.
 message CreateTablePB {
   optional string table_name = 1;
-  // Representation of a table's schema, include columns's message and
-  // primary keys.
+  // Representation of a table's schema.
   optional SchemaPB schema = 2;
-  // The table partition message, include hash partition and range partition.
+  // Information on the table partitioning.
   optional PartitionPB partition = 3;
-  //Number of tablet replica
+  // Number of replicas for table's tablets.
   optional int32 num_replicas = 4;
   // The table's extra configuration properties.
   optional ExtraConfigPB extra_configs = 5;
-  // The dimension label for tablets that were created during table creation. 
Used for
-  // dimension-specific placement of tablet replicas corresponding to the 
partitions of
-  // the newly created table.
+  // The dimension label for tablets that were created during table creation.
+  // Used for dimension-specific placement of tablet replicas corresponding
+  // to the partitions of the newly created table.
   optional string dimension_label = 6;
+  // The owner for the newly created table. If not specified, the owner is
+  // automatically set to the effective OS user name that the kudu CLI tool is
+  // run with.
+  optional string owner = 7;
+  // Table's comment.
+  optional string comment = 8;
 }
diff --git a/src/kudu/tools/tool_action_table.cc 
b/src/kudu/tools/tool_action_table.cc
index 2ebc2f9b7..ad4dd3053 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -273,23 +273,71 @@ class TableAlter {
 
 namespace {
 
-const char* const kNewTableNameArg = "new_table_name";
-const char* const kColumnNameArg = "column_name";
-const char* const kNewColumnNameArg = "new_column_name";
-const char* const kKeyArg = "primary_key";
-const char* const kConfigNameArg = "config_name";
-const char* const kConfigValueArg = "config_value";
-const char* const kErrorMsgArg = "unable to parse value $0 for column $1 of 
type $2";
-const char* const kTableRangeLowerBoundArg = "table_range_lower_bound";
-const char* const kTableRangeUpperBoundArg = "table_range_upper_bound";
-const char* const kDefaultValueArg = "default_value";
-const char* const kCompressionTypeArg = "compression_type";
-const char* const kEncodingTypeArg = "encoding_type";
-const char* const kBlockSizeArg = "block_size";
-const char* const kColumnCommentArg = "column_comment";
-const char* const kCreateTableJSONArg = "create_table_json";
-const char* const kReplicationFactorArg = "replication_factor";
-const char* const kDataTypeArg = "data_type";
+constexpr const char* const kBlockSizeArg = "block_size";
+constexpr const char* const kColumnCommentArg = "column_comment";
+constexpr const char* const kColumnNameArg = "column_name";
+constexpr const char* const kCompressionTypeArg = "compression_type";
+constexpr const char* const kConfigNameArg = "config_name";
+constexpr const char* const kConfigValueArg = "config_value";
+constexpr const char* const kCreateTableExtraDescription =
+    R"*(provide parameters for the table to create as a JSON object, e.g.
+'{
+  "table_name": "test",
+  "schema": {
+    "columns": [
+      {
+        "column_name": "id",
+        "column_type": "INT32",
+        "default_value": "1"
+      },
+      {
+        "column_name": "key",
+        "column_type": "INT64",
+        "is_nullable": false,
+        "comment": "range partition column"
+      },
+      {
+        "column_name": "name",
+        "column_type": "STRING",
+        "is_nullable": false,
+        "comment": "user name"
+      }
+    ],
+    "key_column_names": ["id", "key"]
+  },
+  "partition": {
+    "hash_partitions": [{"columns": ["id"], "num_buckets": 2, "seed": 8}],
+    "range_partition": {
+      "columns": ["key"],
+      "range_bounds": [
+        {
+          "lower_bound": {"bound_type": "inclusive", "bound_values": ["2"]},
+          "upper_bound": {"bound_type": "exclusive", "bound_values": ["3"]}
+        },
+        {
+          "lower_bound": {"bound_type": "inclusive", "bound_values": ["3"]}
+        }
+      ]
+    }
+  },
+  "extra_configs": {
+    "configs": { "kudu.table.history_max_age_sec": "3600" }
+  },
+  "comment": "a test table",
+  "num_replicas": 3
+}')*";
+constexpr const char* const kCreateTableJSONArg = "create_table_json";
+constexpr const char* const kDataTypeArg = "data_type";
+constexpr const char* const kDefaultValueArg = "default_value";
+constexpr const char* const kEncodingTypeArg = "encoding_type";
+constexpr const char* const kErrorMsgArg =
+    "unable to parse value $0 for column $1 of type $2";
+constexpr const char* const kKeyArg = "primary_key";
+constexpr const char* const kNewColumnNameArg = "new_column_name";
+constexpr const char* const kNewTableNameArg = "new_table_name";
+constexpr const char* const kReplicationFactorArg = "replication_factor";
+constexpr const char* const kTableRangeLowerBoundArg = 
"table_range_lower_bound";
+constexpr const char* const kTableRangeUpperBoundArg = 
"table_range_upper_bound";
 
 enum PartitionAction {
   ADD,
@@ -1483,22 +1531,30 @@ Status CreateTable(const RunnerContext& context) {
   RETURN_NOT_OK(CreateKuduClient(context, &client));
   KuduSchema kudu_schema;
   RETURN_NOT_OK(ParseTableSchema(table_req.schema(), &kudu_schema));
-  unique_ptr<KuduTableCreator> table_creator(client->NewTableCreator());
-  table_creator->table_name(table_req.table_name())
-                                     .schema(&kudu_schema);
-  RETURN_NOT_OK(ParseTablePartition(table_req.partition(), kudu_schema, 
table_creator.get()));
+  unique_ptr<KuduTableCreator> tc(client->NewTableCreator());
+  auto& table_creator = *tc;
+  table_creator
+      .table_name(table_req.table_name())
+      .schema(&kudu_schema);
+  RETURN_NOT_OK(ParseTablePartition(table_req.partition(), kudu_schema, 
&table_creator));
   if (table_req.has_num_replicas()) {
-    table_creator->num_replicas(table_req.num_replicas());
+    table_creator.num_replicas(table_req.num_replicas());
   }
   if (table_req.has_extra_configs()) {
     map<string, string> 
extra_configs(table_req.extra_configs().configs().begin(),
                                       
table_req.extra_configs().configs().end());
-    table_creator->extra_configs(extra_configs);
+    table_creator.extra_configs(extra_configs);
   }
   if (table_req.has_dimension_label()) {
-    table_creator->dimension_label(table_req.dimension_label());
+    table_creator.dimension_label(table_req.dimension_label());
+  }
+  if (table_req.has_owner()) {
+    table_creator.set_owner(table_req.owner());
+  }
+  if (table_req.has_comment()) {
+    table_creator.set_comment(table_req.comment());
   }
-  return table_creator->Create();
+  return table_creator.Create();
 }
 
 
@@ -1769,21 +1825,9 @@ unique_ptr<Mode> BuildTableMode() {
   unique_ptr<Action> create_table =
       ClusterActionBuilder("create", &CreateTable)
       .Description("Create a new table")
-      .ExtraDescription("Provide the  table-build statements as a JSON object, 
e.g."
-                        
"'{\"table_name\":\"test\",\"schema\":{\"columns\":[{\"column_name"
-                        
"\":\"id\",\"column_type\":\"INT32\",\"default_value\":\"1\"},{"
-                        
"\"column_name\":\"key\",\"column_type\":\"INT64\",\"is_nullable\""
-                        ":false,\"comment\":\"range 
key\"},{\"column_name\":\"name\",\""
-                        
"column_type\":\"STRING\",\"is_nullable\":false,\"comment\":\""
-                        "user name\"}],\"key_column_names\":[\"id\", 
\"key\"]},\"partition\""
-                        
":{\"hash_partitions\":[{\"columns\":[\"id\"],\"num_buckets\":2,\"seed"
-                        
"\":100}],\"range_partition\":{\"columns\":[\"key\"],\"range_bounds\":"
-                        
"[{\"upper_bound\":{\"bound_type\":\"inclusive\",\"bound_values\":[\"2"
-                        "\"]}},{\"lower_bound\": 
{\"bound_type\":\"exclusive\",\"bound_values"
-                        "\": 
[\"2\"]},\"upper_bound\":{\"bound_type\":\"inclusive\",\""
-                        
"bound_values\":[\"3\"]}}]}},\"extra_configs\":{\"configs\":{\""
-                        
"kudu.table.history_max_age_sec\":\"3600\"}},\"num_replicas\":3}'.")
-      .AddRequiredParameter({ kCreateTableJSONArg, "JSON object for creating 
table" })
+      .ExtraDescription(kCreateTableExtraDescription)
+      .AddRequiredParameter({ kCreateTableJSONArg,
+                              "JSON object for creating table" })
       .Build();
 
   return ModeBuilder("table")

Reply via email to