kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] branch master updated: tools: support for changing column comment
Date Mon, 02 Dec 2019 18:16:54 GMT
This is an automated email from the ASF dual-hosted git repository.

adar 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 d8a8ac7  tools: support for changing column comment
d8a8ac7 is described below

commit d8a8ac7aca0af3a62fc87209e8b3a6677b4f953c
Author: helifu <hzhelifu@corp.netease.com>
AuthorDate: Mon Dec 2 13:28:53 2019 +0800

    tools: support for changing column comment
    
    Change-Id: I8bfc7f5b1c4f89d01d2f5145b648d15d90f95dfb
    Reviewed-on: http://gerrit.cloudera.org:8080/14814
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 src/kudu/tools/kudu-tool-test.cc    | 37 +++++++++++++++++++++++++++++++++----
 src/kudu/tools/tool_action_table.cc | 23 +++++++++++++++++++++++
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 5a77955..49f9d50 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -1111,14 +1111,26 @@ TEST_F(ToolTest, TestModeHelp) {
   }
   {
     const vector<string> kTableModeRegexes = {
+        "add_range_partition.*Add a range partition for table",
+        "column_remove_default.*Remove write_default value for a column",
+        "column_set_block_size.*Set block size for a column",
+        "column_set_compression.*Set compression type for a column",
+        "column_set_default.*Set write_default value for a column",
+        "column_set_encoding.*Set encoding type for a column",
+        "column_set_comment.*Set comment for a column",
+        "copy.*Copy table data to another table",
+        "create.*Create a new table",
+        "delete_column.*Delete a column",
         "delete.*Delete a table",
-        "rename_table.*Rename a table",
-        "rename_column.*Rename a column",
+        "describe.*Describe a table",
+        "drop_range_partition.*Drop a range partition of table",
+        "get_extra_configs.*Get the extra configuration properties for a table",
         "list.*List tables",
+        "locate_row.*Locate which tablet a row belongs to",
+        "rename_column.*Rename a column",
+        "rename_table.*Rename a table",
         "scan.*Scan rows from a table",
-        "copy.*Copy table data to another table",
         "set_extra_config.*Change a extra configuration value on a table",
-        "get_extra_configs.*Get the extra configuration properties for a table",
         "statistics.*Get table statistics"
     };
     NO_FATALS(RunTestHelp("table", kTableModeRegexes));
@@ -3443,6 +3455,23 @@ TEST_F(ToolTest, TestAlterColumn) {
 
   // Test invalid block_size.
   NO_FATALS(check_bad_input("column_set_block_size", "0", "Invalid block size:"));
+
+  // Alter comment for a column.
+  const auto alter_comment = [&] (size_t idx) {
+    ObjectIdGenerator generator;
+    const string comment = generator.Next();
+    ASSERT_EQ(table->schema().Column(idx).comment(), "");
+    NO_FATALS(RunActionStdoutNone(Substitute("table column_set_comment $0 $1 $2 $3",
+                                             master_addr,
+                                             kTableName,
+                                             table->schema().Column(idx).name(),
+                                             comment)));
+    ASSERT_OK(client->OpenTable(kTableName, &table));
+    ASSERT_EQ(table->schema().Column(idx).comment(), comment);
+  };
+  for (int i = 0; i < table->schema().num_columns(); ++i) {
+    NO_FATALS(alter_comment(i));
+  }
 }
 
 TEST_F(ToolTest, TestColumnSetDefault) {
diff --git a/src/kudu/tools/tool_action_table.cc b/src/kudu/tools/tool_action_table.cc
index b68e079..aaa6d70 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -178,6 +178,7 @@ 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";
 
 enum PartitionAction {
@@ -839,6 +840,18 @@ Status ColumnSetBlockSize(const RunnerContext& context) {
   return alterer->Alter();
 }
 
+Status ColumnSetComment(const RunnerContext& context) {
+  const string& table_name = FindOrDie(context.required_args, kTableNameArg);
+  const string& column_name = FindOrDie(context.required_args, kColumnNameArg);
+  const string& column_comment = FindOrDie(context.required_args, kColumnCommentArg);
+
+  client::sp::shared_ptr<KuduClient> client;
+  RETURN_NOT_OK(CreateKuduClient(context, &client));
+  unique_ptr<KuduTableAlterer> alterer(client->NewTableAlterer(table_name));
+  alterer->AlterColumn(column_name)->Comment(column_comment);
+  return alterer->Alter();
+}
+
 Status DeleteColumn(const RunnerContext& context) {
   const string& table_name = FindOrDie(context.required_args, kTableNameArg);
   const string& column_name = FindOrDie(context.required_args, kColumnNameArg);
@@ -1320,6 +1333,15 @@ unique_ptr<Mode> BuildTableMode() {
       .AddRequiredParameter({ kBlockSizeArg, "Block size of the column" })
       .Build();
 
+  unique_ptr<Action> column_set_comment =
+      ActionBuilder("column_set_comment", &ColumnSetComment)
+      .Description("Set comment for a column")
+      .AddRequiredParameter({ kMasterAddressesArg, kMasterAddressesArgDesc })
+      .AddRequiredParameter({ kTableNameArg, "Name of the table to alter" })
+      .AddRequiredParameter({ kColumnNameArg, "Name of the table column to alter" })
+      .AddRequiredParameter({ kColumnCommentArg, "Comment of the column" })
+      .Build();
+
   unique_ptr<Action> delete_column =
       ActionBuilder("delete_column", &DeleteColumn)
       .Description("Delete a column")
@@ -1365,6 +1387,7 @@ unique_ptr<Mode> BuildTableMode() {
       .AddAction(std::move(column_set_compression))
       .AddAction(std::move(column_set_default))
       .AddAction(std::move(column_set_encoding))
+      .AddAction(std::move(column_set_comment))
       .AddAction(std::move(copy_table))
       .AddAction(std::move(create_table))
       .AddAction(std::move(delete_column))


Mime
View raw message