Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Merge pull request basicthinker#7 from ldeng-ustc/zeropadding
Browse files Browse the repository at this point in the history
add zeropadding parameter
  • Loading branch information
basicthinker authored Apr 7, 2021
2 parents fc18fa4 + 4a43341 commit 6475c7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/core_workload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const string CoreWorkload::REQUEST_DISTRIBUTION_PROPERTY =
"requestdistribution";
const string CoreWorkload::REQUEST_DISTRIBUTION_DEFAULT = "uniform";

const string CoreWorkload::ZERO_PADDING_PROPERTY = "zeropadding";
const string CoreWorkload::ZERO_PADDING_DEFAULT = "1";

const string CoreWorkload::MAX_SCAN_LENGTH_PROPERTY = "maxscanlength";
const string CoreWorkload::MAX_SCAN_LENGTH_DEFAULT = "1000";

Expand Down Expand Up @@ -94,6 +97,7 @@ void CoreWorkload::Init(const utils::Properties &p) {
record_count_ = std::stoi(p.GetProperty(RECORD_COUNT_PROPERTY));
std::string request_dist = p.GetProperty(REQUEST_DISTRIBUTION_PROPERTY,
REQUEST_DISTRIBUTION_DEFAULT);
zero_padding_ = std::stoi(p.GetProperty(ZERO_PADDING_PROPERTY, ZERO_PADDING_DEFAULT));
int max_scan_len = std::stoi(p.GetProperty(MAX_SCAN_LENGTH_PROPERTY,
MAX_SCAN_LENGTH_DEFAULT));
std::string scan_len_dist = p.GetProperty(SCAN_LENGTH_DISTRIBUTION_PROPERTY,
Expand Down
13 changes: 12 additions & 1 deletion core/core_workload.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class CoreWorkload {
static const std::string REQUEST_DISTRIBUTION_PROPERTY;
static const std::string REQUEST_DISTRIBUTION_DEFAULT;

///
/// The name of the property for adding zero padding to record numbers in order to match
/// string sort order. Controls the number of 0s to left pad with.
///
static const std::string ZERO_PADDING_PROPERTY;
static const std::string ZERO_PADDING_DEFAULT;

///
/// The name of the property for the max scan length (number of records).
///
Expand Down Expand Up @@ -184,6 +191,7 @@ class CoreWorkload {
CounterGenerator insert_key_sequence_;
bool ordered_inserts_;
size_t record_count_;
int zero_padding_;
};

inline std::string CoreWorkload::NextSequenceKey() {
Expand All @@ -203,7 +211,10 @@ inline std::string CoreWorkload::BuildKeyName(uint64_t key_num) {
if (!ordered_inserts_) {
key_num = utils::Hash(key_num);
}
return std::string("user").append(std::to_string(key_num));
std::string key_num_str = std::to_string(key_num);
int zeros = zero_padding_ - key_num_str.length();
zeros = std::max(0, zeros);
return std::string("user").append(zeros, '0').append(key_num_str);
}

inline std::string CoreWorkload::NextFieldName() {
Expand Down

0 comments on commit 6475c7a

Please sign in to comment.