Skip to content

Commit

Permalink
KUDU-3606 [tools] Show column ids when using 'kudu table describe'
Browse files Browse the repository at this point in the history
Column id is an internal concept, this patch
adds a new flag --show_column_id to indicate
whether to show it when using 'kudu table describe'.

It's helpful to compare whether two tables'
schema are competely the same with considering
the internal column id as well.

Change-Id: Ib9b28bd8f879bb6cace1683bc366c72772caebdc
Reviewed-on: http://gerrit.cloudera.org:8080/21717
Reviewed-by: Yifan Zhang <[email protected]>
Reviewed-by: Wang Xixu <[email protected]>
Tested-by: Yingchun Lai <[email protected]>
Reviewed-by: Marton Greber <[email protected]>
  • Loading branch information
acelyc111 authored and martongreber committed Sep 13, 2024
1 parent a0b7a52 commit e5d11b2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 37 deletions.
6 changes: 6 additions & 0 deletions src/kudu/client/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ DEFINE_bool(show_attributes, false,
DEFINE_bool(show_column_comment, false,
"Whether to show column comment.");

DEFINE_bool(show_column_id, false,
"Whether to show column id.");

MAKE_ENUM_LIMITS(kudu::client::KuduColumnStorageAttributes::EncodingType,
kudu::client::KuduColumnStorageAttributes::AUTO_ENCODING,
kudu::client::KuduColumnStorageAttributes::RLE);
Expand Down Expand Up @@ -1046,6 +1049,9 @@ string KuduSchema::ToString() const {
if (FLAGS_show_column_comment) {
mode |= Schema::ToStringMode::WITH_COLUMN_COMMENTS;
}
if (FLAGS_show_column_id) {
mode |= Schema::ToStringMode::WITH_COLUMN_IDS;
}
return schema_->ToString(mode);
}

Expand Down
110 changes: 74 additions & 36 deletions src/kudu/tools/kudu-admin-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ TEST_F(AdminCliTest, TestDescribeTable) {
"REPLICAS 1\n"
"COMMENT table comment");

// Test the describe output with `-show_attributes=true`.
// Test the describe output with show_attributes, show_column_comment and show_column_id as true.
stdout.clear();
stderr.clear();
s = RunKuduTool({
Expand All @@ -2077,40 +2077,51 @@ TEST_F(AdminCliTest, TestDescribeTable) {
cluster_->master()->bound_rpc_addr().ToString(),
kAnotherTableId,
"-show_attributes=true",
"-show_column_comment=true"
"-show_column_comment=true",
"-show_column_id=true"
}, &stdout, &stderr);
ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr);

ASSERT_STR_CONTAINS(
stdout,
"(\n"
" key_hash0 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" key_hash1 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" key_hash2 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" key_range INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" int8_val INT8 NULLABLE PLAIN_ENCODING NO_COMPRESSION - -,\n"
" int16_val INT16 NULLABLE RLE SNAPPY - -,\n"
" int32_val INT32 NULLABLE BIT_SHUFFLE LZ4 - -,\n"
" int64_val INT64 NULLABLE AUTO_ENCODING ZLIB 123 123,\n"
" timestamp_val UNIXTIME_MICROS NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" date_val DATE NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" string_val STRING NULLABLE PREFIX_ENCODING DEFAULT_COMPRESSION \"hello\" \"hello\" "
"comment for hello,\n"
" bool_val BOOL NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION false false,\n"
" float_val FLOAT NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" double_val DOUBLE NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION 123.4 123.4,\n"
" binary_val BINARY NULLABLE DICT_ENCODING DEFAULT_COMPRESSION - -,\n"
" decimal_val DECIMAL(30, 4) NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" PRIMARY KEY (key_hash0, key_hash1, key_hash2, key_range)\n"
")\n"
"HASH (key_hash0) PARTITIONS 2,\n"
"HASH (key_hash1, key_hash2) PARTITIONS 3,\n"
"RANGE (key_range) (\n"
" PARTITION 0 <= VALUES < 1,\n"
" PARTITION 2 <= VALUES < 3\n"
")\n"
"OWNER alice\n"
"REPLICAS 1");
Substitute("(\n"
" $00:key_hash0 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $01:key_hash1 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $02:key_hash2 INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $03:key_range INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $04:int8_val INT8 NULLABLE PLAIN_ENCODING NO_COMPRESSION - -,\n"
" $05:int16_val INT16 NULLABLE RLE SNAPPY - -,\n"
" $06:int32_val INT32 NULLABLE BIT_SHUFFLE LZ4 - -,\n"
" $07:int64_val INT64 NULLABLE AUTO_ENCODING ZLIB 123 123,\n"
" $08:timestamp_val UNIXTIME_MICROS NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION "
"- -,\n"
" $09:date_val DATE NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $10:string_val STRING NULLABLE PREFIX_ENCODING DEFAULT_COMPRESSION "
"\"hello\" \"hello\" "
"comment for hello,\n"
" $11:bool_val BOOL NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION false false,\n"
" $12:float_val FLOAT NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $13:double_val DOUBLE NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION "
"123.4 123.4,\n"
" $14:binary_val BINARY NULLABLE DICT_ENCODING DEFAULT_COMPRESSION - -,\n"
" $15:decimal_val DECIMAL(30, 4) NULLABLE AUTO_ENCODING DEFAULT_COMPRESSION "
"- -,\n"
" PRIMARY KEY (key_hash0, key_hash1, key_hash2, key_range)\n"
")\n"
"HASH (key_hash0) PARTITIONS 2,\n"
"HASH (key_hash1, key_hash2) PARTITIONS 3,\n"
"RANGE (key_range) (\n"
" PARTITION 0 <= VALUES < 1,\n"
" PARTITION 2 <= VALUES < 3\n"
")\n"
"OWNER alice\n"
"REPLICAS 1",
// In DEBUG builds, column id starts from 10 while in RELEASE builds it starts from 0.
#ifdef NDEBUG
"", "1"));
#else
"1", "2"));
#endif

