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
commit e05ff65951e72dcb216abf5472af9577fbe38fce Author: Alexey Serbin <[email protected]> AuthorDate: Thu Nov 18 20:16:05 2021 -0800 [client] fix custom hash schema criterion in KuduTableCreator::Create() This patch fixes a bug in KuduTableCreator::Create(): the criterion for the presence of custom hash schemas per range flag should account for the case when the table-wide hash schema is non-empty, but there is a range partition with empty hash schema. This patch also contains a new test to cover the related functionality. I verified that the test was failing before this patch, and with this patch it's now passing. Change-Id: I51fb745cfe7afb861b4bba54e56d79eca4832605 Reviewed-on: http://gerrit.cloudera.org:8080/18039 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Mahesh Reddy <[email protected]> Reviewed-by: Andrew Wong <[email protected]> --- src/kudu/client/client.cc | 2 +- src/kudu/client/flex_partitioning_client-test.cc | 55 +++++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/kudu/client/client.cc b/src/kudu/client/client.cc index 757a598..e26a46c 100644 --- a/src/kudu/client/client.cc +++ b/src/kudu/client/client.cc @@ -947,7 +947,7 @@ Status KuduTableCreator::Create() { bool has_range_with_custom_hash_schema = false; for (const auto& p : data_->range_partitions_) { - if (!p->data_->hash_schema_.empty()) { + if (!p->data_->is_table_wide_hash_schema_) { has_range_with_custom_hash_schema = true; break; } diff --git a/src/kudu/client/flex_partitioning_client-test.cc b/src/kudu/client/flex_partitioning_client-test.cc index ed38612..b4967f0 100644 --- a/src/kudu/client/flex_partitioning_client-test.cc +++ b/src/kudu/client/flex_partitioning_client-test.cc @@ -353,7 +353,59 @@ TEST_F(FlexPartitioningCreateTableTest, EmptyTableWideHashSchema) { // There should be 2 tablets total: one per each range created. NO_FATALS(CheckTabletCount(kTableName, 2)); ASSERT_OK(InsertTestRows(kTableName, -111, 222, KuduSession::MANUAL_FLUSH)); - NO_FATALS(CheckTableRowsNum(kTableName, 333)); + NO_FATALS(CheckLiveRowCount(kTableName, 333)); + // TODO(aserbin): uncomment the line below once PartitionPruner handles such + // cases properly + //NO_FATALS(CheckTableRowsNum(kTableName, 333)); +} + +TEST_F(FlexPartitioningCreateTableTest, SingleCustomRangeEmptyHashSchema) { + // Create a table with the following partitions: + // + // hash bucket + // key 0 1 + // ------------------------- + // <111 x:{key} x:{key} + // 111-222 - - + constexpr const char* const kTableName = "SingleCustomRangeEmptyHashSchema"; + + unique_ptr<KuduTableCreator> table_creator(client_->NewTableCreator()); + table_creator->table_name(kTableName) + .schema(&schema_) + .num_replicas(1) + .add_hash_partitions({ kKeyColumn }, 2) + .set_range_partition_columns({ kKeyColumn }); + + // Add a range partition with the table-wide hash partitioning rules. + { + unique_ptr<KuduPartialRow> lower(schema_.NewRow()); + ASSERT_OK(lower->SetInt32(kKeyColumn, INT32_MIN)); + unique_ptr<KuduPartialRow> upper(schema_.NewRow()); + ASSERT_OK(upper->SetInt32(kKeyColumn, 111)); + table_creator->add_range_partition(lower.release(), upper.release()); + } + + // Add a range partition with no hash bucketing. Not calling + // KuduRangePartition::add_hash_partitions() on the newly created range means + // the range doesn't have any hash bucketing. + { + auto p = CreateRangePartition(111, 222); + table_creator->add_custom_range_partition(p.release()); + } + + ASSERT_OK(table_creator->Create()); + NO_FATALS(CheckTabletCount(kTableName, 3)); + + // Make sure it's possible to insert rows into the table for all the existing + // the partitions: first check the range of table-wide schema, then check + // the ranges with custom hash schemas. + ASSERT_OK(InsertTestRows(kTableName, -111, 0)); + NO_FATALS(CheckLiveRowCount(kTableName, 111)); + ASSERT_OK(InsertTestRows(kTableName, 111, 222)); + NO_FATALS(CheckLiveRowCount(kTableName, 222)); + // TODO(aserbin): uncomment the line below once PartitionPruner handles such + // cases properly + //NO_FATALS(CheckTableRowsNum(kTableName, 222)); } // Create a table with mixed set of range partitions, using both table-wide and @@ -362,7 +414,6 @@ TEST_F(FlexPartitioningCreateTableTest, EmptyTableWideHashSchema) { // TODO(aserbin): add verification based on PartitionSchema provided by // KuduTable::partition_schema() once PartitionPruner // recognized custom hash bucket schema for ranges -// TODO(aserbin): add InsertTestRows() when proper key encoding is implemented TEST_F(FlexPartitioningCreateTableTest, DefaultAndCustomHashSchemas) { // Create a table with the following partitions: //
