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 9d571f954 [tools] KUDU-2671 Update the kudu table describe tool
9d571f954 is described below
commit 9d571f954302a52249435726cc67dd0b8fd582f7
Author: Abhishek Chennaka <[email protected]>
AuthorDate: Wed Jul 27 18:05:31 2022 -0400
[tools] KUDU-2671 Update the kudu table describe tool
This patch updates the kudu table describe tool to output ranges
which have a custom hash schema with the corresponding hash schema.
If a partition has multiple custom hash dimensions they are
separated by a space.
Change-Id: I9fa2eb965051a5f63d1c482e6fd43ff654ec6364
Reviewed-on: http://gerrit.cloudera.org:8080/18794
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
---
src/kudu/tools/kudu-admin-test.cc | 58 +++++++++++++++++++++++++++++++++++++
src/kudu/tools/tool_action_table.cc | 6 ++--
2 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/src/kudu/tools/kudu-admin-test.cc
b/src/kudu/tools/kudu-admin-test.cc
index 45e66b292..8602b74f4 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -2086,6 +2086,64 @@ TEST_F(AdminCliTest, TestDescribeTableNoOwner) {
ASSERT_STR_CONTAINS(stdout, "OWNER \n");
}
+TEST_F(AdminCliTest, TestDescribeTableCustomHashSchema) {
+ NO_FATALS(BuildAndStart({}, {}, {}, /*create_table*/false));
+ KuduSchema schema;
+
+ // Build the schema
+ {
+ KuduSchemaBuilder builder;
+ builder.AddColumn("key_range")->Type(KuduColumnSchema::INT32)->NotNull();
+ builder.AddColumn("key_hash0")->Type(KuduColumnSchema::INT32)->NotNull();
+ builder.AddColumn("key_hash1")->Type(KuduColumnSchema::INT32)->NotNull();
+ builder.SetPrimaryKey({"key_range", "key_hash0", "key_hash1"});
+ ASSERT_OK(builder.Build(&schema));
+ }
+
+ constexpr const char* const kTableName = "table_with_custom_hash_schema";
+ unique_ptr<KuduTableCreator> table_creator(client_->NewTableCreator());
+ table_creator->table_name(kTableName)
+ .schema(&schema)
+ .add_hash_partitions({"key_hash0"}, 2)
+ .set_range_partition_columns({"key_range"})
+ .num_replicas(1);
+
+ // Create a KuduRangePartition with custom hash schema
+ {
+ unique_ptr<KuduPartialRow> lower(schema.NewRow());
+ CHECK_OK(lower->SetInt32("key_range", 0));
+ unique_ptr<KuduPartialRow> upper(schema.NewRow());
+ CHECK_OK(upper->SetInt32("key_range", 100));
+ unique_ptr<client::KuduRangePartition> partition(
+ new client::KuduRangePartition(lower.release(), upper.release()));
+ partition->add_hash_partitions({"key_hash1"}, 3);
+ table_creator->add_custom_range_partition(partition.release());
+ }
+
+ // Create a partition with table wide hash schema
+ {
+ unique_ptr<KuduPartialRow> lower(schema.NewRow());
+ CHECK_OK(lower->SetInt32("key_range", 100));
+ unique_ptr<KuduPartialRow> upper(schema.NewRow());
+ CHECK_OK(upper->SetInt32("key_range", 200));
+ table_creator->add_range_partition(lower.release(), upper.release());
+ }
+
+ // Create the table and run the tool
+ ASSERT_OK(table_creator->Create());
+ string stdout;
+ ASSERT_OK(RunKuduTool(
+ {
+ "table",
+ "describe",
+ cluster_->master()->bound_rpc_addr().ToString(),
+ kTableName,
+ },
+ &stdout));
+ ASSERT_STR_CONTAINS(stdout, "PARTITION 0 <= VALUES < 100 HASH(key_hash1)
PARTITIONS 3,\n"
+ " PARTITION 100 <= VALUES < 200");
+}
+
TEST_F(AdminCliTest, TestListTabletWithPartition) {
FLAGS_num_tablet_servers = 1;
FLAGS_num_replicas = 1;
diff --git a/src/kudu/tools/tool_action_table.cc
b/src/kudu/tools/tool_action_table.cc
index f6f82bbaa..2ebc2f9b7 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -435,9 +435,9 @@ Status DescribeTable(const RunnerContext& context) {
continue;
}
auto range_partition_str =
-
partition_schema.RangePartitionDebugString(partition.begin().range_key(),
- partition.end().range_key(),
- schema_internal);
+
partition_schema.RangeWithCustomHashPartitionDebugString(partition.begin().range_key(),
+
partition.end().range_key(),
+
schema_internal);
partition_strs.emplace_back(std::move(range_partition_str));
}
cout << partition_schema.DisplayString(schema_internal, partition_strs)