This is an automated email from the ASF dual-hosted git repository.
mgreber 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 e5d11b2c9 KUDU-3606 [tools] Show column ids when using 'kudu table
describe'
e5d11b2c9 is described below
commit e5d11b2c9c09688ea1a260aa1c8f5a25e23d8b12
Author: Yingchun Lai <[email protected]>
AuthorDate: Fri Aug 23 16:21:53 2024 +0800
KUDU-3606 [tools] Show column ids when using 'kudu table describe'
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]>
---
src/kudu/client/schema.cc | 6 ++
src/kudu/tools/kudu-admin-test.cc | 110 ++++++++++++++++++++++++------------
src/kudu/tools/tool_action_table.cc | 3 +-
3 files changed, 82 insertions(+), 37 deletions(-)
diff --git a/src/kudu/client/schema.cc b/src/kudu/client/schema.cc
index c7e655655..2ceff0242 100644
--- a/src/kudu/client/schema.cc
+++ b/src/kudu/client/schema.cc
@@ -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);
@@ -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);
}
diff --git a/src/kudu/tools/kudu-admin-test.cc
b/src/kudu/tools/kudu-admin-test.cc
index 8c5eca346..b85990c10 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -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({
@@ -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",
@@ -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) {
diff --git a/src/kudu/tools/tool_action_table.cc
b/src/kudu/tools/tool_action_table.cc
index 5c985998b..8035f0766 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -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 =