Skip to content

Commit 46f2a49

Browse files
authored
Merge 39fefbf into 6e24151
2 parents 6e24151 + 39fefbf commit 46f2a49

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

ydb/library/workload/abstract/workload_query_generator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/value/value.h>
77
#include <ydb/library/accessor/accessor.h>
88
#include <library/cpp/getopt/last_getopt.h>
9+
#include <ydb/public/lib/ydb_cli/common/command.h>
910

1011
#include <list>
1112
#include <string>
@@ -172,6 +173,7 @@ class TWorkloadParams {
172173
virtual ~TWorkloadParams() = default;
173174
virtual void ConfigureOpts(NLastGetopt::TOpts& /*opts*/, const ECommandType /*commandType*/, int /*workloadType*/) {
174175
};
176+
virtual void Parse(NYdb::NConsoleClient::TClientCommand::TConfig& /*config*/) {};
175177
virtual THolder<IWorkloadQueryGenerator> CreateGenerator() const = 0;
176178
virtual TWorkloadDataInitializer::TList CreateDataInitializers() const {
177179
return {};

ydb/library/workload/log/log.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "log.h"
2+
#include <util/random/entropy.h>
3+
#include <util/random/mersenne.h>
24
#include <ydb/public/api/protos/ydb_formats.pb.h>
35
#include <library/cpp/json/json_value.h>
46
#include <library/cpp/resource/resource.h>
@@ -252,6 +254,11 @@ class TRandomLogGenerator {
252254
return result.str();
253255
}
254256

257+
TInstant UniformInstant(ui64 from, ui64 to) const {
258+
TMersenne<ui64> rnd(Seed());
259+
return TInstant::FromValue(rnd.Uniform(from, to));
260+
}
261+
255262
TInstant RandomInstant() const {
256263
auto result = TInstant::Now() - TDuration::Seconds(Params.TimestampSubtract);
257264
i64 millisecondsDiff = 60 * 1000 * NormalRandom<double>(0., Params.TimestampStandardDeviationMinutes);
@@ -279,7 +286,7 @@ class TRandomLogGenerator {
279286
for (size_t row = 0; row < count; ++row) {
280287
result.emplace_back();
281288
result.back().LogId = CreateGuidAsString().c_str();
282-
result.back().Ts = RandomInstant();
289+
result.back().Ts = Params.TimestampDateFrom.has_value() ? UniformInstant(*Params.TimestampDateFrom, *Params.TimestampDateTo) : RandomInstant();
283290
result.back().Level = RandomNumber<ui32>(10);
284291
result.back().ServiceName = RandomWord(false);
285292
result.back().Component = RandomWord(true);
@@ -419,7 +426,23 @@ void TLogWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandT
419426
opts.AddLongOption("rows", "Number of rows to upsert")
420427
.DefaultValue(RowsCnt).StoreResult(&RowsCnt);
421428
opts.AddLongOption("timestamp_deviation", "Standard deviation. For each timestamp, a random variable with a specified standard deviation in minutes is added.")
422-
.DefaultValue(TimestampStandardDeviationMinutes).StoreResult(&TimestampStandardDeviationMinutes);
429+
// .DefaultValue(TimestampStandardDeviationMinutes)
430+
.Optional()
431+
.StoreResult(&TimestampStandardDeviationMinutes);
432+
// TODO: maybe it shoudn't be optional
433+
434+
opts.AddLongOption("date-from", "Left boundary of the interval to generate "
435+
"timestamp uniformly from specified interval. Presents as seconds since epoch. Once this option passed, 'date-to' "
436+
"should be passed as well. This option is mutually exclusive with 'timestamp_deviation'")
437+
.Optional().StoreResult(&TimestampDateFrom);
438+
opts.AddLongOption("date-to", "Right boundary of the interval to generate "
439+
"timestamp uniformly from specified interval. Presents as seconds since epoch. Once this option passed, 'date-from' "
440+
"should be passed as well. This option is mutually exclusive with 'timestamp_deviation'")
441+
.Optional().StoreResult(&TimestampDateTo);
442+
443+
// opts.MutuallyExclusive("timestamp_deviation", "date-from");
444+
// opts.MutuallyExclusive("timestamp_deviation", "date-to");
445+
423446
opts.AddLongOption("timestamp_subtract", "Value in seconds to subtract from timestamp. For each timestamp, this value in seconds is subtracted")
424447
.DefaultValue(0).StoreResult(&TimestampSubtract);
425448
opts.AddLongOption("null-percent", "Percent of nulls in generated data")
@@ -450,6 +473,21 @@ void TLogWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandT
450473
}
451474
}
452475

476+
void TLogWorkloadParams::Parse(NYdb::NConsoleClient::TClientCommand::TConfig& config) {
477+
// TODO: should I check if it's a specific command type: run ?
478+
auto timestamp_dev_passed = config.ParseResult->Has("timestamp_deviation");
479+
auto date_from_passed = config.ParseResult->Has("date-from");
480+
auto date_to_passed = config.ParseResult->Has("date-to");
481+
482+
if (timestamp_dev_passed && (date_from_passed || date_to_passed)) {
483+
throw yexception() << "The `timestamp_deviation` and `date_from`, `date_to` are mutually exclusive and shouldn't be passed at once";
484+
}
485+
486+
if ((date_from_passed && !date_to_passed) || (!date_from_passed && date_to_passed)) {
487+
throw yexception() << "The `date_from` and `date_to` parameters must be provided together to specify the interval for uniform PK generation";
488+
}
489+
}
490+
453491
THolder<IWorkloadQueryGenerator> TLogWorkloadParams::CreateGenerator() const {
454492
return MakeHolder<TLogGenerator>(this);
455493
}

ydb/library/workload/log/log.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TLogWorkloadParams : public TWorkloadParams {
1414
};
1515

1616
void ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandType commandType, int workloadType) override;
17+
void Parse(NYdb::NConsoleClient::TClientCommand::TConfig& config) override;
1718
THolder<IWorkloadQueryGenerator> CreateGenerator() const override;
1819
TString GetWorkloadName() const override;
1920
ui64 MinPartitions = 40;
@@ -24,6 +25,8 @@ class TLogWorkloadParams : public TWorkloadParams {
2425
ui64 IntColumnsCnt = 0;
2526
ui64 KeyColumnsCnt = 0;
2627
ui64 TimestampStandardDeviationMinutes = 0;
28+
std::optional<ui64> TimestampDateFrom{std::nullopt};
29+
std::optional<ui64> TimestampDateTo{std::nullopt};
2730
ui64 TimestampTtlMinutes = 0;
2831
ui64 TimestampSubtract = 0;
2932
ui64 RowsCnt = 1;

ydb/library/workload/tpch/driver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ extern "C" {
66

77
#include <ydb/library/benchmarks/gen/tpch-dbgen/config.h>
88
#include <ydb/library/benchmarks/gen/tpch-dbgen/release.h>
9+
#ifdef DT_CHR
10+
#undef DT_CHR
11+
#endif
912
#include <ydb/library/benchmarks/gen/tpch-dbgen/dss.h>
13+
#ifdef DT_CHR
14+
#undef DT_CHR
15+
#endif
1016
#include <ydb/library/benchmarks/gen/tpch-dbgen/dsstypes.h>
1117

1218
void InitTpchGen(DSS_HUGE scale);

ydb/public/lib/ydb_cli/commands/ydb_workload.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ void TWorkloadCommandBase::Config(TConfig& config) {
374374
Params.ConfigureOpts(config.Opts->GetOpts(), CommandType, Type);
375375
}
376376

377+
void TWorkloadCommandBase::Parse(TConfig& config) {
378+
Params.Parse(config);
379+
}
380+
377381
int TWorkloadCommandBase::Run(TConfig& config) {
378382
if (!DryRun) {
379383
Driver = MakeHolder<NYdb::TDriver>(CreateDriver(config));

ydb/public/lib/ydb_cli/commands/ydb_workload.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class TWorkloadCommandBase: public TYdbCommand {
8989
const TString& description = TString(),
9090
int type = 0);
9191
virtual void Config(TConfig& config) override;
92+
virtual void Parse(TConfig& config) override;
9293
virtual int Run(TConfig& config) override final;
9394

9495
protected:

0 commit comments

Comments
 (0)