s = RunKuduTool({
"table",
Expand Down Expand Up @@ -2300,20 +2311,47 @@ TEST_F(AdminCliTest, TestDescribeTableColumnFlags) {
")\n");
stdout.clear();

ASSERT_OK(RunKuduTool({"table",
"describe",
cluster_->master()->bound_rpc_addr().ToString(),
kTableName,
"-show_column_id"},
&stdout));
ASSERT_STR_CONTAINS(stdout,
Substitute("(\n"
" $00:foo INT32 NOT NULL,\n"
" $01:bar INT32 NOT NULL,\n"
" PRIMARY KEY (foo)\n"
")\n",
#ifdef NDEBUG
""));
#else
"1"));
#endif
stdout.clear();

ASSERT_OK(RunKuduTool({"table",
"describe",
cluster_->master()->bound_rpc_addr().ToString(),
kTableName,
"-show_attributes",
"-show_column_comment"},
"-show_column_comment",
"-show_column_id"},
&stdout));
ASSERT_STR_CONTAINS(
stdout,
"(\n"
" foo INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" bar INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - - comment for bar,\n"
" PRIMARY KEY (foo)\n"
")\n");
Substitute("(\n"
" $00:foo INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - -,\n"
" $01:bar INT32 NOT NULL AUTO_ENCODING DEFAULT_COMPRESSION - - comment for "
"bar,\n"
" PRIMARY KEY (foo)\n"
")\n",
#ifdef NDEBUG
""));
#else
"1"));
#endif

}

TEST_F(AdminCliTest, TestDescribeTableNoOwner) {
Expand Down
3 changes: 2 additions & 1 deletion src/kudu/tools/tool_action_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1922,8 +1922,9 @@ unique_ptr<Mode> BuildTableMode() {
.Description("Describe a table")
.AddRequiredParameter({ kTableNameArg, "Name of the table to describe" })
.AddOptionalParameter("show_attributes")
.AddOptionalParameter("show_column_comment")
.AddOptionalParameter("show_avro_format_schema")
.AddOptionalParameter("show_column_comment")
.AddOptionalParameter("show_column_id")
.Build();

unique_ptr<Action> list_tables =
Expand Down

0 comments on commit e5d11b2

Please sign in to comment.