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 7b0a94d [common] add PartitionSchema::HasCustomHashSchemas() method
7b0a94d is described below
commit 7b0a94d72de4475c6e6c3d7d78569403407cb278
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Sep 30 19:19:58 2021 -0700
[common] add PartitionSchema::HasCustomHashSchemas() method
Added PartitionSchema::HasCustomHashSchemas() method and corresponding
unit test. This new method will be used in a follow-up changelist to
tell between tables with table-wide and custom per-range hash schemas.
Change-Id: I73508447677884391ae26b6b20886d85960836b7
Reviewed-on: http://gerrit.cloudera.org:8080/17895
Tested-by: Kudu Jenkins
Reviewed-by: Mahesh Reddy <[email protected]>
Reviewed-by: Andrew Wong <[email protected]>
---
src/kudu/common/partition-test.cc | 75 +++++++++++++++++++++++++++++++++++++++
src/kudu/common/partition.h | 4 +++
2 files changed, 79 insertions(+)
diff --git a/src/kudu/common/partition-test.cc
b/src/kudu/common/partition-test.cc
index 7071810..c8fa5a7 100644
--- a/src/kudu/common/partition-test.cc
+++ b/src/kudu/common/partition-test.cc
@@ -1809,4 +1809,79 @@ TEST_F(PartitionTest, TestOverloadedEqualsOperator) {
ASSERT_OK(PartitionSchema::FromPB(schema_builder, schema,
&partition_schema));
ASSERT_NE(partition_schema, partition_schema_1);
}
+
+// A test scenario to verify functionality of the
+// PartitionSchema::HasCustomHashSchemas() method.
+TEST_F(PartitionTest, HasCustomHashSchemasMethod) {
+ const Schema schema({ ColumnSchema("a", STRING),
+ ColumnSchema("b", STRING),
+ ColumnSchema("c", STRING) },
+ { ColumnId(0), ColumnId(1), ColumnId(2) }, 3);
+
+ // No hash schema (even table-wide) case.
+ {
+ PartitionSchemaPB pb;
+ PartitionSchema partition_schema;
+ ASSERT_OK(PartitionSchema::FromPB(pb, schema, &partition_schema));
+ ASSERT_FALSE(partition_schema.HasCustomHashSchemas());
+ }
+
+ // Table-wide hash schema.
+ {
+ PartitionSchemaPB pb;
+ AddHashDimension(&pb, { "b" }, 2, 0);
+ PartitionSchema partition_schema;
+ ASSERT_OK(PartitionSchema::FromPB(pb, schema, &partition_schema));
+ ASSERT_FALSE(partition_schema.HasCustomHashSchemas());
+ }
+
+ // No table-wide schema, just a range with custom hash schema.
+ {
+ PartitionSchemaPB pb;
+ auto* range = pb.add_custom_hash_schema_ranges();
+ RowOperationsPBEncoder encoder(range->mutable_range_bounds());
+ KuduPartialRow lower(&schema);
+ KuduPartialRow upper(&schema);
+ ASSERT_OK(lower.SetStringCopy("a", "a0"));
+ ASSERT_OK(lower.SetStringCopy("c", "c0"));
+ ASSERT_OK(upper.SetStringCopy("a", "a0"));
+ ASSERT_OK(upper.SetStringCopy("c", "c1"));
+ encoder.Add(RowOperationsPB::RANGE_LOWER_BOUND, lower);
+ encoder.Add(RowOperationsPB::RANGE_UPPER_BOUND, upper);
+
+ auto* hash_dimension = range->add_hash_schema();
+ hash_dimension->add_columns()->set_name("a");
+ hash_dimension->set_num_buckets(2);
+
+ PartitionSchema partition_schema;
+ ASSERT_OK(PartitionSchema::FromPB(pb, schema, &partition_schema));
+ ASSERT_TRUE(partition_schema.HasCustomHashSchemas());
+ }
+
+ // Table-wide hash schema and one range with custom hash schema.
+ {
+ PartitionSchemaPB pb;
+ AddHashDimension(&pb, { "a" }, 2, 0);
+
+ auto* range = pb.add_custom_hash_schema_ranges();
+ RowOperationsPBEncoder encoder(range->mutable_range_bounds());
+ KuduPartialRow lower(&schema);
+ KuduPartialRow upper(&schema);
+ ASSERT_OK(lower.SetStringCopy("a", "a0"));
+ ASSERT_OK(lower.SetStringCopy("c", "c0"));
+ ASSERT_OK(upper.SetStringCopy("a", "a1"));
+ ASSERT_OK(upper.SetStringCopy("c", "c1"));
+ encoder.Add(RowOperationsPB::RANGE_LOWER_BOUND, lower);
+ encoder.Add(RowOperationsPB::RANGE_UPPER_BOUND, upper);
+
+ auto* hash_dimension = range->add_hash_schema();
+ hash_dimension->add_columns()->set_name("b");
+ hash_dimension->set_num_buckets(3);
+
+ PartitionSchema partition_schema;
+ ASSERT_OK(PartitionSchema::FromPB(pb, schema, &partition_schema));
+ ASSERT_TRUE(partition_schema.HasCustomHashSchemas());
+ }
+}
+
} // namespace kudu
diff --git a/src/kudu/common/partition.h b/src/kudu/common/partition.h
index 590fcf9..61e1a3e 100644
--- a/src/kudu/common/partition.h
+++ b/src/kudu/common/partition.h
@@ -364,6 +364,10 @@ class PartitionSchema {
return ranges_with_hash_schemas_;
}
+ bool HasCustomHashSchemas() const {
+ return !ranges_with_hash_schemas_.empty();
+ }
+
// Given the specified table schema, populate the 'range_column_indexes'
// container with column indexes of the range partition keys.
// If any of the columns is not in the key range columns then an