Skip to content

Commit

Permalink
hms: synchronize column comments to the HMS
Browse files Browse the repository at this point in the history
This patch ensures column comments are
synchronized to the HMS when a table is created
or altered.

Change-Id: I12da391ea74e153483b6657e7028aa6784ac41b3
Reviewed-on: http://gerrit.cloudera.org:8080/13381
Reviewed-by: Hao Hao <[email protected]>
Tested-by: Grant Henke <[email protected]>
  • Loading branch information
granthenke committed May 21, 2019
1 parent c33bc33 commit 722678d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/kudu/hms/hms_catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ hive::FieldSchema column_to_field(const ColumnSchema& column) {
hive::FieldSchema field;
field.name = column.name();
field.type = column_to_field_type(column);
field.comment = column.comment();
return field;
}

Expand Down
4 changes: 3 additions & 1 deletion src/kudu/integration-tests/hms_itest-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Status HmsITestBase::CreateKuduTable(const string& database_name,
MonoDelta timeout) {
// Get coverage of all column types.
KuduSchemaBuilder b;
b.AddColumn("key")->Type(KuduColumnSchema::INT32)->NotNull()->PrimaryKey();
b.AddColumn("key")->Type(KuduColumnSchema::INT32)->NotNull()
->PrimaryKey()->Comment("The Primary Key");
b.AddColumn("int8_val")->Type(KuduColumnSchema::INT8);
b.AddColumn("int16_val")->Type(KuduColumnSchema::INT16);
b.AddColumn("int32_val")->Type(KuduColumnSchema::INT32);
Expand Down Expand Up @@ -159,6 +160,7 @@ void HmsITestBase::CheckTable(const string& database_name,
ASSERT_EQ(schema.num_columns(), hms_table.sd.cols.size());
for (int idx = 0; idx < schema.num_columns(); idx++) {
ASSERT_EQ(schema.Column(idx).name(), hms_table.sd.cols[idx].name);
ASSERT_EQ(schema.Column(idx).comment(), hms_table.sd.cols[idx].comment);
}
ASSERT_EQ(table->id(), hms_table.parameters[hms::HmsClient::kKuduTableIdKey]);
ASSERT_EQ(HostPort::ToCommaSeparatedString(cluster_->master_rpc_addrs()),
Expand Down
8 changes: 8 additions & 0 deletions src/kudu/integration-tests/master_hms-itest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <gtest/gtest.h>

#include "kudu/client/client.h"
#include "kudu/client/schema.h"
#include "kudu/client/shared_ptr.h"
#include "kudu/common/common.pb.h"
#include "kudu/common/table_util.h"
Expand Down Expand Up @@ -240,6 +241,13 @@ TEST_F(MasterHmsTest, TestAlterTable) {
ASSERT_OK(table_alterer->DropColumn("int8_val")->Alter());
NO_FATALS(CheckTable("default", "a", /*user=*/ none));

// Alter a column comment in Kudu. This should be reflected in the HMS.
unique_ptr<KuduTableAlterer> comment_alterer(client_->NewTableAlterer("default.a"));
comment_alterer->AlterColumn("key")->Comment("");
comment_alterer->AlterColumn("int16_val")->Comment("A new comment");
ASSERT_OK(comment_alterer->Alter());
NO_FATALS(CheckTable("default", "a", /*user=*/ none));

// Shutdown the HMS and try to alter the table.
ASSERT_OK(StopHms());
table_alterer.reset(client_->NewTableAlterer("default.a")->DropColumn("int16_val"));
Expand Down

0 comments on commit 722678d

Please sign in to comment.